Repository navigation
Conversation
…ID/OAuth2 When the identity provider returns no refresh token (e.g. Google when the account already granted consent), login and /auth/refresh were rejected with "No [OpenID] Session found". Add an opt-in provider option; with `false`, a missing refresh token no longer rejects and the Directus session is authoritative. A stored refresh token is still exchanged at the provider and a revoked grant still ends the session. Default (`true`) keeps current behavior. Refs LaWebcapsule#401 Signed-off-by: Kyrylo Kuzmytskyi <slykirill@gmail.com>
Address review on LaWebcapsule#401: - getUserID() no longer overwrites a stored refresh token with null when the provider issues none on login (e.g. Google skipping consent); the stored token is still exchanged in refresh(). Empty updates are skipped to keep the LaWebcapsule#127 crash fix. - With REQUIRE_REFRESH_TOKEN=true (default), a missing refresh token now throws InvalidTokenException, so the OpenID/OAuth2 callbacks retry once with prompt=consent instead of failing the login. Refs LaWebcapsule#401 Signed-off-by: Kyrylo Kuzmytskyi <slykirill@gmail.com>
slyk
added a commit
to slyk/d9
that referenced
this pull request
Oct 15, 2026
…k only) Signed-off-by: Kyrylo Kuzmytskyi <slykirill@gmail.com>
Contributor
|
Hello @slyk, |
louisdussarps
approved these changes
Oct 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Change description
Lets OpenID and OAuth2 logins work when the identity provider returns no refresh token (for example Google when the
account has already granted consent). Today such a login, and every
/auth/refreshafter it, is rejected withINVALID_CREDENTIALS/ "No [OpenID] Session found". Discussed and agreed in #401.AUTH_<PROVIDER>_REQUIRE_REFRESH_TOKEN(defaulttrue, current behavior). Withfalse, a missingrefresh token no longer rejects the login or the session renewal; the d9 session is then the only source of truth for
that user. A refresh token that is stored is still exchanged at the provider, and a revoked grant still ends the
session.
getUserID()used to writeauth_data: userPayload.auth_data ?? null, so alogin without a new refresh token overwrote a still-valid stored one with
null. It now writesauth_dataonly whenthe provider returned a new token. An update with nothing to write is skipped, so the empty
.update()crash from Empty update in auth drivers thows an error, preventing login #127stays fixed.
true), the missing-token branch ofrefresh()throwsInvalidTokenExceptioninstead ofInvalidCredentialsException. The OpenID and OAuth2 callbacks already catch it andredirect once with
prompt=consent, so Google shows the consent screen, returns a refresh token and the loginsucceeds without any extra configuration. The existing
promptflag prevents a loop: if the provider still sends notoken after consent, the login fails as before, and that is where the new option applies.
/auth/refreshthe missing-token case now returns 403INVALID_TOKEN(what a revoked token already returns)instead of 401
INVALID_CREDENTIALS. The app logs out on either.config-options.md(with the trade-off) and a consent-screen tip in the Google section ofsso.md.@wbce-d9/apiminor.Testing note
As mentioned in #401: this was tested against Google only, in our own setup (one Google Cloud project, several d9
instances, each a separate OAuth client, all used by the same few accounts). It was not tested against other providers
or with many different client configurations. A Keycloak setup that issues no refresh token (or a client with offline
access disabled) should reproduce Google's behavior. Cases worth checking:
prompt=consent, then login works.REQUIRE_REFRESH_TOKEN=false, no token: login and/auth/refreshwork./auth/refresh.Unit tests for these paths are in
api/src/auth/drivers/baseoauth.test.ts(10 tests;openid.test.tsstill passes).Type of change
Related issues
Checklists
Development
Security
The new option is off by default. With
false, a user's d9 session is no longer checked against the provider when norefresh token is stored, so removing the user at the provider does not end their d9 session until it expires; this is
stated in the docs. When a token is stored, it is still checked as before.
Network
No new endpoints or network configuration.
Code review
necessary