【发布时间】:2017-11-01 15:33:51
【问题描述】:
我正在尝试使用以下博客文章中概述的方法从 Java 向 S3 验证 cognito 身份:
我已成功实现开发人员身份验证提供程序,并且可以为我的 cognito 身份检索有效的 OpenId 令牌。将文件上传/下载到 S3 时,该令牌适用于 iOS 和 Android SDK。不幸的是,我无法在我的 Java 应用程序中成功地向 S3 验证相同的身份。这是我正在使用的代码:
Map<String, String> logins = new HashMap();
logins.put("cognito-identity.amazonaws.com", cognitoOpenIdToken);
GetCredentialsForIdentityRequest getCredentialsRequest =
new GetCredentialsForIdentityRequest()
.withIdentityId(cognitoIdentityId)
.withLogins(logins);
AmazonCognitoIdentityClient cognitoIdentityClient =
new AmazonCognitoIdentityClient();
GetCredentialsForIdentityResult getCredentialsResult =
cognitoIdentityClient.getCredentialsForIdentity(getCredentialsRequest);
对 getCredentialsForIdentity 的调用失败并出现错误“com.amazonaws.AmazonClientException:无法从链中的任何提供商加载 AWS 凭证”。此方法被记录为不需要身份验证的公共 API。但是,我注意到,如果在系统变量中配置了有效的 IAM 凭证的环境中完成,调用会成功。它在不是这种情况的环境中失败。
我错过了一些简单的东西吗?
【问题讨论】:
标签: java amazon-web-services amazon-cognito