Skip to content

[codex] Preserve offline refresh-token semantics - #205

Merged
salasebas merged 2 commits into
mainfrom
advisor/002-preserve-better-auth-offline-refresh
Jul 23, 2026
Merged

[codex] Preserve offline refresh-token semantics#205
salasebas merged 2 commits into
mainfrom
advisor/002-preserve-better-auth-offline-refresh

Conversation

@salasebas

@salasebas salasebas commented Jul 3, 2026

Copy link
Copy Markdown
Owner

Summary

  • Preserve Better Auth-compatible OAuth offline_access behavior after the originating web session ends.
  • Keep valid access and refresh tokens active through introspection while omitting stale sid values after sign-out or web-session expiry.
  • Prevent custom opaque-token claims from overriding reserved introspection claims.
  • Return exactly { "active": false } for expired opaque access tokens and expired or revoked refresh tokens without unnecessary downstream lookups.
  • Add regression coverage and upstream mapping notes for these behaviors.

Why

Offline OAuth refresh tokens are delegated client grants and should not silently become invalid when the RustAuth web session ends. Introspection must reflect token validity independently, avoid stale session identifiers, protect canonical claims from custom resolvers, and minimize information returned for inactive tokens.

Impact

Clients using offline_access keep their expected refresh behavior after sign-out. Active token introspection omits stale sid values, custom claims cannot replace canonical fields, and inactive-token responses are minimal and consistent.

Validation

  • cargo nextest run -p rustauth-oauth-provider --all-features -E "test(/(inactive_token_introspection|custom_access_claims_cannot|introspection_keeps_tokens|refresh_token_grant_allows)/)"
  • cargo fmt --all --check
  • cargo clippy --workspace --all-targets --all-features -- -D warnings
  • cargo nextest run -p rustauth-oauth-provider --all-features

@vercel

vercel Bot commented Jul 3, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
rustauth-docs-site Ignored Ignored Jul 23, 2026 5:44am

@github-actions github-actions Bot added the oauth label Jul 3, 2026

@salasebas salasebas left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes requested

GitHub does not allow the PR author to submit a formal REQUEST_CHANGES review on their own PR, so this review records the required changes explicitly.

The target behavior is correct and matches Better Auth: deleting the web session must not invalidate offline access/refresh tokens, and introspection should omit a stale sid. Please address these issues before merge:

  1. Apply custom claims before reserved introspection claims. In opaque access-token introspection, custom_access_token_claims is extended after the filtered sid and standard fields are built. A resolver can therefore reintroduce a stale sid or overwrite active, client_id, sub, etc. Resolve custom claims first, then stamp the standard/reserved claims (or reject reserved keys), and add a collision regression test.

  2. Return exactly { "active": false } for inactive tokens before session/custom lookups. Expired opaque access tokens and expired/revoked refresh tokens currently continue building metadata and querying the session. Upstream returns early. The current behavior leaks unnecessary metadata and can turn a deterministic inactive response into a database/resolver error.

  3. Strengthen the session-deletion tests. Assert that introspection contains sid before deletion, then that the same still-active token omits it afterward. Prefer exercising the real sign-out/logout path, or rename/document the test as direct session deletion; also cover an expired session.

The refresh-token rotation race discussed separately is pre-existing and is not being attributed to this PR. It remains a release-level prerequisite rather than an additional finding introduced by this change.

@salasebas
salasebas force-pushed the advisor/002-preserve-better-auth-offline-refresh branch from 42e913c to e7f1b1a Compare July 17, 2026 03:38
@salasebas
salasebas force-pushed the advisor/002-preserve-better-auth-offline-refresh branch from e7f1b1a to cf0d3b1 Compare July 23, 2026 05:44
@salasebas
salasebas marked this pull request as ready for review July 23, 2026 05:50
@salasebas
salasebas merged commit 3490e11 into main Jul 23, 2026
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant