我很難想出如何在我的Web應用程序(基於Java)中使用Amazon Cognito。我想擁有某種身份驗證中心(Amazon Cognito)通過多個身份驗證提供程序對用戶進行身份驗證 - 這就是爲什麼我想使用Amazon Cognito! :)使用Cognito聯合身份驗證
首先,我設置了用戶池(我有我的UserPoolId:eu-central-1_xxxxxxxxxx)並創建了一個用戶。接下來,我使用IdentityPoolId創建了Identity Pool(eu-central-1:yyyyyyyyyy)。然後我使用AWS JavaScript SDK對UserPool進行身份驗證以獲得idToken,並且它工作得很好!我從Cognito UserPool收到idToken。然後我將這個idToken發送到我的後端應用程序(基於Java),並且我想用IdentityPool驗證此idToken。我在UserPoolId中添加了新的身份驗證提供程序 - Cognito,並在UserPool中添加了新創建的應用程序ID。我試圖按照本教程: https://aws.amazon.com/blogs/mobile/use-amazon-cognito-in-your-website-for-simple-aws-authentication/ 但每次我做
GetID
要求我recevied異常與
com.amazonaws.services.cognitoidentity.model.NotAuthorizedException: Token is not from a supported provider of this identity pool.
我的Java代碼如下:
final AmazonCognitoIdentityClient identityClient = new AmazonCognitoIdentityClient(
new BasicAWSCredentials("accessKey", "secretKey"));
identityClient.setRegion(Region.getRegion(Regions.EU_CENTRAL_1));
GetIdRequest idRequest = new GetIdRequest();
idRequest.setAccountId("accountId");
idRequest.setIdentityPoolId(identityPoolId);
final String providerName = "cognito-idp.eu-central-1.amazonaws.com/eu-central-1_xxxxxxxx";
Map providerTokens = new HashMap();
providerTokens.put(providerName, idToken);
idRequest.setLogins(providerTokens);
GetIdResult idResp = identityClient.getId(idRequest);
沒有人能幫助我完成這項任務?也許我做錯了什麼?
感謝, 卡米爾:)