@arcblock/did-connect-service 4.1.14 → 4.1.16

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.
Files changed (33) hide show
  1. package/dist/blocklet-service-rpc.d.ts.map +1 -1
  2. package/dist/blocklet-service-rpc.js +4 -3
  3. package/dist/blocklet-service-rpc.js.map +1 -1
  4. package/dist/handlers/access-key-connect-handler.d.ts.map +1 -1
  5. package/dist/handlers/access-key-connect-handler.js +15 -0
  6. package/dist/handlers/access-key-connect-handler.js.map +1 -1
  7. package/dist/handlers/access-key-handler.d.ts +1 -1
  8. package/dist/handlers/access-key-handler.d.ts.map +1 -1
  9. package/dist/handlers/access-key-handler.js +5 -1
  10. package/dist/handlers/access-key-handler.js.map +1 -1
  11. package/dist/handlers/auth-handler.d.ts.map +1 -1
  12. package/dist/handlers/auth-handler.js +23 -1
  13. package/dist/handlers/auth-handler.js.map +1 -1
  14. package/dist/handlers/oauth-as-handler.d.ts +108 -0
  15. package/dist/handlers/oauth-as-handler.d.ts.map +1 -0
  16. package/dist/handlers/oauth-as-handler.js +756 -0
  17. package/dist/handlers/oauth-as-handler.js.map +1 -0
  18. package/dist/handlers/passkey-handler.d.ts.map +1 -1
  19. package/dist/handlers/passkey-handler.js +5 -4
  20. package/dist/handlers/passkey-handler.js.map +1 -1
  21. package/dist/index.d.ts +2 -0
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +1 -0
  24. package/dist/index.js.map +1 -1
  25. package/dist/pages/gen-access-key-page.d.ts.map +1 -1
  26. package/dist/pages/gen-access-key-page.js +16 -0
  27. package/dist/pages/gen-access-key-page.js.map +1 -1
  28. package/dist/store/d1-store.d.ts +25 -0
  29. package/dist/store/d1-store.d.ts.map +1 -1
  30. package/dist/store/d1-store.js +67 -0
  31. package/dist/store/d1-store.js.map +1 -1
  32. package/migrations/0012_oauth_clients.sql +22 -0
  33. package/package.json +3 -3
@@ -0,0 +1,108 @@
1
+ /**
2
+ * OAuthAsHandler — RFC 8414 Authorization Server metadata + RFC 8628
3
+ * device authorization grant + RFC 6749 authorization_code (PKCE S256).
4
+ *
5
+ * This is the MCP resource-server AS surface (arc#3788 / epic #3783 / arc#3868).
6
+ * It does NOT reuse OAuthHandler (Google/GitHub IdP login).
7
+ *
8
+ * Mapping to existing access-key device flow:
9
+ * POST device_authorization → createAccessKeySession ({id, challenge})
10
+ * verification_uri → /.well-known/service/gen-access-key
11
+ * verification_uri_complete → gen-access-key?__token__=<device_code>
12
+ * user authorizes → existing POST .../access-key/authorize
13
+ * POST token (device_code) → decrypt session secret → access_token
14
+ *
15
+ * Authorization code + PKCE (arc#3868):
16
+ * GET /oauth/authorize → login (query preserved) or confirm page
17
+ * POST /oauth/authorize → 302 redirect_uri?code&state (fresh code, no mint)
18
+ * PKCE + bound userDid/instanceDid live in session.source as `oauth-code:{json}`
19
+ * challenge column stays the AES wrap key for the approved-user payload
20
+ * POST token (authorization_code) → mint instance-bound access key
21
+ * redirect_uri is re-checked as RFC 8252 loopback on GET, POST, and token
22
+ *
23
+ * Tokens are instance-bound access keys (same store / resolveAccessKeyCaller).
24
+ *
25
+ * Routes:
26
+ * GET /.well-known/oauth-authorization-server
27
+ * GET /.well-known/service/oauth/authorize
28
+ * POST /.well-known/service/oauth/authorize
29
+ * POST /.well-known/service/oauth/register
30
+ * POST /.well-known/service/oauth/device_authorization
31
+ * POST /.well-known/service/oauth/token
32
+ *
33
+ * DCR (arc#3869): code grant resolves client_id via resolveOAuthClient
34
+ * (cs_oauth_clients ∪ pre-registered; CIMD stub only). Device grant stays
35
+ * loose — unregistered client_id still works. client_id grants no permissions.
36
+ */
37
+ import { type Logger } from "../logger.js";
38
+ import type { D1Store, StoredOAuthClient } from "../store/d1-store.js";
39
+ import type { AccessKeyHandler } from "./access-key-handler.js";
40
+ import type { Auth } from "./passkey-handler.js";
41
+ /** Unverified estimate: DCR records expire after 7 days. */
42
+ export declare const OAUTH_DCR_TTL_SECONDS: number;
43
+ /** Unverified estimate: DCR registrations per IP per window. */
44
+ export declare const OAUTH_DCR_RATE_LIMIT = 20;
45
+ export declare const OAUTH_DCR_RATE_WINDOW_MS: number;
46
+ export interface OAuthAsHandlerOptions {
47
+ store: D1Store;
48
+ /** Structured logger (defaults to consoleLogger). */
49
+ logger?: Logger;
50
+ /** Session verifier — required for /oauth/authorize. */
51
+ auth?: Auth;
52
+ /** Mints the instance-bound access key at the token endpoint. */
53
+ accessKeyHandler?: AccessKeyHandler;
54
+ /** Override DCR per-IP rate limit (tests). Default {@link OAUTH_DCR_RATE_LIMIT}. */
55
+ dcrRateLimit?: number;
56
+ }
57
+ export type OAuthClientRecord = StoredOAuthClient;
58
+ export declare class OAuthAsHandler {
59
+ private store;
60
+ private logger;
61
+ private auth?;
62
+ private accessKeyHandler?;
63
+ private dcrRateLimit;
64
+ constructor(options: OAuthAsHandlerOptions);
65
+ fetch(request: Request, instanceDid?: string): Promise<Response | null>;
66
+ /** GET /.well-known/oauth-authorization-server — RFC 8414 */
67
+ private metadata;
68
+ /**
69
+ * POST /.well-known/service/oauth/register — RFC 7591
70
+ * Public client (token_endpoint_auth_method=none). Echoes the full schema;
71
+ * a `{client_id}`-only body is a hard fail for Claude Code.
72
+ */
73
+ private register;
74
+ /**
75
+ * GET /.well-known/service/oauth/authorize — RFC 6749 §4.1.1
76
+ * Unauthenticated → existing login (query preserved via return_to).
77
+ * Authenticated → pending oauth-code session + confirm UI.
78
+ */
79
+ private authorizeGet;
80
+ /**
81
+ * POST /.well-known/service/oauth/authorize
82
+ * User confirmation. Does not mint — token endpoint mints.
83
+ * Success: 302 redirect_uri?code&state
84
+ */
85
+ private authorizePost;
86
+ /**
87
+ * POST /.well-known/service/oauth/device_authorization — RFC 8628 §3.1
88
+ * Creates an access-key session; device_code = session id.
89
+ */
90
+ private deviceAuthorization;
91
+ /**
92
+ * POST /.well-known/service/oauth/token — RFC 8628 §3.4 / RFC 6749 §4.1.3
93
+ * Device: decrypt session secret. Code: mint a new instance-bound access key.
94
+ */
95
+ private token;
96
+ /**
97
+ * grant_type=authorization_code — PKCE S256, one-time code, mint at token.
98
+ */
99
+ private authorizationCodeToken;
100
+ }
101
+ /**
102
+ * DCR table ∪ pre-registered. Expired DCR rows are treated as unknown.
103
+ * Device grant must NOT call this (unregistered client_id stays valid).
104
+ */
105
+ export declare function resolveOAuthClient(store: D1Store, clientId: string): Promise<OAuthClientRecord | null>;
106
+ /** CIMD (Client ID Metadata Document) — stub only this wave. */
107
+ export declare function resolveCimdClient(_clientId: string): Promise<OAuthClientRecord | null>;
108
+ //# sourceMappingURL=oauth-as-handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth-as-handler.d.ts","sourceRoot":"","sources":["../../src/handlers/oauth-as-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAGH,OAAO,EAAiB,KAAK,MAAM,EAAE,MAAM,cAAc,CAAC;AAE1D,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEvE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAQjD,4DAA4D;AAC5D,eAAO,MAAM,qBAAqB,QAAmB,CAAC;AACtD,gEAAgE;AAChE,eAAO,MAAM,oBAAoB,KAAK,CAAC;AACvC,eAAO,MAAM,wBAAwB,QAAiB,CAAC;AAmBvD,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,OAAO,CAAC;IACf,qDAAqD;IACrD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,wDAAwD;IACxD,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,iEAAiE;IACjE,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC,oFAAoF;IACpF,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,MAAM,iBAAiB,GAA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