How to generate - access token vs refresh token
See original GitHub issueHey,
I have a problem in understanding on how to generate properly access token and refresh token. According to the docs there is a concept of both due to JWT_REFRESH_EXPIRATION_DELTA
and JWT_EXPIRATION_DELTA
configuration variables, but in the source files I’ve seen only single method for generating a token which is https://github.com/flavors/django-graphql-jwt/blob/master/graphql_jwt/shortcuts.py#L4
The flow which I would like to follow is:
- User sign-up/sign-in to the app
- User receives two tokens:
access_token
(valid for 5 minutes) andrefresh_token
(valid for 7 days) - The
access_token
is used to communicate frontend app with the backend API - The
refresh_token
is used to regenerate theaccess_token
in intervals, so it would be valid during using the app in longer session
Is it correct approach to such scenario?
access_token = get_token(user)
refresh_token = get_token(user, exp=datetime.utcnow() + settings.JWT_REFRESH_EXPIRATION_DELTA)
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
What Are Refresh Tokens and How to Use Them Securely
Once they expire, client applications can use a refresh token to "refresh" the access token. That is, a refresh token is a credential...
Read more >Solved: Difference between Refresh token and Access token
Refresh Token, A credential that a client uses to obtain new access tokens without requiring additional user authorization.
Read more >Why Does OAuth v2 Have Both Access and Refresh Tokens?
The lifetime of a refresh token is up to the (AS) authorization server — they can expire, be revoked, etc. The difference between...
Read more >Authentication and Authorization: Refresh Tokens - OCLC
Refresh Token are typically longer lived than Access Tokens and used to request a new Access Token without forcing user authentication. Unlike ...
Read more >What Are Refresh Tokens and How Can They Boost Your ...
Normally, a user with an access token can only access protected resources or perform specific actions for a set period of time, which...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
What happens if I don’t call
refreshToken
afterJWT_EXPIRATION_DELTA=minutes=5
but withinJWT_REFRESH_EXPIRATION_DELTA=days=7
? WillverifyToken(t)
returnfalse
ifJWT_VERIFY_EXPIRATION=true
but refreshToken will return a new valid token? Or doesJWT_VERIFY_EXPIRATION
need to be turned off in order to refresh an expired token?1 question to this great explanation. How to keep the user logged in “forever” then? Well, forever as long as he keeps rehreshing within allowed JWT_EXPIRATION_DELTA time span (as I understand I’d refresh triggered after the time of 5 minutes in this case, token gets invalidated?)
I could set JWT_REFRESH_EXPIRATION_DELTA to be like 30 days but it’s still not forever.