【问题标题】:Credential Provider Not Authorised Exception AWS Android SDK凭据提供程序未授权异常 AWS Android 开发工具包
【发布时间】:2017-08-28 14:08:17
【问题描述】:

我试图在 AWS IoT 上使用经过身份验证的用户和联合身份来发布和订阅。直到我不断收到错误CognitoCachingCredentialsProvider: Failure to get credentials

我查了here。但是他们提供的 sn-p 不再被 Facebook 使用。我该如何解决这个问题?

安卓代码:

    public void IntializeAwsIot() {
    clientId = "us-east-1:fcbd66e0-***************";

    // Initialize the AWS Cognito credentials provider
    credentialsProvider = new CognitoCachingCredentialsProvider(
            getApplicationContext(), // context
            AWSConfiguration.AMAZON_COGNITO_IDENTITY_POOL_ID,// Identity Pool ID
            AWSConfiguration.AMAZON_COGNITO_REGION // Region
    );

    Region region = Region.getRegion(AWSConfiguration.AMAZON_COGNITO_REGION);
    // MQTT Client
    mqttManager = new AWSIotMqttManager(clientId, CUSTOMER_SPECIFIC_ENDPOINT);


    // The following block uses IAM user credentials for authentication with AWS IoT.
    //awsCredentials = new BasicAWSCredentials("ACCESS_KEY_CHANGE_ME", "SECRET_KEY_CHANGE_ME");
    //btnConnect.setEnabled(true);

    // The following block uses a Cognito credentials provider for authentication with AWS IoT.
    new Thread(new Runnable() {
        @Override
        public void run() {
            awsCredentials = credentialsProvider.getCredentials();
            Connect();
        }
    }).start();
}

错误:

/com.amazon.mysampleapp E/CognitoCachingCredentialsProvider: Failure to get credentials

com.amazonaws.services.cognitoidentity.model.NotAuthorizedException: Access to Identity 'us-east-1:fcbd66e0-**************' is forbidden. (Service: AmazonCognitoIdentity; Status Code: 400; Error Code: NotAuthorizedException; Request ID: 0fa5100d-88a0-11e7-af8c-854a7b8add4d)
                                                                                           at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:729)
                                                                                           at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:405)
                                                                                           at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:212)
                                                                                           at com.amazonaws.services.cognitoidentity.AmazonCognitoIdentityClient.invoke(AmazonCognitoIdentityClient.java:558)
                                                                                           at com.amazonaws.services.cognitoidentity.AmazonCognitoIdentityClient.getCredentialsForIdentity(AmazonCognitoIdentityClient.java:388)
                                                                                           at com.amazonaws.auth.CognitoCredentialsProvider.populateCredentialsWithCognito(CognitoCredentialsProvider.java:691)
                                                                                           at com.amazonaws.auth.CognitoCredentialsProvider.startSession(CognitoCredentialsProvider.java:617)
                                                                                           at com.amazonaws.auth.CognitoCredentialsProvider.getCredentials(CognitoCredentialsProvider.java:388)
                                                                                           at com.amazonaws.auth.CognitoCachingCredentialsProvider.getCredentials(CognitoCachingCredentialsProvider.java:442)
                                                                                           at com.mysampleapp.AWSIoT.PubSub$1.run(PubSub.java:69)
                                                                                           at java.lang.Thread.run(Thread.java:818)

【问题讨论】:

    标签: android amazon-web-services aws-iot


    【解决方案1】:

    问题是 Cognito 缓存中没有凭据。所以我们需要保存相应的凭证,这样获取凭证的功能才能工作。

    我们只需要添加以下内容。

        Map<String, String> logins = new HashMap<String, String>();
        logins.put("graph.facebook.com", AccessToken.getCurrentAccessToken().getToken());
        credentialsProvider.setLogins(logins);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-30
      • 2016-11-10
      • 2020-01-01
      • 2022-11-02
      • 2019-07-08
      相关资源
      最近更新 更多