Skip to content

fix(backend): return actionable error when verifyToken receives an OAuth access token - #11034

Open
RealAdii wants to merge 1 commit into
clerk:mainfrom
RealAdii:fix/verify-token-oauth-jwt-error
Open

RealAdii wants to merge 1 commit into
clerk:mainfrom
RealAdii:fix/verify-token-oauth-jwt-error

Conversation

@RealAdii

Copy link
Copy Markdown

Description

Update verifyToken() in @clerk/backend to detect OAuth 2.0 JWT access tokens (typ: 'at+jwt' or 'application/at+jwt') and OAuth headerType options and return a clear token-invalid error directing callers to authenticateRequest(request, { acceptsToken: 'oauth_token' }) instead of 'Invalid session token category.'. Also clarify in the @clerk/backend 3.28.0 changelog entry that OAuth JWT access tokens are rejected by verifyToken() alongside OIDC id_tokens.

Fixes #11026

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

@changeset-bot

changeset-bot Bot commented Nov 29, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 300af84

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 11 packages
Name Type
@clerk/backend Patch
@clerk/astro Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/hono Patch
@clerk/nextjs Patch
@clerk/nuxt Patch
@clerk/react-router Patch
@clerk/tanstack-react-start Patch
@clerk/testing Patch
@clerk/swingset Patch

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

@vercel

vercel Bot commented Nov 29, 2026

Copy link
Copy Markdown

@RealAdii is attempting to deploy a commit to the Clerk Production Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

verifyToken() now returns an OAuth-specific token-invalid error when a JWT uses an OAuth access-token type or the headerType options allow only OAuth access-token types. Tests cover these cases and session-token verification when headerType includes JWT. The changeset and changelog document the error and direct callers to authenticateRequest() with acceptsToken: '***REDACTED_SECRET_ASSIGNMENT***'.

Estimated code review effort: 2 (Simple) | ~10 minutes

Severity of issue fixed: Medium

Suggested reviewers: dominic-clerk, wobsoriano, clerk-cookie

Merge Risk: Minimal · up to 300af

verifyToken now returns a clearer error directing callers to authenticateRequest with acceptsToken set to [REDACTED] when given an OAuth access-token JWT. Session token verification is unchanged. No actionable merge risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: verifyToken() now returns an actionable error when it receives an OAuth access token. The changeset, verify.ts, and tests all match this. The title uses the convention…
Description check Passed The description states the change. It says verifyToken() in @clerk/backend now detects OAuth 2.0 JWT access tokens and OAuth headerType options, returns a token-invalid error, and clarifies the 3.28.0…
Linked Issues check Passed Issue #11026 asks for two changes that the PR scope covers: (1) when a token has OAuth typ (at+jwt or application/at+jwt) or the OAuth headerType is requested, verifyToken() should return an…
Out of Scope Changes check Passed All changed files relate to the linked issue. verify.ts contains the new OAuth detection and error message. verify.test.ts tests that logic. CHANGELOG.md clarifies the 3.28.0 entry as the issue …
Full details: Title check

Explanation

The title names the main change: verifyToken() now returns an actionable error when it receives an OAuth access token. The changeset, verify.ts, and tests all match this. The title uses the conventional fix(backend): prefix and stays specific.

Full details: Description check

Explanation

The description states the change. It says verifyToken() in @clerk/backend now detects OAuth 2.0 JWT access tokens and OAuth headerType options, returns a token-invalid error, and clarifies the 3.28.0 changelog entry. It also links issue #11026 and includes a checklist. It matches the changeset.

Full details: Linked Issues check

Explanation

Issue #11026 asks for two changes that the PR scope covers: (1) when a token has OAuth typ (at+jwt or application/at+jwt) or the OAuth headerType is requested, verifyToken() should return an error naming authenticateRequest({ acceptsToken: '***REDACTED_SECRET_ASSIGNMENT***' }) instead of 'Invalid session token category.'; (2) the 3.28.0 changelog entry should mention OAuth access tokens and the replacement. In packages/backend/src/tokens/verify.ts, the head adds a check on header.typ (via the existing OAUTH_ACCESS_TOKEN_TYPES import from ./machine) and on options.headerType. When either matches, the function returns a TokenInvalid error with the OAuth-specific message. Otherwise the existing category error is kept. packages/backend/CHANGELOG.md is updated for the 3.28.0 entry, and a patch changeset is added. Tests in verify.test.ts cover the OAuth typ cases, the OAuth-only headerType case, and a session JWT with headerType including JWT. Issue suggestions 3 (deprecate or document headerType) and 4 (public token-only verifier) are not in the PR scope. The linked issue itself says the author will send a PR for items 1 and 2 only, and the PR objectives state that the PR does not address 3 and 4. Those are not required here.

Full details: Out of Scope Changes check

Explanation

All changed files relate to the linked issue. verify.ts contains the new OAuth detection and error message. verify.test.ts tests that logic. CHANGELOG.md clarifies the 3.28.0 entry as the issue requests. The .changeset file adds the patch note for @clerk/backend. The verify.ts diff adds no unrelated logic, and the existing JWT-template exception and the non-OAuth category error path are preserved. The changelog edit alters a past release note, but the linked issue requests that clarification.

Finishing Touches

Fix failing CI checks

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Linked repositories: This review skipped 6 repositories. Cross-repository analysis may be incomplete. Check linked repository access and settings.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: clerk/javascript
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: c7d761a
  • Layers: Repository YAML (base), Organization UI (inherited)
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: d2fe92f5-2ede-499c-bf7b-6902b2dce195
Commits

Reviewing files that changed from the base of the PR and between c7d761a and 300af84.

Files selected for processing: 4

  • .changeset/verify-token-oauth-jwt-error.md
  • packages/backend/CHANGELOG.md
  • packages/backend/src/tokens/__tests__/verify.test.ts
  • packages/backend/src/tokens/verify.ts
Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

This branch has not been deployed

No deployments
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.

@clerk/backend 3.28+: verifyToken rejects OAuth JWT access tokens with a misleading error

1 participant