I am trying to use AWS Cognito to authenticate (using Google) and authorise users, with the intention of assigning IAM roles for the authorised users.
I have followed the below steps till now
Use the authorization end point to fire up Google OAuth process http://docs.aws.amazon.com/cognito/latest/developerguide/authorization-endpoint.html
I am using "Grant flow" I receive a such as
code=b3e8bca6-5a01-45db-b4c6-cd6900d0xxxx
Make a post request to oath/token http://docs.aws.amazon.com/cognito/latest/developerguide/token-endpoint.html
I receive the following information:
"id_token": "eyJraWQiOiJJR2NVdHJcL3pOa3pQK1lre...........", "access_token": "eyJraWQiOiJCbWx0cjJvMnJlVGhHW..........", "refresh_token": "eyJjdHkiOiJKV1QiLCJlbmMiOi............", "expires_in": 3600, "token_type": "Bearer"
Try to fetch the AWS credntions using the CognitoIdentityCredentials
AWS.config.credentials = new AWS.CognitoIdentityCredentials({ IdentityPoolId: environment.identityPoolId, // Federated ID eu-west-2:af47703f-350c-4018-ae6a-xxxxxx RoleArn: environment.roleArn,// IAM role Logins: { 'accounts.google.com': data.id_token }, }); AWS.config.getCredentials((error) => { if(error) console.log("Error: ", error); this.creds = AWS.config.credentials; });
I get a bad request 500 error
{"__type":"NotAuthorizedException","message":"Invalid login token. Issuer doesn't match providerName"}
Couple of questions
- Is the sequence of steps followed correct?
- How to I get a CongnitoUserId ?
id_token
is a very long string, but not sure what information can I extract from it? - Finally how to I get accessKey to make AWS calls?
Any help or direction will be much appreciated.
Thanks