AWS cognito "remember me" option

246 Views Asked by At

I have a react native and a react native web frontend application with an AWS backend. For authentication I use AWS Cognito. Some of my users use a public computer, so for those users the authentication tokens should expire within an hour (if they set the "remember me" option to false during login).

the problem

AWS amplify

Although AWS amplify is a high level library that doesn't leave much room for customisation, I could just drop the refresh token? enter image description here

Is this a valid option? And more importantly, a secure option?

1

There are 1 best solutions below

6
Nicolas Lykke Iversen On

You cannot set the access, ID, or refresh token's lifetime in the request to the /oauth2/token endpoint, like it's seemingly possible with other IdPs:

https://docs.aws.amazon.com/cognito/latest/developerguide/token-endpoint.html

If the refresh token is expired, your app user must re-authenticate by signing in again to your user pool.

Depending on the security profile of your application, you shouldn't specify a low refresh token expiration, as it hurts the user's experience:

https://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-user-pools-using-the-refresh-token.html

You cannot manipulate the expiration time of cookies to delete them, either at a specified time or when the browser is closed, as they are configured as HttpOnly and Secure:

You can also add an expiry date (in UTC time). By default, the cookie is deleted when the browser is closed:

Are you sure the tokens are stored as cookies? Normally they're stored in local- or session storage. If so, they can be deleted client-side using JavaScript. This answer shows, that you can configure the Amplify library to store the tokens in session storage, i.e. they will be deleted, when the browser tab is closed:

Auth.configure({ storage: window.sessionStorage })

Finally, you might want to revoke the user's refresh token. This can be accomplished solely using the access token:

https://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-user-pools-using-the-refresh-token.html#amazon-cognito-identity-user-pools-revoking-all-tokens-for-user