- Newest
- Most votes
- Most comments
Based on the information you've provided, it seems there are a few areas we can troubleshoot to resolve your issue with authenticating Google users through Amazon Cognito Identity Pools.
-
Identity Pool Configuration: Ensure that you have properly configured Google as an authentication provider in your Identity Pool settings. In the AWS Console, go to the Cognito Identity Pools section, select your Identity Pool, and verify that Google is listed as an authentication provider with the correct Google app ID.
-
GetId API Call: Your GetId API call looks correct. The error "Token is not from a supported provider of this identity pool" suggests that either the Google provider is not correctly configured in your Identity Pool, or there's an issue with the Google ID token. Double-check that the Google ID token is valid and not expired.
-
AssumeRoleWithWebIdentity: The "Not authorized to perform sts:AssumeRoleWithWebIdentity" error indicates a permissions issue. Your trust policy looks mostly correct, but there are a couple of things to check:
a. Ensure that the
<GOOGLE_WEB_CLIENT_ID>in your trust policy exactly matches the client ID in your Google configuration.b. The condition for the Google federation in your trust policy uses "accounts.google.com:aud". This should actually be "accounts.google.com:sub" to match the subject (user ID) from the Google token.
-
Authentication Flow: Instead of calling AssumeRoleWithWebIdentity directly, you should use the enhanced authentication flow with Cognito Identity. After getting the ID from GetId, use the GetCredentialsForIdentity API. This API handles the role assumption internally and is the recommended way to get credentials when using Cognito Identity Pools.
Here's what you should try:
-
Verify your Identity Pool configuration for Google as an authentication provider.
-
Use the GetId API call as you've done.
-
If GetId is successful, use the returned Identity ID to call GetCredentialsForIdentity. Here's an example curl command:
curl --location 'https://cognito-identity.us-east-1.amazonaws.com' \ --header 'Content-Type: application/x-amz-json-1.1' \ --header 'X-Amz-Target: AWSCognitoIdentityService.GetCredentialsForIdentity' \ --data '{ "IdentityId": "<IDENTITY_ID_FROM_GETID>", "Logins": { "accounts.google.com": "<GOOGLE_ID_TOKEN>" } }'This should return temporary AWS credentials that you can use to access AWS services.
-
If you still encounter issues, double-check your IAM role permissions to ensure they allow the necessary Cognito Identity actions.
By following these steps and using the enhanced authentication flow with GetCredentialsForIdentity, you should be able to successfully authenticate Google users and obtain AWS credentials using only an Identity Pool.
Sources
Identity pools authentication flow - Amazon Cognito
GetCredentialsForIdentity - Amazon Cognito Federated Identities
Getting credentials - Amazon Cognito
GetId - Amazon Cognito Federated Identities
Request temporary security credentials - AWS Identity and Access Management
