Niklas Rosencrantz
Niklas Rosencrantz

Reputation: 26655

How to send aws cognito token from client

I use serverless-framework with aws lambda and aws cognito. I have set up a user pool and registered the app. I can login in the login ui and get the code and then exchange the code programmatically for tokens.

But how should I send the tokens from the web client to the aws lambda?

I can use the program Postman or curl but I need to use a web client (http browser). How should I set the header with the token?

Upvotes: 0

Views: 740

Answers (1)

Ashan
Ashan

Reputation: 19738

After you receive the token from Cognito Token endpoint, you can store it in the Browser storage (e.g; LocalStorage, SessionStorage, ClientSide Cookies) using JavaScript and send it in Authorization header for API requests (Ajax requests).

You can use AWS Amplify JS library to simplify the authentication and refreshing the token.

Note: One can argue that it is not safe to store the token's in Browser Storage, but if you look at AWS Amplify JS library, it uses LocalStorage to store both id token and refresh token.

Upvotes: 1

Related Questions