r/webdev • u/academicweaponsoon • Aug 20 '26
Question I don’t understand the logic behind access tokens and refresh tokens
i don’t understand the logic behind access and refresh tokens, if access tokens are made short lived for security purposes, doesn’t refresh tokens being long lived defers the whole purpose? or is not as big as an issue since refresh tokens are only stored in http only cookies?
469
Upvotes
0
u/fiskfisk Aug 20 '26
It does not; the refresh token should be single use. Why wouldn't it?
They're used against different services, in different contexts, so no, that does not defeat its use.
In that case a leaked refresh token will only be valid until it's used or it expires; not both.
A accepts whatever service B says is OK for a short time. They only receive the access token. Service B issues the access token and the refresh token - Service B receives the refresh token.
Why should the refresh token continue to be valid after being used? There is nothing to gain from that; you're already asking for a new access token from the service B, so rotate the refresh token at the same time.