#5039·dex

Refresh grant returns `invalid_request` instead of `invalid_grant` for invalid, reused or expired refresh tokens

Author: and-winCreated Sep 24, 2026Updated Sep 24, 2026

Preflight Checklist

  • I agree to follow the Code of Conduct that this project adheres to.
  • I have searched the issue tracker for an issue that matches the one I want to file, without success.
  • I am not looking for support or already pursued the available support channels without success.

Version

master, commit 56958b1ad2ad7e62765b3e8fc79fe5464d14e7c7 (in production). The same code is on current master 98e0af563213b163ccaed6bd1b8314e2fa22c641.

Storage Type

MySQL

Installation Type

Custom container image

Expected Behavior

When a client sends a refresh token that is unknown, already rotated or expired, Dex should answer 400 with error=invalid_grant.

RFC 6749, section 5.2 defines invalid_grant as: "The provided authorization grant (e.g., authorization code, resource owner credentials) or refresh token is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client." invalid_request is for a request that is missing a parameter or is malformed.

Actual Behavior

Dex returns invalid_grant only when the token belongs to another client. For all other rejected tokens it returns invalid_request:

  • unknown token, for example deleted because the same user logged in again on the same client: invalid_request, "Refresh token is invalid or has already been claimed by another client."
  • already rotated token: the same invalid_request
  • expired token (absoluteLifetime / validIfNotUsedFor): invalid_request, "Refresh token expired."

The mapping is in server/grants/refresh.go#L293-L307.

Why this matters: clients use invalid_grant as the signal "this refresh token is dead, start a new login". With invalid_request they treat the error as temporary and keep the dead token. We hit this with the Jenkins oic-auth plugin: it drops the session only on invalid_grant. On invalid_request it returns 401 on every request and keeps the session, so users are stuck until they clear their cookies.

A second, smaller point: the "unknown token" case is not logged at all (refresh_lookup.go#L31-L37), while "claimed twice" and "expired" are logged. In our case this was the most common rejection, and the Dex logs did not show it, which made the problem hard to find.

Steps To Reproduce

  1. Configure a static client with offline_access (no expiry section, default rotation).
  2. Log in as user A with scope openid offline_access and save the refresh token R1.
  3. Log in again as user A on the same client. Dex replaces the user's refresh token for this client and deletes R1.
  4. Call the token endpoint with grant_type=refresh_token and R1.
  5. The response is 400 {"error":"invalid_request","error_description":"Refresh token is invalid or has already been claimed by another client."}, and there is no log line for it.

The same invalid_request comes back if you refresh R1, get R2, and then refresh R1 again.

Additional Information

  • Dex already changed other cases to invalid_grant for the same reason: #1952 (invalid or expired auth codes) and #2344 (token of another client). The remaining refresh cases seem to be left over.
  • Related reports with the same error text: #2613, #1976.
  • I will open a PR with a fix and a test.

Configuration

Not relevant: no expiry section, MySQL storage, one microsoft connector.

Logs

The "unknown token" case writes nothing in Dex. Client side (Jenkins oic-auth):

OidcTokenException: Bad token response, error=invalid_request, description=Refresh token is invalid or has already been claimed by another client., status=400