V16.1: Never reject a token response #19651
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This is a follow-up from #19495
If a token response is rejected, then the pipeline will also fail because it does not understand that error. Let the API interceptors do their job instead and simply return the old, now-invalid token, which will prompt the API interceptors to store the request states and retry them afterwards.
Details
The error is prompted because the
/tokenendpoint on the server returns a 400 error, which the client doesn't understand. Instead of relying on server errors, we merely assume that no new token was received. This means that the following requests will be stored and retried once a real login happens.(The login is prompted automatically by the API interceptors, so the AuthFlow does not need to call
timeoutitself)How to test
Umbraco:CMS:Global:Before
After
2025-07-02.at.13.54.08.-.Red.Flamingo.mp4
Copilot
This pull request modifies the
performWithFreshTokensmethod inauth-flow.tsto improve token refresh handling and clarify its behavior. The key changes include updating the return type documentation, adding logic to clear token state when the refresh fails, and simplifying the method's structure.Improvements to token refresh handling:
src/Umbraco.Web.UI.Client/src/packages/core/auth/auth-flow.ts: Updated the return type documentation ofperformWithFreshTokensto specify{Promise<string>}. Added logic to clear token storage when the refresh token request fails and removed redundant code for handling missingtokenResponse. Simplified the method to ensure a valid access token is returned or an empty string if unavailable.