Skip to content

Allow managed OAuth clients without scopes and with HTTP Basic revocation - #467

Merged
tnkuehne merged 4 commits into
mainfrom
managed-oauth-scopeless-basic-revocation
Nov 28, 2026
Merged

tnkuehne merged 4 commits into
mainfrom
managed-oauth-scopeless-basic-revocation

Conversation

@tnkuehne

@tnkuehne tnkuehne commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Change

Clients without scopes.

  • A registered client may list no scopes ("scopes": []), for services that decide a client's access in its registration, such as Notion, whose integration's capabilities and the pages a person selects decide access.
  • An authorization request without scopes is accepted only for such a client. For a client with a scope policy, it is rejected: without a scope parameter, a server may grant its own default scopes (RFC 6749 §3.3).
  • Client ID Metadata Document clients still need scopes; a public client without them could receive the server's defaults.

Revocation method.

  • revocationEndpointAuthMethod names how a registered client authenticates at its revocationUrl, with RFC 8414's method names: client_secret_post, the default, or client_secret_basic. It requires a revocationUrl. Metadata document clients have no secret and do not take it.
  • With client_secret_basic, the credentials go in HTTP Basic authentication, encoded as Better Auth encodes them for token requests, and the form carries only the token.
  • Notion's revocation endpoint answers invalid_client when the credentials are in the form and revokes with HTTP Basic (checked against Notion with a real OAuth integration).
  • Notion revokes an access token and the tokens issued before it; revoking the current access token also invalidates every refresh token of the grant. It answers a refresh token with 200 without revoking anything, so a Notion grant is revoked by its current access token (checked against Notion).

Notion refresh.

  • The Better Auth core patch refreshes Notion tokens with HTTP Basic client authentication. Better Auth's Notion provider authenticates code exchanges with HTTP Basic but sends the credentials in the form on refresh, which Notion answers with invalid_client (checked against Notion). The broker refreshes through that provider.

Tests

  • Broker tests for a client without scopes: authorization without a scope parameter, rejected requested scopes, and code exchange, refresh and revocation of the access token each authenticated with HTTP Basic and without credentials in the form, against a mock that rejects any other authentication.
  • Revocation without a method sends the credentials in the form.
  • Configuration: scopes required for metadata document clients, a revocation method only with a revocation URL and only for registered clients.
  • pnpm check, the broker tests and the managed OAuth tests of the templates.

…tion

Some services decide a client's access in its registration and take no
scopes, such as Notion. A managed client may now list no scopes, and an
authorization without scopes is accepted only for such a client, so a server
cannot grant its default scopes to a client with a scope policy.

`revocationAuthentication: "basic"` revokes grants with the client's
credentials in HTTP Basic authentication instead of the form, which Notion's
revocation endpoint requires. Without it, revocation keeps sending them in the
form.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
widefleet-docs 4623b5b Nov 28 2026, 05:27 PM

…TTP Basic

- `revocationEndpointAuthMethod` (`client_secret_post` or
  `client_secret_basic`) replaces `revocationAuthentication`. Only registered
  clients take it, and only with a revocation URL; public metadata document
  clients have no secret to authenticate with.
- Only registered clients may list no scopes. A metadata document client
  without scopes could receive the server's defaults.
- The Better Auth core patch refreshes Notion tokens with HTTP Basic client
  authentication, the only kind Notion's token endpoint accepts. Better Auth's
  Notion provider sends the credentials in the form on refresh.
- Tests check how each request authenticates: Notion's code exchange, refresh
  and revocation with HTTP Basic, and revocation with the credentials in the
  form by default.
Notion revokes an access token and the tokens issued before it, and answers a
refresh token without revoking anything (checked against Notion).
Each exchange and refresh in the test issues a new access token, and the
test revokes the one from the refresh, as the Notion template does. The
schema says what a client without scopes is granted.
@tnkuehne
tnkuehne merged commit 7a0b705 into main Nov 28, 2026
15 of 16 checks passed
@tnkuehne
tnkuehne deleted the managed-oauth-scopeless-basic-revocation branch November 28, 2026 17:33
tnkuehne added a commit that referenced this pull request Nov 28, 2026
## Change

**A Notion template.**
- 61 methods for Notion's API in version `2026-03-11`, generated from
Notion's published OpenAPI description
(`https://developers.notion.com/openapi.json`):
  - users, search, pages, page properties and page Markdown, async tasks
- blocks, databases, data sources, data source templates, views and view
queries
- comments, file uploads, custom emojis, AI meeting notes from
recordings
- Custom Agents, their sessions and events, Agent Skills plugins and
skills
- `streamSessionMessage` sends a session message with `Accept:
text/event-stream` and answers with the turn's events
(`session.snapshot`, `event.provisional`, `event.committed`,
`stream.timeout`, `stream.end`, `stream.error`), and replays a turn from
a committed event with `continue_from`.
- `getPageProperty` sends property IDs as Notion returned them,
URL-encoded.
- Every method takes an optional `notionBeta` for Notion's opt-in betas,
such as `status-group-filters-2026-10-06`.
- Not offered, because they do not work with the person's OAuth token:
  - the OAuth endpoints, which take the OAuth client's credentials
- deleting a Custom Agent, changing its credit limit, creating a
full-page meeting note and linking it to a calendar event, which take a
personal access token or a Notion Worker
  - Notion's Admin API, which takes an organization bot token
- `updateAgentStatus` offers the deprecated agent status endpoint, which
Notion still serves.
- Errors keep Notion's `code`, `message`, `request_id` and
`additional_data`. A write that was saved although its answer timed out
returns its `retry_guidance` and `committed_resource_id`.
- 429 and 529 return `rate_limited` with `Retry-After`. A connection
Notion blocked (`public_api_request_blocked`) returns Notion's error
instead.

**Connection.**
- Each person connects their own Notion account through Better Auth's
Notion provider and chooses the pages to share in Notion's page picker.
- An installation's managed `notion` client is used when present; it
needs #467, which this PR builds on. Otherwise the app asks for
`NOTION_CLIENT_ID` and `NOTION_CLIENT_SECRET` of the organization's own
OAuth integration.

**Generator.**
- A header the description requires with one allowed value, such as
`Notion-Version`, is sent on every request instead of being an input
(`fixedHeaders`). The generated types describe that version.
- A fixed header's value may come from a referenced schema.
- `encodedPathParameters` names path parameters the API hands out
URL-encoded; the runtime sends them as they are when they hold only
unreserved characters and percent escapes.
- A union lists no string values next to a named type of any string,
such as Notion's `IdRequest | "notion_ai"`.
- The shared `rest.ts` sends the fixed headers; the other REST templates
get the updated copy.

## Screenshots

The connection page. The favicon is Notion's own icon from notion.com.

| | Setup required | Not connected | Connected |
| --- | --- | --- | --- |
| 1280 px, light | <img
src="https://gist.githubusercontent.com/tnkuehne/bf81b61359b40ebba014f4afc27b9e20/raw/23f5391258f5facd642e016683944febd7721518/notion-setup-1280-light.png"
width="300"> | <img
src="https://gist.githubusercontent.com/tnkuehne/bf81b61359b40ebba014f4afc27b9e20/raw/23f5391258f5facd642e016683944febd7721518/notion-disconnected-1280-light.png"
width="300"> | <img
src="https://gist.githubusercontent.com/tnkuehne/bf81b61359b40ebba014f4afc27b9e20/raw/23f5391258f5facd642e016683944febd7721518/notion-connected-1280-light.png"
width="300"> |
| 1280 px, dark | <img
src="https://gist.githubusercontent.com/tnkuehne/bf81b61359b40ebba014f4afc27b9e20/raw/23f5391258f5facd642e016683944febd7721518/notion-setup-1280-dark.png"
width="300"> | <img
src="https://gist.githubusercontent.com/tnkuehne/bf81b61359b40ebba014f4afc27b9e20/raw/23f5391258f5facd642e016683944febd7721518/notion-disconnected-1280-dark.png"
width="300"> | <img
src="https://gist.githubusercontent.com/tnkuehne/bf81b61359b40ebba014f4afc27b9e20/raw/23f5391258f5facd642e016683944febd7721518/notion-connected-1280-dark.png"
width="300"> |
| 390 px, light | <img
src="https://gist.githubusercontent.com/tnkuehne/bf81b61359b40ebba014f4afc27b9e20/raw/23f5391258f5facd642e016683944febd7721518/notion-setup-390-light.png"
width="200"> | <img
src="https://gist.githubusercontent.com/tnkuehne/bf81b61359b40ebba014f4afc27b9e20/raw/23f5391258f5facd642e016683944febd7721518/notion-disconnected-390-light.png"
width="200"> | <img
src="https://gist.githubusercontent.com/tnkuehne/bf81b61359b40ebba014f4afc27b9e20/raw/23f5391258f5facd642e016683944febd7721518/notion-connected-390-light.png"
width="200"> |
| 390 px, dark | <img
src="https://gist.githubusercontent.com/tnkuehne/bf81b61359b40ebba014f4afc27b9e20/raw/23f5391258f5facd642e016683944febd7721518/notion-setup-390-dark.png"
width="200"> | <img
src="https://gist.githubusercontent.com/tnkuehne/bf81b61359b40ebba014f4afc27b9e20/raw/23f5391258f5facd642e016683944febd7721518/notion-disconnected-390-dark.png"
width="200"> | <img
src="https://gist.githubusercontent.com/tnkuehne/bf81b61359b40ebba014f4afc27b9e20/raw/23f5391258f5facd642e016683944febd7721518/notion-connected-390-dark.png"
width="200"> |

Not shown: the connection error alert.

## Tests

- Template tests: streamed session turns, encoded property IDs,
connection, Notion-Version and Notion-Beta headers, cursor pages, user
and issuer isolation, approvals, multipart uploads with binary bytes,
reconnecting the same Notion user, Notion's errors, rate limits,
overload and saved-but-timed-out writes.
- Managed OAuth tests for the Notion client: authorization, exchange,
refresh and revocation with HTTP Basic client authentication.
- Generator tests for fixed headers, referenced header schemas, encoded
path parameters and unions with named string types.
- `pnpm check`, all template tests, the generator tests and the app
runtime's OAuth tests.
- Regenerating from the downloaded description reproduces the committed
files.

**Live against Notion** (an OAuth integration in a workspace on the free
plan):
- Connecting through OAuth with the organization's own client.
- Users, search, pages, page properties, page Markdown and async tasks,
blocks, databases, data sources, views and view queries, comments,
single-part file uploads, custom emojis, Agent Skills plugin listing and
download. Test data with non-ASCII text and a PNG with binary bytes,
which downloaded identically.
- `getPageProperty` with property IDs as Notion returned them,
URL-encoded (`%5BT%40s`, `%3BaJY`, `%5CCab` and others), for every
property type of a test database, with non-ASCII names and values.
Notion also accepts the IDs encoded a second time; the template sends
them as Notion's reference and SDK do.
- Refresh and revocation with HTTP Basic, and their rejection with
credentials in the form. Notion revokes an access token and the tokens
issued before it, and answers a refresh token without revoking anything,
so disconnecting revokes the current access token; afterwards every
access and refresh token of the grant is rejected. A revoked token
returns `reconnect_required`.

**Not run live**, because the test workspace does not offer them:
- Custom Agents and sessions: the test integration had no agent
capabilities (403).
- `uploadSkill`: the workspace's only skill is in use.
- Multi-part uploads (`completeFileUpload`) and `createMeetingNote`: not
available on the free plan.
- The managed client, which the hosted installation configures after
this is released.
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.

1 participant