SSO: clients get logged out when the IdP is briefly unreachable (refresh returns invalid_grant)
Prerequisites
- I have searched the existing Closed AND Open Issues AND Discussions
- I have searched and read the documentation
Vaultwarden Support String
Your environment (Generated via diagnostics page)
- Vaultwarden version: v1.37.1-46d71107
- Web-vault version: v2026.7.0
- OS/Arch: linux/x86_64
- Running within a container: yes :heavy_plus_sign: (Base: Debian)
- Database type: PostgreSQL
- Database version: PostgreSQL 18.4 (Debian 18.4-1.pgdg13+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 14.2.0-19) 14.2.0, 64-bit
- Uses config.json: no :heavy_minus_sign:
- Uses custom templates: no :heavy_minus_sign:
- Uses a reverse proxy: yes :heavy_plus_sign:
- IP Header check: true :white_check_mark: (X-Forwarded-For)
- Internet access: true :white_check_mark:
- Internet access via a proxy: no :heavy_minus_sign:
- DNS Check: true :white_check_mark:
- TZ environment: Europe/Istanbul
- Browser/Server Time Check: true :white_check_mark:
- Server/NTP Time Check: true :white_check_mark:
- Domain Configuration Check: true :white_check_mark:
- HTTPS Check: true :white_check_mark:
- Websocket Check: true :white_check_mark:
- HTTP Response Checks: true :white_check_mark:
Config & Details (Generated via diagnostics page)
Show Config & DetailsConfig:
{
"data_folder": "/data",
"database_url": "**********://**************************************************************************************************************************************************************************************************************************",
"icon_cache_folder": "/data/icon_cache",
"attachments_folder": "/data/attachments",
"sends_folder": "/data/sends",
"tmp_folder": "/data/tmp",
"templates_folder": "/data/templates",
"rsa_key_filename": "/data/rsa_key",
"web_vault_folder": "web-vault/",
"enable_websocket": true,
"push_enabled": true,
"push_relay_uri": "https://api.bitwarden.eu",
"push_identity_uri": "https://identity.bitwarden.eu",
"push_installation_id": "***",
"push_installation_key": "***",
"job_poll_interval_ms": 30000,
"send_purge_schedule": "0 5 * * * *",
"trash_purge_schedule": "0 5 0 * * *",
"incomplete_2fa_schedule": "30 * * * * *",
"emergency_notification_reminder_schedule": "0 3 * * * *",
"emergency_request_timeout_schedule": "0 7 * * * *",
"event_cleanup_schedule": "0 10 0 * * *",
"auth_request_purge_schedule": "30 * * * * *",
"duo_context_purge_schedule": "30 * * * * *",
"purge_incomplete_sso_auth": "0 20 0 * * *",
"domain": "*****://********************",
"domain_set": true,
"domain_origin": "*****://********************",
"domain_path": "",
"web_vault_enabled": true,
"sends_allowed": true,
"hibp_api_key": null,
"user_attachment_limit": 524288,
"org_attachment_limit": 524288,
"user_send_limit": 102400,
"trash_auto_delete_days": 3650,
"incomplete_2fa_time_limit": 3,
"disable_icon_download": false,
"signups_allowed": false,
"signups_verify": true,
"signups_verify_resend_time": 3600,
"signups_verify_resend_limit": 6,
"signups_domains_whitelist": "***************,***************,***********",
"org_events_enabled": true,
"org_creation_users": "***",
"invitations_allowed": true,
"invitation_expiration_hours": 120,
"emergency_access_allowed": true,
"email_change_allowed": true,
"password_iterations": 600000,
"password_hints_allowed": true,
"show_password_hint": false,
"admin_token": "***",
"invitation_org_name": "Vaultwarden",
"events_days_retain": null,
"client_suppress_onboarding": true,
"ip_header": "X-Forwarded-For",
"_ip_header_enabled": true,
"ip_header_trusted_proxies": "local",
"icon_service": "internal",
"_icon_service_url": "",
"_icon_service_csp": "",
"icon_redirect_code": 302,
"icon_cache_ttl": 2592000,
"icon_cache_negttl": 259200,
"icon_download_timeout": 10,
"icon_blacklist_regex": null,
"icon_blacklist_non_global_ips": true,
"http_request_block_regex": null,
"http_request_block_non_global_ips": false,
"disable_2fa_remember": false,
"authenticator_disable_time_drift": false,
"experimental_client_feature_flags": "ssh-agent-v2,ssh-key-vault-item,pm-25373-windows-biometrics-v2,pm-26340-linux-biometrics-v2,pm-30529-webauthn-related-origins",
"require_device_email": false,
"reload_templates": false,
"extended_logging": true,
"log_timestamp_format": "%Y-%m-%d %H:%M:%S.%3f",
"use_syslog": false,
"log_file": "/data/vaultwarden.log",
"log_level": "info",
"enable_db_wal": false,
"db_connection_retries": 15,
"database_timeout": 30,
"database_idle_timeout": 600,
"database_max_conns": 10,
"database_min_conns": 2,
"database_conn_init": "",
"disable_admin_token": false,
"allowed_iframe_ancestors": "",
"allowed_connect_src": "",
"login_ratelimit_seconds": 60,
"login_ratelimit_max_burst": 10,
"unauthenticated_ratelimit_seconds": 60,
"unauthenticated_ratelimit_max_burst": 50,
"admin_ratelimit_seconds": 300,
"admin_ratelimit_max_burst": 3,
"admin_session_lifetime": 20,
"org_groups_enabled": true,
"increase_note_size_limit": false,
"_max_note_size": 10000,
"enforce_single_org_with_reset_pw_policy": false,
"dns_prefer_ipv6": false,
"sso_enabled": true,
"sso_only": true,
"sso_signups_match_email": true,
"sso_allow_unknown_email_verification": false,
"sso_client_id": "****************************************",
"sso_client_secret": "***",
"sso_authority": "*****://****************************************************",
"sso_scopes": "email profile offline_access",
"sso_authorize_extra_params": "",
"sso_pkce": true,
"sso_audience_trusted": null,
"sso_callback_path": "*****://*************************************************",
"sso_master_password_policy": null,
"sso_auth_only_not_session": false,
"sso_client_cache_expiration": 0,
"sso_debug_tokens": false,
"_enable_yubico": true,
"yubico_client_id": null,
"yubico_secret_key": null,
"yubico_server": null,
"_enable_duo": true,
"duo_use_iframe": false,
"duo_ikey": null,
"duo_skey": null,
"duo_host": null,
"_duo_akey": null,
"_enable_smtp": true,
"use_sendmail": false,
"sendmail_command": null,
"smtp_host": "*******************************************",
"smtp_ssl": null,
"smtp_explicit_tls": null,
"smtp_security": "off",
"smtp_port": 25,
"smtp_from": "********************",
"smtp_from_name": "***********",
"smtp_username": null,
"smtp_password": null,
"smtp_auth_mechanism": "Plain",
"smtp_timeout": 15,
"helo_name": "********************",
"smtp_embed_images": true,
"_smtp_img_src": "***:",
"smtp_debug": false,
"smtp_accept_invalid_certs": false,
"smtp_accept_invalid_hostnames": false,
"_enable_email_2fa": true,
"email_token_size": 6,
"email_expiration_time": 600,
"email_attempts_limit": 3,
"email_2fa_enforce_on_verified_invite": false,
"email_2fa_auto_fallback": false
}Vaultwarden Build Version
1.37.1-46d71107
Deployment method
Official Container Image
Custom deployment method
No response
Reverse Proxy
haproxy 3.3
Host/Server Operating System
Linux
Operating System Version
Win 11
Clients
Desktop
Client Version
2026.9.0
Steps To Reproduce
- Enable SSO with Authentik using the default session handling (
SSO_AUTH_ONLY_NOT_SESSION=false) andoffline_accessinSSO_SCOPES, so Authentik hands out a refresh token. - Log in with SSO on a few clients.
- Take Authentik down. In my case it was just a normal Authentik upgrade to 2026.8.3, down for a few minutes.
- Use a client while it's down, or wait until its access token is within 5 minutes of expiry, so it calls
/identity/connect/tokenwithgrant_type=refresh_token. - The client logs out.
Expected Result
A refresh that fails because the IdP can't be reached shouldn't end the session. The client should keep it, and the next refresh should work once the IdP is back. Logging out makes sense when the IdP actually rejects the refresh token, not when it's just unreachable.
Actual Result
Every client that tried to refresh while Authentik was down got logged out and had to go through SSO again. During the Authentik upgrade HAProxy had the Authentik backend marked down, so the provider's discovery URL returned 503, and Vaultwarden answered each refresh with 400 {"error":"invalid_grant"}, although nothing was wrong with the grant. Three clients were logged out within 18 seconds.
Logs
[2026-09-25 19:45:55.787][vaultwarden::sso_client][ERROR] Failed to discover OpenID provider: Server returned invalid response: HTTP status code 503 Service Unavailable at https://auth.example.com/application/o/vaultwarden/.well-known/openid-configuration
[2026-09-25 19:45:55.787][error][ERROR] Unable to refresh login credentials: Failed to discover OpenID provider: Server returned invalid response: HTTP status code 503 Service Unavailable at https://auth.example.com/application/o/vaultwarden/.well-known/openid-configuration
[2026-09-25 19:45:55.787][response][INFO] (login) POST /identity/connect/token => 400 Bad Request
(same three lines again at 19:46:11 and 19:46:13)Screenshots or Videos
No response
Additional Context
I went through the code on main (32098ca) to see where this comes from.
refresh_tokens() sends SSO sessions to sso::exchange_refresh_token(), which talks to the provider:
https://github.com/dani-garcia/vaultwarden/blob/32098ca7d1b94abce848b03e66545442a5d0e836/src/auth.rs#L1337-L1339
In my case it already failed at discovery, because the provider returned 503: https://github.com/dani-garcia/vaultwarden/blob/32098ca7d1b94abce848b03e66545442a5d0e836/src/sso_client.rs#L120
If discovery works but the token call fails, the error is turned into a plain string, so a connection error can't be told apart from a real invalid_grant answer anymore:
https://github.com/dani-garcia/vaultwarden/blob/32098ca7d1b94abce848b03e66545442a5d0e836/src/sso_client.rs#L318-L332
Either way, refresh_login() returns invalid_grant for any error:
https://github.com/dani-garcia/vaultwarden/blob/32098ca7d1b94abce848b03e66545442a5d0e836/src/api/identity.rs#L168-L174
and the clients log out on exactly 400 + invalid_grant:
https://github.com/bitwarden/clients/blob/2d5c6673c68356be85bcc05f016b3e088c0c6615/libs/common/src/services/api.service.ts#L1828-L1839
As far as I can tell, any other error just fails that one request and the client tries the refresh again later.
The invalid_grant response came in with #7105 (for #7060), and for expired or invalid refresh tokens that's correct and should stay. The side effect is that a short IdP outage now looks exactly like a revoked session. There was already a remark in the #7105 review about maybe giving the /connect/token endpoints more specific errors.
My suggestion: keep the openidconnect error type, return invalid_grant only when the provider itself answers invalid_grant (plus the existing cases like an invalid Vaultwarden refresh JWT), and return something like a 503 for connection errors, 5xx or unparseable responses and discovery failures. The check_validity() path (no refresh token, user_info check) probably needs the same.
SSO_AUTH_ONLY_NOT_SESSION=true avoids this, but then disabling a user in the IdP no longer ends their Vaultwarden sessions, so I'd rather keep the session tied to the IdP.
Source: dani-garcia/vaultwarden