将用户池与Amazon Cognito Identity与身份验证提供程序集成 [英] Integrating User Pools with Amazon Cognito Identity with authentication provider
问题描述
我遵循链接中所述的步骤: http://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-integrating-user-pools-with-identity-pools.html 进行集成我的具有认知身份的用户池。但是每次我尝试使用身份验证提供程序访问amazone S3时,都会出现以下错误:
I follow the steps described in the link: http://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-integrating-user-pools-with-identity-pools.html to integrate my user pool with cognito identity. But every time I am trying to access amazone S3 using the Authentication providers I get the following error:
E / CognitoCachingCredentialsProvider:无法获取凭据
com.amazonaws.services.cognitoidentity.model.NotAuthorizedException:
登录名不匹配。请为此
身份或身份池至少包含一个有效的登录名。 (服务:AmazonCognitoIdentity;状态
代码:400;错误代码:NotAuthorizedException;请求ID:
ff4da8ad-9a96-11e6-9c64-67a5c841c727)
at
com.amazonaws.http .AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:712)
at
com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:388)
at
com.amazonaws.http .AmazonHttpClient.execute(AmazonHttpClient.java:199)
at
com.amazonaws.services.cognitoidentity.AmazonCognitoIdentityClient.invoke(AmazonCognitoIdentityClient.java:558)
在
处com.amazonaws.services.cognitoidentity.AmazonCognitoIdentityClient.getId(AmazonCognitoIdentityClient.java:444)在
处获得
com.amazonaws.auth.AWSAbstractCognitoIdentityProvider.getIdentityId(AWSAbstractCognitoIdentityProvider。 $ b在
com.amazonaws.auth.AWSEnhancedCognitoIdentityProvider.refresh(AWSEnhancedCognitoIdentityProvider.java:76)$ b $在
com.amazonaws.auth.CognitoCredentialsProvider.startSession(CognitoCredentialsProvider.java:561)b $ b at
com.amazonaws.auth.CognitoCredentialsProvider.getCredentials(CognitoCredentialsPr ovider.java:371)
在
com.amazonaws.auth.CognitoCachingCredentialsProvider.java:441)
在
com.amazonaws.auth.CognitoCachingCredentialsProvider.getCredentials( CognitoCachingCredentialsProvider.java:76)
at
com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:4369)
at
com.amazonaws.services.s3。 AmazonS3Client.putObject(AmazonS3Client.java:1704)
at
com.amazonaws.mobileconnectors.s3.transferutility.Uplo adTask.uploadSinglePartAndWaitForCompletion(UploadTask.java:203)
at
com.amazonaws.mobileconnectors.s3.transferutility.UploadTask.call(UploadTask.java:85)
at
com。 amazonaws.mobileconnectors.s3.transferutility.UploadTask.call(UploadTask.java:44)
在java.util.concurrent.FutureTask.run(FutureTask.java:234)
在
java。 util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at
java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:573 )
在java.lang.Thread.run(Thread.java:864)。
E/CognitoCachingCredentialsProvider: Failure to get credentials com.amazonaws.services.cognitoidentity.model.NotAuthorizedException: Logins don't match. Please include at least one valid login for this identity or identity pool. (Service: AmazonCognitoIdentity; Status Code: 400; Error Code: NotAuthorizedException; Request ID: ff4da8ad-9a96-11e6-9c64-67a5c841c727) at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:712) at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:388) at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:199) at com.amazonaws.services.cognitoidentity.AmazonCognitoIdentityClient.invoke(AmazonCognitoIdentityClient.java:558) at com.amazonaws.services.cognitoidentity.AmazonCognitoIdentityClient.getId(AmazonCognitoIdentityClient.java:444) at com.amazonaws.auth.AWSAbstractCognitoIdentityProvider.getIdentityId(AWSAbstractCognitoIdentityProvider.java:172) at com.amazonaws.auth.AWSEnhancedCognitoIdentityProvider.refresh(AWSEnhancedCognitoIdentityProvider.java:76) at com.amazonaws.auth.CognitoCredentialsProvider.startSession(CognitoCredentialsProvider.java:561) at com.amazonaws.auth.CognitoCredentialsProvider.getCredentials(CognitoCredentialsProvider.java:371) at com.amazonaws.auth.CognitoCachingCredentialsProvider.getCredentials(CognitoCachingCredentialsProvider.java:441) at com.amazonaws.auth.CognitoCachingCredentialsProvider.getCredentials(CognitoCachingCredentialsProvider.java:76) at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:4369) at com.amazonaws.services.s3.AmazonS3Client.putObject(AmazonS3Client.java:1704) at com.amazonaws.mobileconnectors.s3.transferutility.UploadTask.uploadSinglePartAndWaitForCompletion(UploadTask.java:203) at com.amazonaws.mobileconnectors.s3.transferutility.UploadTask.call(UploadTask.java:85) at com.amazonaws.mobileconnectors.s3.transferutility.UploadTask.call(UploadTask.java:44) at java.util.concurrent.FutureTask.run(FutureTask.java:234) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) at java.lang.Thread.run(Thread.java:864).
这是代码:
public static TransferUtility getTransferUtility(Context context) {
if (sTransferUtility == null) {
sTransferUtility = new TransferUtility(getS3Client(context.getApplicationContext()),
context.getApplicationContext());
}
return sTransferUtility;
}
public static AmazonS3Client getS3Client(Context context) {
if (sS3Client == null) {
sS3Client = new AmazonS3Client(getCredProvider(context.getApplicationContext()));
}
return sS3Client;
}
private static CognitoCachingCredentialsProvider getCredProvider(Context context) {
if (sCredProvider == null) {
sCredProvider = new CognitoCachingCredentialsProvider(
context.getApplicationContext(),
Constants.COGNITO_POOL_ID,
Regions.EU_WEST_1);
Map<String, String> logins = new HashMap<>();
logins.put("cognito-idp.eu-west-1.amazonaws.com/eu-west-1_xxxxxxxxx", idToken);
sCredProvider.setLogins(logins);
}
return sCredProvider;
}
在这里我如何获得代币
AuthenticationHandler authenticationHandler = new AuthenticationHandler() {
@Override
public void onSuccess(CognitoUserSession cognitoUserSession, CognitoDevice device) {
Log.e(TAG, "***Auth Success***");
idToken = cognitoUserSession.getIdToken().getJWTToken();
AppHelper.setCurrSession(cognitoUserSession);
AppHelper.newDevice(device);
closeWaitDialog();
launchUser();
}
transferutility是com.amazonaws.mobileconnectors.s3.transferutility软件包的一部分。
The transferutility is part of com.amazonaws.mobileconnectors.s3.transferutility package.
感谢您的帮助。
felini
Thank you for your help. felini
推荐答案
这是一个配置问题。我已将现有身份池Cognito用户池添加为身份验证提供程序。我提供了用户池ID和客户端ID。
It was a configuration problem. I added to an existing identity pool, Cognito user pool as Authentication Providers. I provided the user pool Id and client Id.
然后单击保存更改。仪表板上的绿色显示我的更改已保存。但实际上并非如此!这就是错误的原因。
Then I click save changes. It was shown in green on the dashboard that my changes was saved. But in reality it was not! That was the reason of the error.
作为解决方案,我从头开始创建了一个新的身份池,并在创建过程中添加了作为身份验证提供程序的cognito用户池。只有在创建池之后,它才能正确保存。
As solution I created a new identity pool from scratch and added during the creation, cognito user pool as authentication provider. Only then it was properly saved after the pool creation.
这篇关于将用户池与Amazon Cognito Identity与身份验证提供程序集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!