When an access token expires, the API rejects it, and the client must get a new one. What happens step by step 1. The token's exp claim is in the past (allowing a small clock skew, by default 5 minutes in ASP.NET Core; many teams reduce it). 2. The API's authentication handler fails validation and responds 401 Unauthorized, typically with: WWW-Authenticate: Bearer error="invalid_token", error_description="The token expired at ..." 3. The endpoint code never runs, so no data is returned or changed. How a well-built client handles it - If it has a refresh token: call the token endpoint, get a new access token (and a rotated refresh token), and retry the original request transparently. The user notices nothing. - If the refresh token is also expired or revoked: clear local session data and redirect to the login page, ideally returning the user to where they were afterwards. - Avoid several simultaneous refresh calls: queue other requests while one refresh is in progress. - Proactive refresh: renew shortly before expiry to avoid failed requests during long operations. Server-side considerations - Keep access tokens short-lived (5–60 minutes). Expiry limits the damage if a token is stolen, because JWTs cannot easily be revoked before they expire. - Refresh tokens last longer and are stored and revocable on the server. - Long-running operations: a request already being processed is not affected — validation happens when the request arrives — but multi-step client workflows should handle a 401 in the middle. - SignalR and WebSocket connections authenticated with a token keep running after it expires unless you close them; set CloseOnAuthenticationExpiration (available in recent ASP.NET Core versions) or handle reconnection with a fresh token. Distinguish 401 from 403: 401 means "not authenticated or invalid token" (renew or log in); 403 means "authenticated but not allowed" (refreshing will not help).
Ravindra Wadile · · 0 likes