Skip to content

Conversation

@Ajsmith1435
Copy link

Fix SSO refresh with Authentik by always adopting the IdP’s rotated refresh token, preventing invalid_grant and premature re-login.

Changes
src/sso_client.rs: exchange_refresh_token always returns Some(current_refresh_token) (rotated if provided, else the one just used).
src/sso.rs: remove fallback to old token; pass the returned token directly to create_auth_tokens.

Why?
Authentik revokes the old refresh token on rotation; reusing it triggers invalid_grant. See

Testing
SSO with Authentik → let access token expire → refresh repeatedly. Expect no invalid_grant; rotated token adopted each cycle.

Refs
Fixes #6311

… token to prevent invalid_grant

Ensures Vaultwarden immediately switches to the IdP’s latest provider refresh token after each refresh, preventing reuse of a revoked token and eliminating `invalid_grant` errors that prematurely log users out.
let new_refresh = token_response
.refresh_token()
.map(|t| t.secret().clone())
.unwrap_or_else(|| rt.secret().clone());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey
Not sure how this change anything since .unwrap_or_else(|| rt.secret().clone()) should be equivalent to new_refresh_token.or(Some(refresh_token)).

@Timshel
Copy link
Contributor

Timshel commented Oct 21, 2025

In the issue you mention Request to exchange_refresh_token endpoint failed is triggered as such the part of the method you modified will be short-circuited.

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.

SSO: Authentik Refresh token not valid

2 participants