Skip to content

feat(server-js): add revokeRefreshToken and logout revocation support - #214

Merged
jd3vi1 merged 9 commits into
mainfrom
SDK-8850
Jul 15, 2026
Merged

feat(server-js): add revokeRefreshToken and logout revocation support#214
jd3vi1 merged 9 commits into
mainfrom
SDK-8850

Conversation

@jd3vi1

@jd3vi1 jd3vi1 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds token revocation support to auth0-server-js so a logout or explicit revoke actually invalidates the refresh token at Auth0, not just clears the local session.

  • ServerClient.revokeRefreshToken(options?, storeOptions?) -- new public method that calls POST /oauth/revoke. Reads the refresh token from the session store by default; accepts an explicit token via options.token to bypass the session lookup.
  • logout({ revokeRefreshToken: true }) -- convenience option that revokes before clearing the session. Best-effort: revocation failure never blocks logout.
  • Resolver mode -- in resolver mode, the session's stored domain is used for the revocation request (preferred over calling the domain resolver), matching the behavior of the rest of the SDK.

Changes

  • packages/auth0-auth-js/src/auth-client.ts -- added revokeToken() method calling POST /oauth/revoke
  • packages/auth0-auth-js/src/types.ts -- added RevokeTokenOptions; fixed JSDoc citation to RFC 7009 only
  • packages/auth0-server-js/src/server-client.ts -- added revokeRefreshToken() and revokeRefreshToken: true option on logout()
  • packages/auth0-server-js/src/types.ts -- added RevokeRefreshTokenOptions and LogoutOptions.revokeRefreshToken
  • packages/auth0-server-js/src/errors.ts -- added TokenRevocationError
  • packages/auth0-server-js/EXAMPLES.md -- added "Revoking a Refresh Token" section covering all three usage patterns
  • examples/example-express-web -- wired POST /auth/revoke and GET /auth/logout-and-revoke routes into the existing Express example

Test plan

  • packages/auth0-auth-js: 360 tests pass (npm test)
  • packages/auth0-server-js: 370 tests pass (npm test)
  • New test coverage: revokeToken success, error, client credentials; revokeRefreshToken from session, explicit token, missing token, resolver mode; logout({ revokeRefreshToken: true }) success, no-op, failure swallowed, resolver mode via logout

Summary by CodeRabbit

  • New Features

    • Added support for revoking access and refresh tokens.
    • Added server-side refresh-token revocation, including optional explicit tokens.
    • Logout now attempts best-effort refresh-token revocation before completing.
    • Added refresh-token revocation to the Express example application.
  • Bug Fixes

    • Added clear errors when no refresh token is available.
    • Logout continues successfully if token revocation fails.
  • Documentation

    • Documented token revocation requirements, behavior, and usage.

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds OAuth token revocation to AuthClient, refresh-token revocation and logout integration to ServerClient, public error and option types, tests, documentation, and an Express example route and form.

Changes

Token Revocation Feature

Layer / File(s) Summary
Revocation contracts and errors
packages/auth0-auth-js/src/types.ts, packages/auth0-server-js/src/types.ts, packages/auth0-auth-js/src/errors.ts, packages/auth0-server-js/src/index.ts
Adds revocation option interfaces, TokenRevocationError, and the server-package error re-export.
AuthClient revocation flow
packages/auth0-auth-js/src/auth-client.ts, packages/auth0-auth-js/src/auth-client.spec.ts
Adds discovery-backed token revocation with optional token hints, client credentials, OAuth error conversion, and request/error tests.
ServerClient revocation and logout
packages/auth0-server-js/src/server-client.ts, packages/auth0-server-js/src/server-client.spec.ts
Adds refresh-token revocation from explicit input or session state, resolver-domain handling, best-effort logout revocation, and coverage for success, failure, and session behavior.
Revocation example and documentation
packages/auth0-server-js/EXAMPLES.md, examples/example-express-web/src/auth0.ts, examples/example-express-web/views/private.ejs
Documents revocation semantics and adds an Express POST route plus private-page form for revoking a refresh token.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Application
  participant ServerClient
  participant AuthClient
  participant Auth0
  participant StateStore
  Application->>ServerClient: revokeRefreshToken()
  ServerClient->>StateStore: read session refresh token
  StateStore-->>ServerClient: refresh token and domain
  ServerClient->>AuthClient: revokeToken(token, refresh_token)
  AuthClient->>Auth0: discover and revoke token
  Auth0-->>AuthClient: success or OAuth error
  AuthClient-->>ServerClient: completion or TokenRevocationError
  ServerClient-->>Application: completion or error
Loading

Suggested reviewers: tusharpandey13, nandan-bhat, pmathew92

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding refresh-token revocation support and logout revocation behavior.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch SDK-8850

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install timed out. The project may have too many dependencies for the sandbox.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@jd3vi1
jd3vi1 marked this pull request as ready for review July 7, 2026 12:37
@jd3vi1
jd3vi1 requested a review from nandan-bhat July 7, 2026 12:40

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/auth0-server-js/src/server-client.ts (1)

1098-1106: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Duplicate session-store read on the resolver-mode logout path.

revokeRefreshToken({}, storeOptions) internally fetches stateData (per the sibling comment above), and then logout() fetches it again at line 1114 for resolver-mode domain checks — two round-trips to the store per logout call in multi-tenant setups. Also, the try {} catch {} around revocation only bounds failures, not latency: a slow/hanging revocation endpoint will still stall logout() since it's awaited before continuing, undermining the "best-effort" intent for responsiveness (not just correctness).

Consider restructuring so logout() fetches stateData once and passes the already-known token/domain into the revocation call, and optionally bound the revoke call with a timeout so a slow endpoint can't delay the redirect response.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/auth0-server-js/src/server-client.ts` around lines 1098 - 1106,
`logout()` is doing duplicate session-state lookups on the resolver-mode path
and still waits unbounded on refresh-token revocation. Update `logout()` in
`server-client.ts` so it reads `stateData` once and reuses the existing
token/domain information when calling `revokeRefreshToken`, instead of letting
that method fetch the same store data again; use the
`logout`/`revokeRefreshToken` flow to pass the known context through. Also make
the best-effort revocation non-blocking for slow endpoints by adding a timeout
around the awaited revoke call so logout can continue promptly even if
revocation hangs.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/auth0-server-js/src/server-client.ts`:
- Around line 1098-1106: `logout()` is doing duplicate session-state lookups on
the resolver-mode path and still waits unbounded on refresh-token revocation.
Update `logout()` in `server-client.ts` so it reads `stateData` once and reuses
the existing token/domain information when calling `revokeRefreshToken`, instead
of letting that method fetch the same store data again; use the
`logout`/`revokeRefreshToken` flow to pass the known context through. Also make
the best-effort revocation non-blocking for slow endpoints by adding a timeout
around the awaited revoke call so logout can continue promptly even if
revocation hangs.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: db6538bf-5405-4bf0-bc00-fa7e5c296d8c

📥 Commits

Reviewing files that changed from the base of the PR and between d86a8cb and 51b4eaa.

📒 Files selected for processing (9)
  • .npmrc
  • packages/auth0-auth-js/src/auth-client.spec.ts
  • packages/auth0-auth-js/src/auth-client.ts
  • packages/auth0-auth-js/src/errors.ts
  • packages/auth0-auth-js/src/types.ts
  • packages/auth0-server-js/src/index.ts
  • packages/auth0-server-js/src/server-client.spec.ts
  • packages/auth0-server-js/src/server-client.ts
  • packages/auth0-server-js/src/types.ts

Comment thread packages/auth0-server-js/src/server-client.ts
Comment thread packages/auth0-server-js/src/server-client.ts Outdated
Comment thread packages/auth0-server-js/src/server-client.ts
Comment thread packages/auth0-server-js/src/server-client.spec.ts Outdated
Comment thread packages/auth0-server-js/src/server-client.spec.ts Outdated
Comment thread packages/auth0-auth-js/src/auth-client.spec.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/auth0-server-js/EXAMPLES.md`:
- Around line 1509-1510: The logout documentation overstates cleanup behavior
after refresh token revocation failure. Update the wording around logout() and
revokeRefreshToken handling to say logout still proceeds best-effort, but local
session deletion only happens in resolver mode when the stored session domain
matches the resolved domain; reference logout() and the session
cleanup/resolver-mode flow so the docs match the actual implementation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e66dbcc5-6119-4c6c-9819-351891cca851

📥 Commits

Reviewing files that changed from the base of the PR and between 51b4eaa and 1d52632.

📒 Files selected for processing (4)
  • packages/auth0-auth-js/src/auth-client.spec.ts
  • packages/auth0-server-js/EXAMPLES.md
  • packages/auth0-server-js/src/server-client.spec.ts
  • packages/auth0-server-js/src/server-client.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/auth0-auth-js/src/auth-client.spec.ts
  • packages/auth0-server-js/src/server-client.ts
  • packages/auth0-server-js/src/server-client.spec.ts

Comment thread packages/auth0-server-js/EXAMPLES.md Outdated
@jd3vi1 jd3vi1 changed the title added token revocation support in auth0-server-js feat(server-js): add revokeRefreshToken and logout revocation support Jul 9, 2026
@jd3vi1
jd3vi1 requested a review from nandan-bhat July 10, 2026 08:51
nandan-bhat
nandan-bhat previously approved these changes Jul 10, 2026
Piyush-85
Piyush-85 previously approved these changes Jul 14, 2026

@Piyush-85 Piyush-85 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/auth0-server-js/src/server-client.ts`:
- Around line 1132-1137: Update both logout revocation catch blocks in
server-client.ts (1132-1137 and 1155-1160) to silently ignore
MissingSessionError while retaining console.warn for all other revocation
failures. Apply the same error discrimination in both the non-resolver and
resolver logout branches.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 00fc5924-ceb8-49c7-a5c2-9d4afa79a32e

📥 Commits

Reviewing files that changed from the base of the PR and between 3fbca81 and ae7b9c4.

📒 Files selected for processing (5)
  • examples/example-express-web/src/auth0.ts
  • packages/auth0-server-js/EXAMPLES.md
  • packages/auth0-server-js/src/server-client.spec.ts
  • packages/auth0-server-js/src/server-client.ts
  • packages/auth0-server-js/src/types.ts
💤 Files with no reviewable changes (2)
  • packages/auth0-server-js/src/types.ts
  • examples/example-express-web/src/auth0.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/auth0-server-js/EXAMPLES.md

Comment on lines +1132 to +1137
try {
await this.revokeRefreshToken({}, storeOptions);
} catch (e) {
// best-effort: revocation failure must not block logout
console.warn('revokeRefreshToken failed during logout (swallowed):', e);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Prevent log pollution for sessions without a refresh token.

Because logout now attempts token revocation by default, users who logged in without requesting the offline_access scope will legitimately lack a refresh token. This predictably causes revokeRefreshToken to throw a MissingSessionError, which is caught and logged as a warning, resulting in log spam on every such logout.

Silently ignore MissingSessionError to avoid warning on this expected state, while preserving the warning for actual revocation failures (like network or configuration errors).

  • packages/auth0-server-js/src/server-client.ts#L1132-L1137: Ignore MissingSessionError in the non-resolver mode logout branch.
  • packages/auth0-server-js/src/server-client.ts#L1155-L1160: Ignore MissingSessionError in the resolver mode logout branch.
🛠️ Proposed fix (applies to both locations)
       try {
         await this.revokeRefreshToken({}, storeOptions);
       } catch (e) {
-        // best-effort: revocation failure must not block logout
-        console.warn('revokeRefreshToken failed during logout (swallowed):', e);
+        if (!(e instanceof MissingSessionError)) {
+          // best-effort: revocation failure must not block logout
+          console.warn('revokeRefreshToken failed during logout (swallowed):', e);
+        }
       }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
try {
await this.revokeRefreshToken({}, storeOptions);
} catch (e) {
// best-effort: revocation failure must not block logout
console.warn('revokeRefreshToken failed during logout (swallowed):', e);
}
try {
await this.revokeRefreshToken({}, storeOptions);
} catch (e) {
if (!(e instanceof MissingSessionError)) {
// best-effort: revocation failure must not block logout
console.warn('revokeRefreshToken failed during logout (swallowed):', e);
}
}
📍 Affects 1 file
  • packages/auth0-server-js/src/server-client.ts#L1132-L1137 (this comment)
  • packages/auth0-server-js/src/server-client.ts#L1155-L1160
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/auth0-server-js/src/server-client.ts` around lines 1132 - 1137,
Update both logout revocation catch blocks in server-client.ts (1132-1137 and
1155-1160) to silently ignore MissingSessionError while retaining console.warn
for all other revocation failures. Apply the same error discrimination in both
the non-resolver and resolver logout branches.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants