Kaymaz
Kaymaz

Reputation: 486

What to do with the token from AWS cognito

The idea is to perform login/authentication + autorization with AWS Cognito and Google Login as Federated entity.

Everything is done on the client side using AWS javascript SDK.

I can login using https://.auth.eu-central-1.amazoncognito.com/oauth2/authorize?identity_provider=Google&redirect_uri=https://&response_type=token&client_id=<Client_id>. I redirects me to my website and adds an access_token in the URL. I can get back AWS access and secret keys with the CognitoIdentityCredentials function.

Questions:

  1. What to do with this access_token?
  2. Which function do I need call to get the current user?
  3. Do I need the access_key and secret_key?

Upvotes: 0

Views: 644

Answers (1)

Kaymaz
Kaymaz

Reputation: 486

Ok, it appears I was confused...

When logged in with Cognito, there are two JWT tokens in the URL (this part is important):

  1. access_token
  2. id_token

The id_token must be sent in the Authorization header when calling API Gateway to authorize the requests. The header is automatically set if you use the AWS Amplify SDK.

I will add more info when I manage to acheive the full flow from login/register to API Gateway requests.

Side note: I thing I got confused when I read all the pieces of code online (Github, Medium, etc.) where they all use Cognito Identity Pool after the login part.

Upvotes: 1

Related Questions