Skip to content

feat(backend): expose orgId and grantedOrgs on verified OAuth access tokens - #11015

Open
Zertsov wants to merge 1 commit into
mainfrom
voz/backend-oauth-token-org-claims
Open

Zertsov wants to merge 1 commit into
mainfrom
voz/backend-oauth-token-org-claims

Conversation

@Zertsov

@Zertsov Zertsov commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Description

Verified OAuth access tokens now expose the organizations of the grant.

A Clerk OAuth access token can carry org_id, the default organization of the grant, and granted_orgs, the organizations the user granted when one consent covers two or more. @clerk/backend verified these tokens but dropped both values, so a server had to decode the token by hand to read them.

  • IdPOAuthAccessToken gains orgId and grantedOrgs ({ id, name }[]), read from the JWT payload and from the Backend API verify response for opaque tokens. Both are undefined when the token has none.
  • The oauth_token auth object gains orgId and grantedOrgs. Both are null when the token has none, and null on the unauthenticated object.
  • A claim with an unexpected shape is ignored and never fails verification. granted_orgs is all or nothing: one malformed entry drops the whole list, so a partial list is never exposed. Extra keys in an entry are dropped.
  • For opaque tokens the values come from the Backend API verify response, so they stay empty until that response includes them.
const { isAuthenticated, userId, orgId, grantedOrgs } = await auth({ acceptsToken: 'oauth_token' });

grantedOrgs records what the user chose at consent time. It carries no role, so a server that authorizes by organization still checks the user's current membership.

To test: pnpm test in packages/backend. The new cases are in src/tokens/__tests__/verify.test.ts ("OAuth token organization claims", for opaque and JWT tokens) and src/tokens/__tests__/authObjects.test.ts.

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:

…tokens

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
clerk-js-sandbox Ready Ready Preview Nov 25, 2026 8:54pm UTC
mosaic-docs Ready Ready Preview Nov 25, 2026 8:54pm UTC
swingset Ready Ready Preview Nov 25, 2026 8:54pm UTC

Request Review

@Zertsov
Zertsov requested a review from brkalow November 25, 2026 20:52
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T20:53:49.884629Z db4c1a9 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@changeset-bot

changeset-bot Bot commented Nov 25, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: db4c1a9

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 Minor
@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

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: db4c1a92ee

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +74 to +76
/** The default organization of the grant. */
readonly orgId?: string,
/** The organizations the user granted in one consent, default first. Present only when two or more were granted. */

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Remove the newly added code comments

The new JSDoc comments for orgId and grantedOrgs violate the root AGENTS.md rule, which states “do not write any code comments” unless specifically requested by the user. These additions do not correct existing comments made inaccurate by changed behavior. Remove both new comments to comply with the repository's explicit convention.

AGENTS.md reference: AGENTS.md:L9-L9

Useful? React with 👍 / 👎.

@blacksmith-sh

blacksmith-sh Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Matches JWT OAuth token exposes orgId and grantedOrgs

Head returns orgId org_default and both granted orgs on the token and on toAuth(); base verifies the same token but exposes neither.

Merge-base

JWT org claims

This PR db4c1a92

JWT org claims

Also checked · 2 match

Matches Opaque OAuth token reads org claims from verify response
Matches Malformed or absent org claims are ignored

Proof on db4c1a92 · mocked: Backend API (loopback HTTP fixture answers POST /oauth_applications/access_tokens/verify with...) · Did Proof get it right? Yes · No

View full Proof report · React 👎 or comment @codesmith dismiss this proof to dismiss

@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

OAuth access-token data now includes optional orgId and grantedOrgs values parsed from org_id and granted_orgs claims. Parsing validates claim values and omits invalid or empty values. Authenticated OAuth machine objects expose the verified values, using null when absent. Unauthenticated OAuth machine objects set both values to null. Tests cover valid, absent, and malformed claims.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: wyattjoh, thiskevinwang

Merge Risk: Minimal · up to db4c1

This adds optional organization claims to verified OAuth access tokens and exposes them on OAuth auth objects, with null when absent. Malformed claims are ignored rather than failing verification. No concrete merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: OAuth access token verification now exposes orgId and grantedOrgs in @clerk/backend. The raw summary confirms IdPOAuthAccessToken, the oauth_token auth object, and the…
Description check Passed The description states that verified OAuth access tokens now expose org_id and granted_orgs as orgId and grantedOrgs. It lists the IdPOAuthAccessToken and oauth_token auth object changes, malformed-cl…
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.
Full details: Title check

Explanation

The title names the main change: OAuth access token verification now exposes orgId and grantedOrgs in @clerk/backend. The raw summary confirms IdPOAuthAccessToken, the oauth_token auth object, and the JSON types all carry these fields, so the title matches the changeset.

Full details: Description check

Explanation

The description states that verified OAuth access tokens now expose org_id and granted_orgs as orgId and grantedOrgs. It lists the IdPOAuthAccessToken and oauth_token auth object changes, malformed-claim handling, opaque-token behavior, and the test locations. These match the changeset files.

  • 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: 5e77db0
  • Layers: Repository YAML (base), Organization UI (inherited)
  • Review profile: ASSERTIVE
  • Plan: Team
  • Run ID: 18982eb3-4028-4d16-bde2-f0d694bd4b6e
Commits

Reviewing files that changed from the base of the PR and between 5e77db0 and db4c1a9.

Files selected for processing: 6

  • .changeset/backend-oauth-token-org-claims.md
  • packages/backend/src/api/resources/IdPOAuthAccessToken.ts
  • packages/backend/src/api/resources/JSON.ts
  • packages/backend/src/tokens/__tests__/authObjects.test.ts
  • packages/backend/src/tokens/__tests__/verify.test.ts
  • packages/backend/src/tokens/authObjects.ts
Linked repositories identified

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

Included review availability: This review used your included allowance. 3 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 10 reviews per hour.

@pkg-pr-new

pkg-pr-new Bot commented Nov 25, 2026

Copy link
Copy Markdown

Open in StackBlitz

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@11015

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@11015

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@11015

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@11015

@clerk/electron

npm i https://pkg.pr.new/@clerk/electron@11015

@clerk/electron-passkeys

npm i https://pkg.pr.new/@clerk/electron-passkeys@11015

@clerk/eslint-plugin

npm i https://pkg.pr.new/@clerk/eslint-plugin@11015

@clerk/expo

npm i https://pkg.pr.new/@clerk/expo@11015

@clerk/expo-biometrics

npm i https://pkg.pr.new/@clerk/expo-biometrics@11015

@clerk/expo-google-signin

npm i https://pkg.pr.new/@clerk/expo-google-signin@11015

@clerk/expo-native-components

npm i https://pkg.pr.new/@clerk/expo-native-components@11015

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@11015

@clerk/express

npm i https://pkg.pr.new/@clerk/express@11015

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@11015

@clerk/hono

npm i https://pkg.pr.new/@clerk/hono@11015

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@11015

@clerk/mosaic

npm i https://pkg.pr.new/@clerk/mosaic@11015

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@11015

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@11015

@clerk/react

npm i https://pkg.pr.new/@clerk/react@11015

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@11015

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@11015

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@11015

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@11015

@clerk/ui

npm i https://pkg.pr.new/@clerk/ui@11015

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@11015

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@11015

commit: db4c1a9

@github-actions

Copy link
Copy Markdown
Contributor

API Changes Report

Generated by Break Check on 2026-11-25T21:00:03.327Z

Summary

Metric Count
Packages analyzed 20
Packages with changes 0
🔴 Breaking changes 0
🟡 Non-breaking changes 0
🟢 Additions 0

No API Changes Detected

All packages have stable APIs with no detected changes.


Report generated by Break Check

Last ran on db4c1a9.

This branch was successfully deployed

2 active deployments
Preview – swingset — db4c1a92 Deployed Nov 25, 2026 by vercel[bot]
Preview – clerk-js-sandbox — db4c1a92 Deployed Nov 25, 2026 by vercel[bot]
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