Repository navigation
Add OIDC token preference for determining session expiry - #1337
Merged
taranvohra merged 2 commits intoOct 30, 2026
Merged
taranvohra merged 2 commits into
taranvohra merged 2 commits into
Conversation
Site admins can now choose whether the GitBook session token expiry is derived from the ID token or the access token returned by the authentication provider. - ID token (default): the `exp` claim, as before, so existing installations are unaffected. - Access token: the `expires_in` of the token response, counted from the moment the token is exchanged, falling back to the minimum session duration when the provider omits it. Session lifetimes are clamped between 1 hour and 7 days regardless of the source, so a long-lived upstream token can no longer mint a GitBook session that outlives a revoked visitor's access by weeks. `OIDCTokenResponseData` is updated to match RFC 6749 section 5.1 and OIDC Core section 3.1.3.3: `id_token`, `access_token` and `token_type` are required, `expires_in`, `refresh_token` and `scope` optional. The runtime guards stay, since the response is untrusted input. The expiry logic moves to `src/session-expiry.ts` so it can be unit tested without pulling in the integration entrypoint. Ref: RND-13568
🦋 Changeset detectedLatest commit: 7ff0947 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
`compilerOptions.types` replaces the list inherited from @gitbook/tsconfig/integration.json rather than extending it, so adding `bun` for `bun:test` dropped `@cloudflare/workers-types` and with it the `Response.json<T>()` generic the token exchange relies on.
Member
Author
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
spastorelli
approved these changes
Oct 30, 2026
taranvohra
deleted the
taran/rnd-13568-add-oidc-token-preference-for-determining-session-expiry
branch
October 30, 2026 13:42
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.
Closes RND-13568
What
Site admins can choose which token returned by their authentication provider drives the expiry of the GitBook session token, via a new Session Expiry select in the OIDC configuration.
expclaim, exactly as today, so existing installations are unaffected.expires_inof the token response, counted from the moment the token is exchanged. Falls back to the minimum session duration when the provider omits it (expires_inis only RECOMMENDED by RFC 6749).Session lifetimes are now clamped between 1 hour and 7 days regardless of the source.
Why cap both sources
The cap is about bounding how long a revoked visitor keeps access, and that reasoning does not depend on which token you read — capping only the access-token path would leave the ID-token path able to mint a multi-month GitBook session from a long-lived
expclaim.This is technically a behaviour change for anyone whose IdP issues ID tokens with
expbeyond 7 days. In practice ID token lifetimes are minutes to hours, so I would expect no installation to be affected, but flagging it rather than burying it.Token response type
OIDCTokenResponseDatanow matches RFC 6749 §5.1 and OIDC Core §3.1.3.3:id_tokenaccess_tokentoken_type'Bearer'literal, the spec makes it case-insensitiveexpires_inrefresh_tokenscopeThe runtime guards stay in place — the response is untrusted input whatever the spec requires.
Tests
The expiry logic moved to
src/session-expiry.tsso it can be unit tested without pulling in the integration entrypoint, matching the existingpkce.ts/cookie.ts/logout-hint.tssplit. 14 tests cover source selection, the floor and the cap, the missing-expires_infallback, stringexpires_in(some providers send it that way), and junk values.This adds
"test": "bun test"and"types": ["bun"]to the integration, copying the webhook integration's setup.Note
tsc --noEmitreports a pre-existingFetchVisitorAuthenticationEvent.cookieserror onsrc/index.tsx, unrelated to this branch — it reproduces onmainand comes from a localbun.lockchange that is not part of this PR.