I have a ReactJS SPA application which connects to the ASP.NET Core WebAPI. The API is also an authorization server thanks to OpenIddict. I am using PasswordFlow and RefreshTokenFlow to handle authentication, which means that the server returns an AccessToken and optionally a RefreshToken. At this moment I struggle with handling Remember me functionality properly. When a user wants to rememebered it is no big deal - the server returns an AccessToken and a RefreshToken which the client stores is LocalStorage, so it can refresh the AccessToken when it's about to expire or is expired by using RefreshToken and it is fine - there is a lot of articles and other helpful resources on the Web. The problem comes when the user does not want to be remembered. How to handle authentication is this scenario? The two solutions I see are:
- the server only issues an
AccessToken, which the client stores inSessionStorage. If it expires - the client forces the user to re-enter his credentials to get a newAccessToken.AccessTokensshould be short-lived (according to what I've learned so far, it can be from one up to several hours, but the more hours it is valid, the less secure it is in a situation when it gets stolen. If it lasts for an hour and after that time the user still uses the application, it seems a bit odd to force him/her to login again. - the server returns an
AccessTokenand aRefreshTokenand the client stores it inSessionStorage. During the session, if theAccessTokenis about to expire, the client can get a new one by using theRefreshToken. This is risky as well as the server will never know that the user closed his browser and that his/hersRefreshTokenshould be revoked. Assuming thatRefreshTokenshave a way longer lifetime, this seems really risky.
I will be grateful for any thoughts, suggestions and insights on this topic. Thank you!