Skip to content

feat(auth0-express-api): add support for on-behalf-of token exchange - #40

Merged
nandan-bhat merged 4 commits into
mainfrom
feat/sdk-8431-api-as-client-obo
Aug 20, 2026
Merged

nandan-bhat merged 4 commits into
mainfrom
feat/sdk-8431-api-as-client-obo

Conversation

@nandan-bhat

@nandan-bhat nandan-bhat commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

What changed

chore: bump auth0-api-js and re-export its public API

@auth0/auth0-api-js goes from ^1.4.0 to ^1.6.1, since OBOTE (On-behalf-Of Token Exchange) landed in 1.6.0. Re-exports only what this package's surface already exposes: the actor claim helpers, the errors it can throw, the OBO types, and ApiClient as a type only, so createAuth0Api() stays the only way to build a client.

feat: on-behalf-of token exchange

  • requiresAuth() now sets req.auth0.token alongside req.auth0.user, so a token on the request is always one this API has verified. It is non-enumerable, so JSON.stringify, spreads and console.log leave it out.
  • The exchange is api-js, not a wrapper. Call req.auth0.client.getTokenOnBehalfOf(token, { audience, scope }) and pass the subject token yourself.
  • On a protected route that token is req.auth0.token. Anywhere else it can be a token your API holds for elsewhere, such as one stored for a background job.
  • Needs clientId plus either clientSecret or clientAssertionSigningKey.
  • EXAMPLES.md gains an API as a client section, which is where token verification and token exchange get separated. It covers the tenant prerequisites, the two errors, and why a subject token must never come from the request.

Usage Example

import { requiresAuth } from '@auth0/auth0-express-api';

app.get('/orders', requiresAuth(), async (req, res) => {
  const { accessToken } = await req.auth0.client.getTokenOnBehalfOf(req.auth0.token!, {
    audience: 'https://orders.example.com',
    scope: 'read:orders',
  });

  const orders = await fetch('https://orders.example.com/orders', {
    headers: { authorization: `Bearer ${accessToken}` },
  });

  res.json(await orders.json());
});

Testing

  • All tests pass across 8 files, including the exchange end to end through msw, a missing subject token, missing
    credentials and a tenant rejection
  • npm run build and npm run lint are clean

@nandan-bhat nandan-bhat changed the title Feat/sdk 8431 api as client obo feat(auth0-express-api):add support for on-behalf-of token exchange Aug 15, 2026
@nandan-bhat
nandan-bhat force-pushed the feat/sdk-8431-api-as-client-obo branch 2 times, most recently from 34daf6e to 033b19f Compare August 19, 2026 23:21
@nandan-bhat
nandan-bhat force-pushed the feat/sdk-8431-api-as-client-obo branch from 033b19f to a4711ed Compare August 19, 2026 23:47
Comment thread packages/auth0-express-api/src/types/express.ts
Comment thread packages/auth0-express-api/EXAMPLES.md Outdated
Comment thread packages/auth0-express-api/EXAMPLES.md
Comment thread packages/auth0-express-api/EXAMPLES.md Outdated
Comment thread packages/auth0-express-api/EXAMPLES.md Outdated
Comment thread examples/example-express-api/src/index.ts
Comment thread packages/auth0-express-api/src/index.ts Outdated
Comment thread packages/auth0-express-api/src/exports.spec.ts Outdated
Comment thread packages/auth0-express-api/src/index.spec.ts Outdated
Comment thread packages/auth0-express-api/src/middleware/require-auth.ts Outdated
Piyush-85

This comment was marked as off-topic.

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

Comment thread packages/auth0-express-api/src/index.ts Outdated
Comment thread packages/auth0-express-api/src/types/express.ts
Comment thread examples/example-express-api/src/index.ts
Comment thread examples/example-express-api/README.md Outdated

@kishore7snehil kishore7snehil 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!

@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

@nandan-bhat
nandan-bhat merged commit a72d569 into main Aug 20, 2026
7 checks passed
@nandan-bhat nandan-bhat changed the title feat(auth0-express-api):add support for on-behalf-of token exchange feat(auth0-express-api): add support for on-behalf-of token exchange Aug 20, 2026
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