Skip to content

fix: end local session on rejected refresh token - #382

Open
H-LK wants to merge 1 commit into
owncloud:masterfrom
H-LK:fix/session-refresh-invalid-grant
Open

H-LK wants to merge 1 commit into
owncloud:masterfrom
H-LK:fix/session-refresh-invalid-grant

Conversation

@H-LK

@H-LK H-LK commented Nov 16, 2026

Copy link
Copy Markdown

When the identity provider rejects the stored refresh token with invalid_grant, the current code treats it like any other refresh failure: it logs the error, calls logout(), and throws. logout() additionally triggers the user.afterlogout hook, which sends a sign-out request to the identity provider — one that fails for the same reason, because the refresh token is already invalid.

This PR ends only the local session in that case:

  • the user.afterlogout listener is kept on a property and removed before logout() runs, so the failing sign-out request is not sent
  • both ways the error can surface are handled: an HTTP 400 ClientException with error=invalid_grant, and a decoded response body with an error property
  • every other refresh failure (different HTTP status, different error codes) keeps the previous behavior: error logged, sign-out request sent, HintException thrown

Tests

  • testRejectedRefreshEndsLocalSession — for invalid_grant (both the HTTP shape and the response-body shape, cached and fresh token) the session ends, the error is logged, a HintException is thrown, and the sign-out request to the identity provider is not triggered
  • testOtherRefreshFailuresRemainErrors — other HTTP errors (400 with a different error code, 500) and other response errors (access_denied, server_error) still log the error, trigger the sign-out request and throw

Background

Split out of #377 as requested in the review there: this PR contains only the SessionVerifier change for the invalid_grant path (related to #376) and no changes to the OAuth2 app. The OpenIdConnectAuthModule part of #377 is intentionally dropped here.

When the identity provider rejects the stored refresh token with
invalid_grant, end only the local session instead of additionally
sending a sign-out request that fails for the same reason. Other
refresh errors keep their previous behavior.

Related: fixes owncloud#376 (invalid_grant branch of session refresh)
Signed-off-by: Hendrik Linka <[email protected]>
@H-LK
H-LK requested a review from a team as a code owner November 16, 2026 13:15
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants