我尝试使用下面的博客文章中介绍的方法来验证从Java cognito身份S3:AWS Cognito GetCredentialsForIdentity
我已经成功地实施了开发商的认证供应商,可以检索有效的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凭证的环境中完成调用,则该调用会成功。如果情况并非如此,它会失败。
我是否缺少一些简单的东西?
就是这样,谢谢你Vinay! – Mike