Based on your sign-in request, here are your Cognito details:
- Region:
ap-southeast-1 - Client ID:
1d1jkchdvgt5tldbb0hivruird - User Pool ID:
⚠️ Still needed - see instructions below
The User Pool ID is different from the Client ID. Here's how to find it:
- Go to AWS Console
- Navigate to Amazon Cognito
- Select User Pools from the left sidebar
- Click on your user pool name
- The Pool ID is displayed at the top
- Format:
ap-southeast-1_XXXXXXXXX(9 random characters after underscore)
- Format:
aws cognito-idp list-user-pools --max-results 10 --region ap-southeast-1Look for the pool with your client ID and note its Id field.
When you sign in, Cognito returns tokens. You can decode the access token (without verification) to see the issuer:
# The issuer contains the User Pool ID
# Format: https://cognito-idp.ap-southeast-1.amazonaws.com/ap-southeast-1_XXXXXXXXXUse your existing sign-in request to get tokens:
curl -X POST 'https://cognito-idp.ap-southeast-1.amazonaws.com/' \
--header 'X-Amz-Target: AWSCognitoIdentityProviderService.InitiateAuth' \
--header 'Content-Type: application/x-amz-json-1.1' \
--data '{
"AuthFlow": "USER_PASSWORD_AUTH",
"ClientId": "1d1jkchdvgt5tldbb0hivruird",
"AuthParameters": {
"USERNAME": "swingshree9@gmail.com",
"PASSWORD": "Shree@99"
}
}'{
"AuthenticationResult": {
"AccessToken": "eyJraWQiOiJ...(long token)...xyz",
"IdToken": "eyJraWQiOiJ...(long token)...abc",
"RefreshToken": "eyJjdHkiOiJ...(long token)...def",
"ExpiresIn": 3600,
"TokenType": "Bearer"
}
}Important: Copy the AccessToken and IdToken values.
Once you have your User Pool ID, update application.properties:
aws.cognito.region=ap-southeast-1
aws.cognito.userPoolId=ap-southeast-1_YOUR_POOL_ID_HERE
aws.cognito.jwks.url=https://cognito-idp.ap-southeast-1.amazonaws.com/ap-southeast-1_YOUR_POOL_ID_HERE/.well-known/jwks.json./gradlew bootRuncurl -X POST 'http://localhost:8080/create-user' \
--header 'Authorization: Bearer YOUR_ACCESS_TOKEN_HERE' \
--header 'X-Id-Token: YOUR_ID_TOKEN_HERE'Replace YOUR_ACCESS_TOKEN_HERE with the actual AccessToken from Step 2.
{
"userid": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"email": "swingshree9@gmail.com",
"preferenceId": null
}The userid will be the Cognito subject (user's unique ID in Cognito).
{
"error": "Token verification failed: Invalid token issuer"
}- Open: http://localhost:8080/h2-console
- Use JDBC URL:
jdbc:h2:mem:testdb - Username:
sa, Password: (leave empty) - Run query:
SELECT * FROM app_user;
You should see your user with:
userid: Cognito subjectemail: swingshree9@gmail.com
curl -X GET 'http://localhost:8080/api/users/YOUR_USER_ID'Replace YOUR_USER_ID with the userid from the create-user response.
COGNITO_RESPONSE=$(curl -s -X POST 'https://cognito-idp.ap-southeast-1.amazonaws.com/' \
--header 'X-Amz-Target: AWSCognitoIdentityProviderService.InitiateAuth' \
--header 'Content-Type: application/x-amz-json-1.1' \
--data '{
"AuthFlow": "USER_PASSWORD_AUTH",
"ClientId": "1d1jkchdvgt5tldbb0hivruird",
"AuthParameters": {
"USERNAME": "swingshree9@gmail.com",
"PASSWORD": "Shree@99"
}
}')
# Extract tokens (requires jq)
ACCESS_TOKEN=$(echo $COGNITO_RESPONSE | jq -r '.AuthenticationResult.AccessToken')
ID_TOKEN=$(echo $COGNITO_RESPONSE | jq -r '.AuthenticationResult.IdToken')
echo "Access Token: $ACCESS_TOKEN"
echo "ID Token: $ID_TOKEN"curl -X POST 'http://localhost:8080/create-user' \
--header "Authorization: Bearer $ACCESS_TOKEN" \
--header "X-Id-Token: $ID_TOKEN"# Should return the same user, not create a duplicate
curl -X POST 'http://localhost:8080/create-user' \
--header "Authorization: Bearer $ACCESS_TOKEN" \
--header "X-Id-Token: $ID_TOKEN"Cause: User Pool ID in configuration doesn't match the one that issued the token.
Solution:
- Decode your access token at https://jwt.io
- Look at the
issclaim:https://cognito-idp.ap-southeast-1.amazonaws.com/ap-southeast-1_XXXXXXXXX - The part after the last
/is your User Pool ID - Update
application.propertieswith this value
Cause: Service can't reach AWS Cognito JWKS endpoint.
Solution: Check internet connectivity and firewall rules.
Possible causes:
- Token is expired (tokens expire after 1 hour by default)
- Token is from a different User Pool
- Token is malformed or truncated
Solution: Get a fresh token from Cognito and try again.
Cause: Missing or malformed Authorization header.
Solution: Ensure header is: Authorization: Bearer <token> with space after "Bearer".
- Method: POST
- URL:
https://cognito-idp.ap-southeast-1.amazonaws.com/ - Headers:
X-Amz-Target:AWSCognitoIdentityProviderService.InitiateAuthContent-Type:application/x-amz-json-1.1
- Body (raw JSON):
{ "AuthFlow": "USER_PASSWORD_AUTH", "ClientId": "1d1jkchdvgt5tldbb0hivruird", "AuthParameters": { "USERNAME": "swingshree9@gmail.com", "PASSWORD": "Shree@99" } } - Test Script (to auto-extract tokens):
var jsonData = pm.response.json(); pm.environment.set("access_token", jsonData.AuthenticationResult.AccessToken); pm.environment.set("id_token", jsonData.AuthenticationResult.IdToken);
- Method: POST
- URL:
http://localhost:8080/create-user - Headers:
Authorization:Bearer {{access_token}}X-Id-Token:{{id_token}}
- Method: GET
- URL:
http://localhost:8080/api/users/{{user_id}} - Note: Set
user_idfrom the create-user response
- ✅ Find your User Pool ID
- ✅ Update
application.properties - ✅ Restart the service
- ✅ Test with real tokens
- ✅ Verify user creation in H2 console
- ✅ Test from Flutter app
Your Flutter app should:
- Sign in with Cognito (you're already doing this)
- Store the access_token
- Call your user service:
final response = await http.post( Uri.parse('https://your-service-url/create-user'), headers: { 'Authorization': 'Bearer $accessToken', 'X-Id-Token': '$idToken', }, );
- Store the userId from response for future API calls
The user service will:
- ✅ Verify the token signature
- ✅ Create user on first sign-in
- ✅ Return existing user on subsequent sign-ins
- ✅ Use Cognito subject as the user ID