我嘗試使用下面的博客文章中介紹的方法來驗證從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