Refresh tokens: renew access safely and detect reuse
Learn how refresh tokens differ from access tokens and how rotation, protected storage, and revocation reduce compromise risk.
Refresh tokens: renew access safely and detect reuse
A refresh token is a long-lived credential an OAuth client presents to the authorization server to obtain a new access token. It can avoid repeated user sign-in, but theft may let an attacker mint access tokens. Protect refresh tokens more strongly than ordinary access tokens, and define renewal, replay detection, and revocation rules.
An access token goes to a resource server with an API request. A refresh token normally goes only to the authorization server's token endpoint. OAuth does not require one string format, and refresh tokens are not necessarily JWTs. Issuance is optional: the server should decide based on client type and risk, and limit renewal to the granted authorization, scopes, and resources.
Renewal and rotation
When an access token expires or is about to expire, the client sends its refresh token to the token endpoint. The server checks the client when required and verifies that the token is valid for that client, grant, scope, and resource. It returns a new access token and, if rotation is enabled, a replacement refresh token. The client must store the new value safely, atomically replace the old one, and never use the old token again. On invalid_grant or another invalid-token response, do not retry the stale token indefinitely; use the application's approved reauthentication flow.
Serialize concurrent refresh attempts. If two requests submit the same token at once, rotation may make one response stale or trigger reuse detection. Coordinate renewal and update token storage atomically; after an uncertain response, check the current token state before retrying.
Reduce theft and replay risk
Use TLS in transit; keep tokens out of URLs, source code, logs, analytics, and browser-accessible storage. Choose protected storage for the platform. Bind tokens to the intended client when supported, limit them to approved scopes and resources, and avoid silently expanding authority during renewal. Rotation issues a new refresh token and invalidates the previous one while the server tracks their relationship. Sender constraint is an alternative where supported. Set idle expiry and consider revocation after security events such as password change or logout, according to risk and policy.
Rotation reuse detection does not identify which party is the attacker. If a copied old token and the legitimate client both use it, the server may revoke the active token family and require the user to sign in again. Prepare a clear recovery message and investigation record.
If exposure is suspected
Find possible copies in logs, browser storage, mobile backups, error reports, or proxies; do not copy the raw token into a ticket or message.
Revoke the refresh token family or related grant at the authorization server, and check whether it tracks token families.
Handle access tokens already issued: revoking a refresh token may not immediately invalidate self-contained access tokens. Assess their remaining lifetime and apply resource-side status checks or temporary account/resource blocks if needed.
Clear the client's stored token and let the user obtain a new grant through the approved authentication flow; do not restore login by retrying an old token.
Fix the cause—excess retention, missing log masking, unnecessary long-lived issuance, or ignored reuse alerts—and verify the updated policy.
RFC 9700 recommends protecting refresh tokens in transit and storage and using sender constraint or rotation with replay detection for public clients where applicable. Actual support depends on the authorization server and client. Revoking a refresh token is not the same as instantly revoking every access token it previously created.
Sources
[RFC 6749: The OAuth 2.0 Authorization Framework](https://www.rfc-editor.org/rfc/rfc6749.html)
[RFC 7009: OAuth 2.0 Token Revocation](https://www.rfc-editor.org/rfc/rfc7009.html)
[RFC 9700: Best Current Practice for OAuth 2.0 Security](https://www.rfc-editor.org/rfc/rfc9700.html)