Is it safe to store access_token in cookies in Code Grant flow?

0

I am using Cognito's Authentication Code Grant. After logging in, a user is given a code inside the callback URL which is later exchanged for an access_token.

In my web application, after logging in, a user can access a "console" (similar to AWS). Each time the user interacts with the console (like accessing a service) it does it through an api in API Gateway.

Unauthenticated users should not access the console and all its services. Hence, the way I am doing this is that every time the user wants to make a request to these REST endpoints the access_token is required.

However, this access_token should be stored somewhere so that the user can pass it in the request headers for later calls.

Where should this access_token be stored?

Which is the right way to do this? Maybe requiring the access_token in every API endpoint is not right?

1 個回答
0

Hi apssg,

You can store your access tokens on client side (local storage/http cookie) or server side in a DynamoDB database, depending on your security and requirements level. Bear in mind that client side is vulnerable to XSS attack.

Moreover, on dynamo you can delete old tokens via Time To Live feature enabled and should be more secure.

It is a good practice to always pass access token as Bearer token in the Authorization header so that you can protect your application with short lived authorization mechanism.

Hope it helps.

profile picture
專家
已回答 1 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南