Skip to content

Broker managed OAuth with Better Auth providers and token placeholders - #241

Merged
tnkuehne merged 1 commit into
feat/templates-without-auth-secretfrom
feat/managed-oauth-providers
Nov 20, 2026
Merged

tnkuehne merged 1 commit into
feat/templates-without-auth-secretfrom
feat/managed-oauth-providers

Conversation

@tnkuehne

@tnkuehne tnkuehne commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

What changes

Configuration. WIDEFLEET_OAUTH names operator clients instead of fixed profiles:

{
  "origin": "https://oauth.example.com",
  "clients": {
    "github": {
      "provider": "github",
      "clientId": "…",
      "clientSecret": "…",
      "scopes": ["read:user", "user:email", "repo"],
      "hosts": ["https://api.github.com"]
    },
    "google": {
      "provider": "google",
      "clientId": "…",
      "clientSecret": "…",
      "scopes": ["openid", "email", "profile", "https://www.googleapis.com/auth/gmail.readonly"],
      "hosts": ["https://gmail.googleapis.com"],
      "options": { "accessType": "offline", "prompt": "select_account consent" },
      "issuer": "https://accounts.google.com",
      "revocationUrl": "https://oauth2.googleapis.com/revoke"
    }
  }
}

provider is one of Better Auth's social providers; options are passed to it. Callback URLs stay /oauth/callback/<client>, so registrations keyed google, github and microsoft keep working. The earlier format no longer parses; hosted deployments fail before deploying until it is updated.

Broker (packages/app-runtime/src/oauth.ts):

  • The code exchange and refresh use @better-auth/core/social-providers, which handle each provider's protocol details. Their logger is disabled inside the broker, because provider error responses can contain credentials.
  • Apps request scopes. The broker refuses scopes outside the client's scopes, including provider defaults in the authorization URL, and refuses and revokes a token response that grants more.
  • The PKCE verifier travels sealed in the state ticket; the exchange compares the app's verifier with it. The ticket and refresh grants stay bound to app, organization, origin, caller and client.
  • Access tokens reach apps as wft1. placeholders bound to the app, the client and its hosts. The network gateway substitutes the real token in Authorization: Bearer only for those hosts and refuses the request otherwise.
  • revoke revokes a grant through the client's RFC 7009 revocationUrl; templates call it when a user disconnects.

Templates request their scopes from the managed client and revoke on disconnect.

Not included

  • The gateway does not remove substituted tokens from responses.
  • Token requests use Better Auth's fetch, which follows redirects from the providers' fixed token endpoints; the earlier broker refused them.

Tests

  • packages/app-runtime/src/oauth.test.ts: placeholders and their hosts, bound grants, PKCE, expiry, scope limits, revocation, invalid and earlier configuration, silent provider errors.
  • packages/app-runtime/src/template-oauth.test.ts: Gmail, GitHub and OneDrive through the broker, with template requests leaving through the runtime gateway.
  • apps/control-plane/tests/managed-oauth-runtime.test.ts: the GitHub template on the real loader; the provider receives real tokens while the app stores placeholders.
  • Cloudflare (248), dynamic runtime (23) and app services (42, workerd and celld) suites pass.

RetriggerView in GreptileConfidence Score: 5/5 Tier: apex

The PR appears safe to merge; no new blocking defect was found.

Summary

Moves managed OAuth to Better Auth providers and named operator clients.

  • Managed OAuth clients use operator settings and Better Auth providers.
  • Apps use access-token placeholders that the gateway opens for allowed hosts.
  • Disconnecting an account asks the broker to revoke its provider grant.

Diagram

sequenceDiagram
  participant App
  participant Broker
  participant Gateway
  participant Provider
  App->>Broker: Exchange code and sealed state
  Broker->>Provider: Exchange code with PKCE verifier
  Provider-->>Broker: Real tokens
  Broker-->>App: Access placeholder and sealed refresh grant
  App->>Gateway: Request with access placeholder
  Gateway->>Gateway: Check app, hosts, and network policy
  Gateway->>Provider: Request with real access token
  Provider-->>App: Response through gateway
Loading

Reviews (7) · Last reviewed commit: "Broker managed OAuth with Better Auth pr..." · Reviewed by Greptile

@tnkuehne
tnkuehne added this pull request to stack #239 November 20, 2026 11:44
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 20, 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 f46010b Nov 20 2026, 01:54 PM

Comment thread packages/app-runtime/src/oauth.ts Resolved
Comment thread packages/app-runtime/src/oauth.ts Resolved
Comment thread packages/app-runtime/src/oauth.test.ts Resolved
@tnkuehne
tnkuehne force-pushed the feat/managed-oauth-providers branch from 7f5b158 to 6fae162 Compare November 20, 2026 12:00
@tnkuehne
tnkuehne force-pushed the feat/managed-oauth-providers branch from 6fae162 to 8a183a9 Compare November 20, 2026 12:08
Comment thread packages/app-runtime/src/oauth.ts Resolved
Comment thread packages/app-runtime/src/oauth.ts Resolved
@tnkuehne
tnkuehne force-pushed the feat/managed-oauth-providers branch from 8a183a9 to a068a09 Compare November 20, 2026 12:17
@tnkuehne
tnkuehne force-pushed the feat/managed-oauth-providers branch from a068a09 to 3e4d287 Compare November 20, 2026 12:36
@tnkuehne
tnkuehne force-pushed the feat/managed-oauth-providers branch from 3e4d287 to d899c6b Compare November 20, 2026 12:56
Managed OAuth clients are configured per provider instead of fixed profiles.
The runtime uses Better Auth's provider modules for the code exchange and
refresh, checks requested and granted scopes against the operator's
configuration, and returns access tokens as placeholders that the network
gateway substitutes only for the client's hosts. Disconnecting revokes a grant
when the client declares an RFC 7009 endpoint.
@tnkuehne
tnkuehne force-pushed the feat/managed-oauth-providers branch from d899c6b to f46010b Compare November 20, 2026 13:53
@tnkuehne
tnkuehne merged commit 1b797d7 into main Nov 20, 2026
17 checks passed
@tnkuehne
tnkuehne deleted the feat/managed-oauth-providers branch November 20, 2026 14:43
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