Amazon Cognito开发人员使用Java SDKvalidation身份

我正在尝试使用经过开发人员身份validation的Cognito身份向AWS服务validationJava应用程序。 这在AWS mobile SDK( 文档 )中非常简单,但我似乎无法在Java SDK中找到等效的类。

我遇到的主要问题是Java SDK类(例如WebIdentityFederationSessionCredentialsProvider)要求客户端代码知道所假定角色的arn。 使用移动SDK,它使用为联合身份配置的角色。 这就是我更喜欢做的事情,但似乎Java SDK没有支持类。

杰夫的最后评论引导我回答。 谢谢Jeff!

String cognitoIdentityId = "your user's identity id"; String openIdToken = "open id token for the user created on backend"; Map logins = new HashMap<>(); logins.put("cognito-identity.amazonaws.com", openIdToken); GetCredentialsForIdentityRequest getCredentialsRequest = new GetCredentialsForIdentityRequest() .withIdentityId(cognitoIdentityId) .withLogins(logins); AmazonCognitoIdentityClient cognitoIdentityClient = new AmazonCognitoIdentityClient(); GetCredentialsForIdentityResult getCredentialsResult = cognitoIdentityClient.getCredentialsForIdentity(getCredentialsRequest); Credentials credentials = getCredentialsResult.getCredentials(); AWSSessionCredentials sessionCredentials = new BasicSessionCredentials( credentials.getAccessKeyId(), credentials.getSecretKey(), credentials.getSessionToken() ); AmazonS3Client s3Client = new AmazonS3Client(sessionCredentials); ... 

如果这是您想要的路线,您可以在IAM控制台中找到此角色,名为Cognito_(Auth | Unauth)_DefaultRole。 这些是Cognito生成并链接到您的池,您可以从那里获得ARN。

这篇博文可能会有所帮助。 SDK用于与Cognito通信以获取凭据的所有API都在Java SDK中公开,您只需使用自己的后端来获取令牌本身。 一旦你拥有它,你可以像往常一样用另一个提供商设置登录,这一切都有效。

Interesting Posts