@cloudflare/workers-oauth-provider 0.10.4 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +144 -50
- package/dist/oauth-provider.d.ts +334 -89
- package/dist/oauth-provider.js +1393 -309
- package/docs/advanced-configuration.md +370 -0
- package/docs/migration-1.0.md +97 -0
- package/docs/resource-servers.md +153 -0
- package/package.json +4 -2
- package/skills/migrate-to-1.0/SKILL.md +35 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: workers-oauth-provider-migrate-1.0
|
|
3
|
+
description: Migrate a Cloudflare Worker from @cloudflare/workers-oauth-provider 0.x to 1.0. Use when upgrading that dependency, when OAuthProvider construction throws about resourceMetadata.resource or resourceMatchOriginOnly, or when asked to adopt the 1.0 role-based API (OAuthAuthorizationServer / OAuthResourceServer).
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Migrate @cloudflare/workers-oauth-provider 0.x → 1.0
|
|
7
|
+
|
|
8
|
+
The single source of truth for every change is the migration guide shipped with the package:
|
|
9
|
+
`node_modules/@cloudflare/workers-oauth-provider/docs/migration-1.0.md`
|
|
10
|
+
(also at https://github.com/cloudflare/workers-oauth-provider/blob/main/docs/migration-1.0.md).
|
|
11
|
+
Read it fully before editing. This skill is the procedure around it; do not work from memory of 0.x or from this file alone.
|
|
12
|
+
|
|
13
|
+
## Procedure
|
|
14
|
+
|
|
15
|
+
1. **Detect the shape.** Find `new OAuthProvider(` and read its options. The common shape is one Worker acting as authorization server and resource server; that shape stays on `OAuthProvider` in 1.0. Do not introduce `OAuthAuthorizationServer`/`OAuthResourceServer` unless the user asks for a multi-Worker or multi-resource topology.
|
|
16
|
+
2. **Choose the canonical resource — ask the user.** `resourceMetadata: { resource }` is required in 1.0. The value is the URL MCP clients connect to (often an existing `apiRoute` on the Worker's public origin, e.g. `https://mcp.example.com/mcp`). Infer a candidate from `wrangler.jsonc` routes/custom domains plus `apiRoute`, present it, and get confirmation — it becomes the token audience, so it must be right.
|
|
17
|
+
3. **Apply the guide's changes** that match the code: add `resourceMetadata.resource`; delete `resourceMatchOriginOnly`; make `resolveExternalToken` return the canonical `audience`; single-string `resource`/`aud` types; check `apiRoute`s are the resource path or descendants.
|
|
18
|
+
4. **Bump the dependency** to `^1.0.0` and install.
|
|
19
|
+
5. **Verify** (below), then walk the user through the guide's "Existing stored data" section so they know what their live clients will experience (nothing, in the common case).
|
|
20
|
+
|
|
21
|
+
## Stop and ask the user
|
|
22
|
+
|
|
23
|
+
- The canonical `resource` value (step 2). Never guess silently.
|
|
24
|
+
- On a multi-resource `OAuthAuthorizationServer`: which resource is `legacyGrantResource` (the migration destination for pre-1.0 grants). Omitting it makes old grants reauthorize.
|
|
25
|
+
- Any DCR client base registered with narrow `grant_types`: 1.0 enforces them; confirm the registered types cover what clients actually send before deploying.
|
|
26
|
+
- Adopting new 1.0 surface (role classes, `ctx.auth`, `insufficientScope`, `onError.internal`) is optional — offer, don't do unasked.
|
|
27
|
+
|
|
28
|
+
## Verify
|
|
29
|
+
|
|
30
|
+
1. `tsc`/typecheck and the project's tests pass.
|
|
31
|
+
2. `wrangler dev`, then:
|
|
32
|
+
- `curl -i http://localhost:8787<api route>` → 401 whose `WWW-Authenticate` names `resource_metadata="…/.well-known/oauth-protected-resource<resource path>"`. This works locally whatever the configured resource's origin.
|
|
33
|
+
- The metadata document itself is origin-strict (RFC 9728 §3): its well-known URL is `<resource origin>/.well-known/oauth-protected-resource<resource path>`. When the dev config's resource is on the loopback origin (e.g. `http://localhost:8787/mcp`), `curl http://localhost:8787/.well-known/oauth-protected-resource/mcp` → 200 with the exact `resource`. A production resource origin serves its document only there — after deploy: `curl https://<host>/.well-known/oauth-protected-resource<resource path>`.
|
|
34
|
+
- Construction errors surface on the first request and name the violated rule; fix per the guide.
|
|
35
|
+
3. If the deployment has live users, re-read "Existing stored data — nothing to do" in the guide and confirm no step you took contradicts it (no KV edits, no `legacyGrantResource` changes after rollout).
|