Repository navigation
Token refresh: Do not report transient failures as expired token - #237
paolostivanin wants to merge 3 commits into
Conversation
Any failed silent token refresh (network error, timeout, IdP 5xx, failed OIDC discovery) ended in an empty bearer token, a second 401 and the "token expired, sign in again" prompt. Background uploads were marked as permanently failed. - AccountAuthenticator now tells a refresh token rejected by the IdP (invalid_grant and similar) from a transient failure. Only the former asks for a new login. The latter is reported as a connection problem and the stored tokens are kept. - ConnectionValidator no longer counts a failed refresh as a success and does not retry with stale credentials. - mTLS: the validation probe and the OIDC discovery and refresh requests now present the account's client certificate. - Serialize refreshes with a lock and store the rotated refresh token before the access token. - Stop logging tokens.
|
Tested your PR behind Cloudflare mTLS, mobile data only. After the access token expired, the refresh (discovery + token request) went through with the client cert and the app kept working, no "session expired" screen. Works for me. Closing my #267 as a duplicate, thanks for the review! |
|
I have started to test and review this PR. First tests look promising. What I have seen so far: The description above says "Tokens are no longer logged", but tokens are still logged when signing in: Please check this. As far as I have seen, there's no requirement to remove this. |
The previous commit stopped logging tokens in AccountAuthenticator, but the sign-in path still wrote secrets to the log: - TokenRequestRemoteOperation logged the raw token response and the parsed TokenResponse (access, refresh and id token). - LoginActivity logged the authorization code and the TokenResponse. - RegisterClientRemoteOperation logged the client registration response, which carries the client_secret. The log lines are kept, without the secret values. Failed token responses are still logged, they only carry the OAuth error.
|
Thanks, you're right. The PR only cleaned up |
Problem
Users are often sent back to the login screen with "The access token has expired or become invalid". Any failed silent token refresh (network error, timeout, IdP 5xx, failed OIDC discovery) was reported that way. The authenticator returned nothing, the request was retried with an empty
Bearerheader, got a second 401 and surfaced as an expired session. Background uploads were marked as permanently failed. With mTLS there were two more problems on the same path.Changes
AccountAuthenticatortells a refresh token rejected by the IdP (invalid_grant,invalid_client,unauthorized_client,access_denied) from a transient failure. Only a rejection asks for a new login. A transient failure throwsNetworkErrorException, which reaches the callers as a connection problem (TokenRefreshFailedException, aSocketException) so it is retried and the stored tokens are kept.TokenRequestRemoteOperationmaps a rejected refresh grant toOAUTH2_ERROR. The login (authorization code) grant keeps its mapping.ConnectionValidatorno longer counts a failed refresh as a success and does not retry with stale credentials.clearPasswordfor OAuth accounts, which wiped a token refreshed by a concurrent request.FileDisplayActivitychecksAccountUtils.isOAuth2Accountinstead of loading credentials, which could trigger another refresh.Testing
ConnectionValidatorTest,AccountAuthenticatorTest, and refresh error mapping inOAuthRemoteOperationTest. The two behavioural validator tests fail on the old code.