Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems with authentik and vaultwarden sso (Request to exchange_refresh_token endpoint failed) #75

Open
dasbenjo opened this issue Aug 27, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@dasbenjo
Copy link

dasbenjo commented Aug 27, 2024

Vaultwarden Docker file

authentik hosted on the same machine

services:
  vaultwarden:
    image: timshel/vaultwarden:latest
    container_name: vaultwarden
    restart: always
    environment:
      - DOMAIN=https://vaultwarden.domain.name  # required when using a reverse proxy; your domain; vaultwarden needs to know it's https to work properly with attachments
      - SIGNUPS_ALLOWED=false # Deactivate this with "false" after you have created your account so that no strangers can register
      - PUSH_ENABLED=true
      - PUSH_INSTALLATION_ID=redacted
      - PUSH_INSTALLATION_KEY=redacted
      - PUSH_RELAY_URI=https://api.bitwarden.eu
      - PUSH_IDENTITY_URI=https://identity.bitwarden.eu
        # Settings
      - SENDS_ALLOWED=false
      - ORG_ATTACHMENT_LIMIT=5000
      - USER_ATTACHMENT_LIMIT=3000
      - INVITATION_ORG_NAME=NAME
      - EMAIL_CHANGE_ALLOWED=false
      - TEMPLATES_FOLDER=data/templates
        # Email Setup
      - SMTP_HOST=mail.domain.name
      - [email protected]
      - SMTP_FROM_NAME=NAME
      - SMTP_PORT=465
      - SMTP_SECURITY=force_tls
      - [email protected]
      - SMTP_PASSWORD=PASSWORD
        # Log Level, standard is info
      - LOG_LEVEL=warn
      - EXTENDED_LOGGING=true
        # SSO Settings
      - SSO_ENABLED=true
      - SSO_ONLY=true
      - SSO_FRONTEND=override
      - SSO_CLIENT_ID=redacted
      - SSO_CLIENT_SECRET=redacted
      - SSO_AUTHORITY=https://authentik.domain.name/application/o/vault/
      - SSO_SCOPES=email profile openid offline_access
      - SSO_PKCE=true
    volumes:
      - ./vw-data:/data # the path before the : can be changed
    ports:
      - 11001:80 # you can replace the 11001 with your preferred port

Steps To Reproduce

start and run container with docker compose

Expected Result

a stable connection with browser extensions and apps

Actual Result

I can login, and use all apps and the browser extension, but I am logged out after a random time (there is no pattern, but the session lasts only 1-2 days maximum)

Screenshots or Videos

oidc provider config in authentik

image

Logs

[2024-08-27 21:29:11.724][request][INFO] GET /alive
[2024-08-27 21:29:11.725][response][INFO] (alive) GET /alive => 200 OK
[2024-08-27 21:29:17.352][request][INFO] POST /identity/connect/token
[2024-08-27 21:29:17.408][reqwest::connect][DEBUG] starting new connection: https://authentik.domain.name/
[2024-08-27 21:29:17.953][request][INFO] POST /identity/connect/token
[2024-08-27 21:29:17.962][reqwest::connect][DEBUG] starting new connection: https://authentik.domain.name/
[2024-08-27 21:29:17.986][reqwest::connect][DEBUG] starting new connection: https://authentik.domain.name/
[2024-08-27 21:29:18.518][reqwest::connect][DEBUG] starting new connection: https://authentik.domain.name/
[2024-08-27 21:29:18.559][reqwest::connect][DEBUG] starting new connection: https://authentik.domain.name/
[2024-08-27 21:29:19.090][vaultwarden::sso][DEBUG] Non jwt refresh_token (expiration set to 1727386159)
[2024-08-27 21:29:19.093][response][INFO] (login) POST /identity/connect/token => 200 OK
[2024-08-27 21:29:19.100][reqwest::connect][DEBUG] starting new connection: https://authentik.domain.name/
[2024-08-27 21:29:19.202][vaultwarden::sso][ERROR] Request to exchange_refresh_token endpoint failed: ServerResponse(StandardErrorResponse { error: invalid_grant, error_description: Some("The provided authorization grant or refresh token is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client"), error_uri: None })
[2024-08-27 21:29:19.202][vaultwarden::api::identity][ERROR] {"error":"","errorModel":{"message":"Request to exchange_refresh_token endpoint failed: ServerResponse(StandardErrorResponse { error: invalid_grant, error_description: Some(\"The provided authorization grant or refresh token is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client\"), error_uri: None })","object":"error"},"error_description":"","exceptionMessage":null,"exceptionStackTrace":null,"innerExceptionMessage":null,"message":"Request to exchange_refresh_token endpoint failed: ServerResponse(StandardErrorResponse { error: invalid_grant, error_description: Some(\"The provided authorization grant or refresh token is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client\"), error_uri: None })","object":"error","validationErrors":{"":["Request to exchange_refresh_token endpoint failed: ServerResponse(StandardErrorResponse { error: invalid_grant, error_description: Some(\"The provided authorization grant or refresh token is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client\"), error_uri: None })"]}}
[2024-08-27 21:29:19.203][response][INFO] (login) POST /identity/connect/token => 401 Unauthorized
[2024-08-27 21:29:19.402][request][INFO] POST /identity/connect/token
[2024-08-27 21:29:19.434][reqwest::connect][DEBUG] starting new connection: https://authentik.domain.name/
[2024-08-27 21:29:19.997][reqwest::connect][DEBUG] starting new connection: https://authentik.domain.name/
[2024-08-27 21:29:20.146][request][INFO] GET /api/config/
[2024-08-27 21:29:20.146][response][INFO] (config) GET /api/config => 200 OK
[2024-08-27 21:29:20.525][reqwest::connect][DEBUG] starting new connection: https://authentik.domain.name/
[2024-08-27 21:29:20.539][request][INFO] GET /api/config/
[2024-08-27 21:29:20.539][response][INFO] (config) GET /api/config => 200 OK
[2024-08-27 21:29:20.624][vaultwarden::sso][ERROR] Request to exchange_refresh_token endpoint failed: ServerResponse(StandardErrorResponse { error: invalid_grant, error_description: Some("The provided authorization grant or refresh token is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client"), error_uri: None })
[2024-08-27 21:29:20.625][vaultwarden::api::identity][ERROR] {"error":"","errorModel":{"message":"Request to exchange_refresh_token endpoint failed: ServerResponse(StandardErrorResponse { error: invalid_grant, error_description: Some(\"The provided authorization grant or refresh token is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client\"), error_uri: None })","object":"error"},"error_description":"","exceptionMessage":null,"exceptionStackTrace":null,"innerExceptionMessage":null,"message":"Request to exchange_refresh_token endpoint failed: ServerResponse(StandardErrorResponse { error: invalid_grant, error_description: Some(\"The provided authorization grant or refresh token is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client\"), error_uri: None })","object":"error","validationErrors":{"":["Request to exchange_refresh_token endpoint failed: ServerResponse(StandardErrorResponse { error: invalid_grant, error_description: Some(\"The provided authorization grant or refresh token is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client\"), error_uri: None })"]}}
[2024-08-27 21:29:20.625][response][INFO] (login) POST /identity/connect/token => 401 Unauthorized
[2024-08-27 21:29:20.898][request][INFO] GET /api/config/
[2024-08-27 21:29:20.898][response][INFO] (config) GET /api/config => 200 OK

Additional Context

No response

Host/Server Operating System

Linux

Operating System Version

Ubuntu 20.04

Deployment method

Official Container Image

Custom deployment method

No response

Vaultwarden Build Version

1.32.0-2

Clients

Browser Extension, Android

Client Version

2024.8.0

@dasbenjo dasbenjo added the bug Something isn't working label Aug 27, 2024
@Timshel
Copy link
Owner

Timshel commented Aug 28, 2024

Erf look like a case of the client sending two request to refresh the token at the same time :( :

[2024-08-27 21:29:17.352][request][INFO] POST /identity/connect/token
[2024-08-27 21:29:17.953][request][INFO] POST /identity/connect/token
[2024-08-27 21:29:19.093][response][INFO] (login) POST /identity/connect/token => 200 OK
[2024-08-27 21:29:19.203][response][INFO] (login) POST /identity/connect/token => 401 Unauthorized

The first one is going through ok but the second one fail since the token has already been exchanged once :(.

Had to revert some code which invalidated the refresh token for the default Vaultwarden session handling.

Will look again at the client, but outside the web-vault, I can't distribute a fix so would have to wait for a PR to be merged (which can take quite a bit of time if it's even accepted).

In the meantime unless there is some setting that could allow Authentik to accept the refresh_token a second time for a short period of time only solution I can propose is to activate: SSO_AUTH_ONLY_NOT_SESSION which will fallback to use the default Vaultwarden session (refresh_token will have a 30days expiration idle time).

@dasbenjo
Copy link
Author

thank you for your quick and detailed answer (and thank you for all the work on oicd and vaultwarden!)

Sadly there is no config in authentik to accept the refresh token a second time, but thanks for tip with SSO_AUTH_ONLY_NOT_SESSION, that's a good workaround 💪

@Timshel
Copy link
Owner

Timshel commented Aug 29, 2024

Had a look at the Bitwarden client code and implemented what I had in mind to prevent parallel calls.

We will see how the PR bitwarden/clients#10799 goes :)

@dasbenjo
Copy link
Author

wow, that was fast! Fingers crossed that it will be accepted quickly 🤞💪

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants