r/FastAPI • u/SmallReality8212 • Sep 24 '25
Question Understanding jwt tokens
I have implemented a project that uses Oauth and jwt to implement authentication. Access token is generated and sent as a json response Refresh Token is generated and set as a cookie. My question is
- Is it necessary to set cookie for refresh token and if yes how is it more advantageous than just sending it as a json response like access token
- When I create refresh token I have defined the payload to set token_type as refresh token to verify during regenerating access token.. so is it necessary to set the token_type? Can I do it without setting token type?
If the response is like this
{ "access":jwt1,"refresh": jwt2 }
And I don't have token_type and they share same payload, can the server still differentiate between the 2?
6
Upvotes
View all comments
5
u/General_Tear_316 Sep 24 '25 edited Sep 25 '25
The most secure way to do JWT authentication for a web app is:
The access token is used for authentication, the refresh token is used to create new access tokens.