@atproto/oauth-client 0.0.0-spaces-alpha-20260818021221

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 (112) hide show
  1. package/CHANGELOG.md +810 -0
  2. package/LICENSE.txt +7 -0
  3. package/README.md +387 -0
  4. package/dist/constants.d.ts +5 -0
  5. package/dist/constants.d.ts.map +1 -0
  6. package/dist/constants.js +5 -0
  7. package/dist/constants.js.map +1 -0
  8. package/dist/errors/auth-method-unsatisfiable-error.d.ts +3 -0
  9. package/dist/errors/auth-method-unsatisfiable-error.d.ts.map +1 -0
  10. package/dist/errors/auth-method-unsatisfiable-error.js +3 -0
  11. package/dist/errors/auth-method-unsatisfiable-error.js.map +1 -0
  12. package/dist/errors/token-invalid-error.d.ts +7 -0
  13. package/dist/errors/token-invalid-error.d.ts.map +1 -0
  14. package/dist/errors/token-invalid-error.js +7 -0
  15. package/dist/errors/token-invalid-error.js.map +1 -0
  16. package/dist/errors/token-refresh-error.d.ts +7 -0
  17. package/dist/errors/token-refresh-error.d.ts.map +1 -0
  18. package/dist/errors/token-refresh-error.js +7 -0
  19. package/dist/errors/token-refresh-error.js.map +1 -0
  20. package/dist/errors/token-revoked-error.d.ts +7 -0
  21. package/dist/errors/token-revoked-error.d.ts.map +1 -0
  22. package/dist/errors/token-revoked-error.js +7 -0
  23. package/dist/errors/token-revoked-error.js.map +1 -0
  24. package/dist/fetch-dpop.d.ts +20 -0
  25. package/dist/fetch-dpop.d.ts.map +1 -0
  26. package/dist/fetch-dpop.js +176 -0
  27. package/dist/fetch-dpop.js.map +1 -0
  28. package/dist/identity-resolver.d.ts +2 -0
  29. package/dist/identity-resolver.d.ts.map +1 -0
  30. package/dist/identity-resolver.js +21 -0
  31. package/dist/identity-resolver.js.map +1 -0
  32. package/dist/index.d.ts +25 -0
  33. package/dist/index.d.ts.map +1 -0
  34. package/dist/index.js +25 -0
  35. package/dist/index.js.map +1 -0
  36. package/dist/lock.d.ts +3 -0
  37. package/dist/lock.d.ts.map +1 -0
  38. package/dist/lock.js +29 -0
  39. package/dist/lock.js.map +1 -0
  40. package/dist/oauth-authorization-server-metadata-resolver.d.ts +25 -0
  41. package/dist/oauth-authorization-server-metadata-resolver.d.ts.map +1 -0
  42. package/dist/oauth-authorization-server-metadata-resolver.js +54 -0
  43. package/dist/oauth-authorization-server-metadata-resolver.js.map +1 -0
  44. package/dist/oauth-callback-error.d.ts +7 -0
  45. package/dist/oauth-callback-error.d.ts.map +1 -0
  46. package/dist/oauth-callback-error.js +14 -0
  47. package/dist/oauth-callback-error.js.map +1 -0
  48. package/dist/oauth-client-auth.d.ts +23 -0
  49. package/dist/oauth-client-auth.d.ts.map +1 -0
  50. package/dist/oauth-client-auth.js +126 -0
  51. package/dist/oauth-client-auth.js.map +1 -0
  52. package/dist/oauth-client.d.ts +338 -0
  53. package/dist/oauth-client.d.ts.map +1 -0
  54. package/dist/oauth-client.js +274 -0
  55. package/dist/oauth-client.js.map +1 -0
  56. package/dist/oauth-protected-resource-metadata-resolver.d.ts +25 -0
  57. package/dist/oauth-protected-resource-metadata-resolver.d.ts.map +1 -0
  58. package/dist/oauth-protected-resource-metadata-resolver.js +54 -0
  59. package/dist/oauth-protected-resource-metadata-resolver.js.map +1 -0
  60. package/dist/oauth-resolver-error.d.ts +7 -0
  61. package/dist/oauth-resolver-error.d.ts.map +1 -0
  62. package/dist/oauth-resolver-error.js +19 -0
  63. package/dist/oauth-resolver-error.js.map +1 -0
  64. package/dist/oauth-resolver.d.ts +73 -0
  65. package/dist/oauth-resolver.d.ts.map +1 -0
  66. package/dist/oauth-resolver.js +99 -0
  67. package/dist/oauth-resolver.js.map +1 -0
  68. package/dist/oauth-response-error.d.ts +11 -0
  69. package/dist/oauth-response-error.d.ts.map +1 -0
  70. package/dist/oauth-response-error.js +22 -0
  71. package/dist/oauth-response-error.js.map +1 -0
  72. package/dist/oauth-server-agent.d.ts +55 -0
  73. package/dist/oauth-server-agent.d.ts.map +1 -0
  74. package/dist/oauth-server-agent.js +189 -0
  75. package/dist/oauth-server-agent.js.map +1 -0
  76. package/dist/oauth-server-factory.d.ts +33 -0
  77. package/dist/oauth-server-factory.d.ts.map +1 -0
  78. package/dist/oauth-server-factory.js +31 -0
  79. package/dist/oauth-server-factory.js.map +1 -0
  80. package/dist/oauth-session.d.ts +34 -0
  81. package/dist/oauth-session.d.ts.map +1 -0
  82. package/dist/oauth-session.js +120 -0
  83. package/dist/oauth-session.js.map +1 -0
  84. package/dist/runtime-implementation.d.ts +17 -0
  85. package/dist/runtime-implementation.d.ts.map +1 -0
  86. package/dist/runtime-implementation.js +2 -0
  87. package/dist/runtime-implementation.js.map +1 -0
  88. package/dist/runtime.d.ts +26 -0
  89. package/dist/runtime.d.ts.map +1 -0
  90. package/dist/runtime.js +100 -0
  91. package/dist/runtime.js.map +1 -0
  92. package/dist/session-getter.d.ts +44 -0
  93. package/dist/session-getter.d.ts.map +1 -0
  94. package/dist/session-getter.js +265 -0
  95. package/dist/session-getter.js.map +1 -0
  96. package/dist/state-store.d.ts +23 -0
  97. package/dist/state-store.d.ts.map +1 -0
  98. package/dist/state-store.js +2 -0
  99. package/dist/state-store.js.map +1 -0
  100. package/dist/types.d.ts +430 -0
  101. package/dist/types.d.ts.map +1 -0
  102. package/dist/types.js +9 -0
  103. package/dist/types.js.map +1 -0
  104. package/dist/util.d.ts +20 -0
  105. package/dist/util.d.ts.map +1 -0
  106. package/dist/util.js +68 -0
  107. package/dist/util.js.map +1 -0
  108. package/dist/validate-client-metadata.d.ts +5 -0
  109. package/dist/validate-client-metadata.d.ts.map +1 -0
  110. package/dist/validate-client-metadata.js +76 -0
  111. package/dist/validate-client-metadata.js.map +1 -0
  112. package/package.json +55 -0
@@ -0,0 +1,176 @@
1
+ import { base64url } from 'multiformats/bases/base64';
2
+ import { cancelBody, peekJson, } from '@atproto-labs/fetch';
3
+ // "undefined" in non https environments or environments without crypto
4
+ const subtle = globalThis.crypto?.subtle;
5
+ const ReadableStream = globalThis.ReadableStream;
6
+ export function dpopFetchWrapper({ key,
7
+ // @TODO we should provide a default based on specs
8
+ supportedAlgs, nonces, sha256 = typeof subtle !== 'undefined' ? subtleSha256 : undefined, isAuthServer, fetch = globalThis.fetch, }) {
9
+ if (!sha256) {
10
+ throw new TypeError(`crypto.subtle is not available in this environment. Please provide a sha256 function.`);
11
+ }
12
+ // Throws if negotiation fails
13
+ const alg = negotiateAlg(key, supportedAlgs);
14
+ return async function (input, init) {
15
+ const request = init == null && input instanceof Request
16
+ ? input
17
+ : new Request(input, init);
18
+ const authorizationHeader = request.headers.get('Authorization');
19
+ const ath = authorizationHeader?.startsWith('DPoP ')
20
+ ? await sha256(authorizationHeader.slice(5))
21
+ : undefined;
22
+ const { origin } = new URL(request.url);
23
+ const htm = request.method;
24
+ const htu = buildHtu(request.url);
25
+ let initNonce;
26
+ try {
27
+ initNonce = await nonces.get(origin);
28
+ }
29
+ catch {
30
+ // Ignore get errors, we will just not send a nonce
31
+ }
32
+ const initProof = await buildProof(key, alg, htm, htu, initNonce, ath);
33
+ request.headers.set('DPoP', initProof);
34
+ const initResponse = await fetch.call(this, request);
35
+ // Make sure the response body is consumed. Either by the caller (when the
36
+ // response is returned), of if an error is thrown (catch block).
37
+ const nextNonce = initResponse.headers.get('DPoP-Nonce');
38
+ if (!nextNonce || nextNonce === initNonce) {
39
+ // No nonce was returned or it is the same as the one we sent. No need to
40
+ // update the nonce store, or retry the request.
41
+ return initResponse;
42
+ }
43
+ // Store the fresh nonce for future requests
44
+ try {
45
+ await nonces.set(origin, nextNonce);
46
+ }
47
+ catch {
48
+ // Ignore set errors
49
+ }
50
+ const shouldRetry = await isUseDpopNonceError(initResponse, isAuthServer);
51
+ if (!shouldRetry) {
52
+ // Not a "use_dpop_nonce" error, so there is no need to retry
53
+ return initResponse;
54
+ }
55
+ // If the input stream was already consumed, we cannot retry the request. A
56
+ // solution would be to clone() the request but that would bufferize the
57
+ // entire stream in memory which can lead to memory starvation. Instead, we
58
+ // will return the original response and let the calling code handle retries.
59
+ if (input === request) {
60
+ // The input request body was consumed. We cannot retry the request.
61
+ return initResponse;
62
+ }
63
+ if (ReadableStream && init?.body instanceof ReadableStream) {
64
+ // The init body was consumed. We cannot retry the request.
65
+ return initResponse;
66
+ }
67
+ // We will now retry the request with the fresh nonce.
68
+ // The initial response body must be consumed (see cancelBody's doc).
69
+ await cancelBody(initResponse, 'log');
70
+ const nextProof = await buildProof(key, alg, htm, htu, nextNonce, ath);
71
+ const nextRequest = new Request(input, init);
72
+ nextRequest.headers.set('DPoP', nextProof);
73
+ const retryRequest = await fetch.call(this, nextRequest);
74
+ const retryNonce = retryRequest.headers.get('DPoP-Nonce');
75
+ if (!retryNonce || retryNonce === initNonce) {
76
+ // No nonce was returned or it is the same as the one we sent. No need to
77
+ // update the nonce store, or retry the request.
78
+ return retryRequest;
79
+ }
80
+ // Store the fresh nonce for future requests
81
+ try {
82
+ await nonces.set(origin, retryNonce);
83
+ }
84
+ catch {
85
+ // Ignore set errors
86
+ }
87
+ return retryRequest;
88
+ };
89
+ }
90
+ /**
91
+ * Strip query and fragment
92
+ *
93
+ * @see {@link https://www.rfc-editor.org/rfc/rfc9449.html#section-4.2-4.6}
94
+ */
95
+ function buildHtu(url) {
96
+ const fragmentIndex = url.indexOf('#');
97
+ const queryIndex = url.indexOf('?');
98
+ const end = fragmentIndex === -1
99
+ ? queryIndex
100
+ : queryIndex === -1
101
+ ? fragmentIndex
102
+ : Math.min(fragmentIndex, queryIndex);
103
+ return end === -1 ? url : url.slice(0, end);
104
+ }
105
+ async function buildProof(key, alg, htm, htu, nonce, ath) {
106
+ const jwk = key.bareJwk;
107
+ if (!jwk) {
108
+ throw new Error('Only asymmetric keys can be used as DPoP proofs');
109
+ }
110
+ const now = Math.floor(Date.now() / 1e3);
111
+ return key.createJwt(
112
+ // https://datatracker.ietf.org/doc/html/rfc9449#section-4.2
113
+ {
114
+ alg,
115
+ typ: 'dpop+jwt',
116
+ jwk,
117
+ }, {
118
+ iat: now,
119
+ // Any collision will cause the request to be rejected by the server. no biggie.
120
+ jti: Math.random().toString(36).slice(2),
121
+ htm,
122
+ htu,
123
+ nonce,
124
+ ath,
125
+ });
126
+ }
127
+ async function isUseDpopNonceError(response, isAuthServer) {
128
+ // https://datatracker.ietf.org/doc/html/rfc6750#section-3
129
+ // https://datatracker.ietf.org/doc/html/rfc9449#name-resource-server-provided-no
130
+ if (isAuthServer === undefined || isAuthServer === false) {
131
+ if (response.status === 401) {
132
+ const wwwAuth = response.headers.get('WWW-Authenticate');
133
+ if (wwwAuth?.startsWith('DPoP')) {
134
+ return wwwAuth.includes('error="use_dpop_nonce"');
135
+ }
136
+ }
137
+ }
138
+ // https://datatracker.ietf.org/doc/html/rfc9449#name-authorization-server-provid
139
+ if (isAuthServer === undefined || isAuthServer === true) {
140
+ if (response.status === 400) {
141
+ try {
142
+ const json = await peekJson(response, 10 * 1024);
143
+ return json?.['error'] === 'use_dpop_nonce';
144
+ }
145
+ catch {
146
+ // Response too big (to be "use_dpop_nonce" error) or invalid JSON
147
+ return false;
148
+ }
149
+ }
150
+ }
151
+ return false;
152
+ }
153
+ function negotiateAlg(key, supportedAlgs) {
154
+ if (supportedAlgs) {
155
+ // Use order of supportedAlgs as preference
156
+ const alg = supportedAlgs.find((a) => key.algorithms.includes(a));
157
+ if (alg)
158
+ return alg;
159
+ }
160
+ else {
161
+ const [alg] = key.algorithms;
162
+ if (alg)
163
+ return alg;
164
+ }
165
+ throw new Error('Key does not match any alg supported by the server');
166
+ }
167
+ async function subtleSha256(input) {
168
+ if (subtle == null) {
169
+ throw new Error(`crypto.subtle is not available in this environment. Please provide a sha256 function.`);
170
+ }
171
+ const bytes = new TextEncoder().encode(input);
172
+ const digest = await subtle.digest('SHA-256', bytes);
173
+ const digestBytes = new Uint8Array(digest);
174
+ return base64url.baseEncode(digestBytes);
175
+ }
176
+ //# sourceMappingURL=fetch-dpop.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch-dpop.js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AW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IAC7C,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,CAAA;IACpD,MAAM,WAAW,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAA;IAC1C,OAAO,SAAS,CAAC,UAAU,CAAC,WAAW,CAAC,CAAA;AAC1C,CAAC","sourcesContent":["import { base64url } from 'multiformats/bases/base64'\nimport type { Key } from '@atproto/jwk'\nimport {\n type Fetch,\n type FetchContext,\n cancelBody,\n peekJson,\n} from '@atproto-labs/fetch'\nimport type { SimpleStore } from '@atproto-labs/simple-store'\n\n// \"undefined\" in non https environments or environments without crypto\nconst subtle = globalThis.crypto?.subtle as SubtleCrypto | undefined\n\nconst ReadableStream = globalThis.ReadableStream as\n typeof globalThis.ReadableStream | undefined\n\nexport type DpopFetchWrapperOptions<C = FetchContext> = {\n key: Key\n nonces: SimpleStore<string, string>\n supportedAlgs?: string[]\n sha256?: (input: string) => Promise<string>\n\n /**\n * Is the intended server an authorization server (true) or a resource server\n * (false)? Setting this may allow to avoid parsing the response body to\n * determine the dpop-nonce.\n *\n * @default undefined\n */\n isAuthServer?: boolean\n fetch?: Fetch<C>\n}\n\nexport function dpopFetchWrapper<C = FetchContext>({\n key,\n // @TODO we should provide a default based on specs\n supportedAlgs,\n nonces,\n sha256 = typeof subtle !== 'undefined' ? subtleSha256 : undefined,\n isAuthServer,\n fetch = globalThis.fetch,\n}: DpopFetchWrapperOptions<C>): Fetch<C> {\n if (!sha256) {\n throw new TypeError(\n `crypto.subtle is not available in this environment. Please provide a sha256 function.`,\n )\n }\n\n // Throws if negotiation fails\n const alg = negotiateAlg(key, supportedAlgs)\n\n return async function (this: C, input, init) {\n const request: Request =\n init == null && input instanceof Request\n ? input\n : new Request(input, init)\n\n const authorizationHeader = request.headers.get('Authorization')\n const ath = authorizationHeader?.startsWith('DPoP ')\n ? await sha256(authorizationHeader.slice(5))\n : undefined\n\n const { origin } = new URL(request.url)\n\n const htm = request.method\n const htu = buildHtu(request.url)\n\n let initNonce: string | undefined\n try {\n initNonce = await nonces.get(origin)\n } catch {\n // Ignore get errors, we will just not send a nonce\n }\n\n const initProof = await buildProof(key, alg, htm, htu, initNonce, ath)\n request.headers.set('DPoP', initProof)\n\n const initResponse = await fetch.call(this, request)\n\n // Make sure the response body is consumed. Either by the caller (when the\n // response is returned), of if an error is thrown (catch block).\n\n const nextNonce = initResponse.headers.get('DPoP-Nonce')\n if (!nextNonce || nextNonce === initNonce) {\n // No nonce was returned or it is the same as the one we sent. No need to\n // update the nonce store, or retry the request.\n return initResponse\n }\n\n // Store the fresh nonce for future requests\n try {\n await nonces.set(origin, nextNonce)\n } catch {\n // Ignore set errors\n }\n\n const shouldRetry = await isUseDpopNonceError(initResponse, isAuthServer)\n if (!shouldRetry) {\n // Not a \"use_dpop_nonce\" error, so there is no need to retry\n return initResponse\n }\n\n // If the input stream was already consumed, we cannot retry the request. A\n // solution would be to clone() the request but that would bufferize the\n // entire stream in memory which can lead to memory starvation. Instead, we\n // will return the original response and let the calling code handle retries.\n\n if (input === request) {\n // The input request body was consumed. We cannot retry the request.\n return initResponse\n }\n\n if (ReadableStream && init?.body instanceof ReadableStream) {\n // The init body was consumed. We cannot retry the request.\n return initResponse\n }\n\n // We will now retry the request with the fresh nonce.\n\n // The initial response body must be consumed (see cancelBody's doc).\n await cancelBody(initResponse, 'log')\n\n const nextProof = await buildProof(key, alg, htm, htu, nextNonce, ath)\n const nextRequest = new Request(input, init)\n nextRequest.headers.set('DPoP', nextProof)\n\n const retryRequest = await fetch.call(this, nextRequest)\n const retryNonce = retryRequest.headers.get('DPoP-Nonce')\n if (!retryNonce || retryNonce === initNonce) {\n // No nonce was returned or it is the same as the one we sent. No need to\n // update the nonce store, or retry the request.\n return retryRequest\n }\n\n // Store the fresh nonce for future requests\n try {\n await nonces.set(origin, retryNonce)\n } catch {\n // Ignore set errors\n }\n\n return retryRequest\n }\n}\n\n/**\n * Strip query and fragment\n *\n * @see {@link https://www.rfc-editor.org/rfc/rfc9449.html#section-4.2-4.6}\n */\nfunction buildHtu(url: string): string {\n const fragmentIndex = url.indexOf('#')\n const queryIndex = url.indexOf('?')\n\n const end =\n fragmentIndex === -1\n ? queryIndex\n : queryIndex === -1\n ? fragmentIndex\n : Math.min(fragmentIndex, queryIndex)\n\n return end === -1 ? url : url.slice(0, end)\n}\n\nasync function buildProof(\n key: Key,\n alg: string,\n htm: string,\n htu: string,\n nonce?: string,\n ath?: string,\n) {\n const jwk = key.bareJwk\n if (!jwk) {\n throw new Error('Only asymmetric keys can be used as DPoP proofs')\n }\n\n const now = Math.floor(Date.now() / 1e3)\n\n return key.createJwt(\n // https://datatracker.ietf.org/doc/html/rfc9449#section-4.2\n {\n alg,\n typ: 'dpop+jwt',\n jwk,\n },\n {\n iat: now,\n // Any collision will cause the request to be rejected by the server. no biggie.\n jti: Math.random().toString(36).slice(2),\n htm,\n htu,\n nonce,\n ath,\n },\n )\n}\n\nasync function isUseDpopNonceError(\n response: Response,\n isAuthServer?: boolean,\n): Promise<boolean> {\n // https://datatracker.ietf.org/doc/html/rfc6750#section-3\n // https://datatracker.ietf.org/doc/html/rfc9449#name-resource-server-provided-no\n if (isAuthServer === undefined || isAuthServer === false) {\n if (response.status === 401) {\n const wwwAuth = response.headers.get('WWW-Authenticate')\n if (wwwAuth?.startsWith('DPoP')) {\n return wwwAuth.includes('error=\"use_dpop_nonce\"')\n }\n }\n }\n\n // https://datatracker.ietf.org/doc/html/rfc9449#name-authorization-server-provid\n if (isAuthServer === undefined || isAuthServer === true) {\n if (response.status === 400) {\n try {\n const json = await peekJson(response, 10 * 1024)\n return (json as any)?.['error'] === 'use_dpop_nonce'\n } catch {\n // Response too big (to be \"use_dpop_nonce\" error) or invalid JSON\n return false\n }\n }\n }\n\n return false\n}\n\nfunction negotiateAlg(key: Key, supportedAlgs: string[] | undefined): string {\n if (supportedAlgs) {\n // Use order of supportedAlgs as preference\n const alg = supportedAlgs.find((a) => key.algorithms.includes(a))\n if (alg) return alg\n } else {\n const [alg] = key.algorithms\n if (alg) return alg\n }\n\n throw new Error('Key does not match any alg supported by the server')\n}\n\nasync function subtleSha256(input: string): Promise<string> {\n if (subtle == null) {\n throw new Error(\n `crypto.subtle is not available in this environment. Please provide a sha256 function.`,\n )\n }\n\n const bytes = new TextEncoder().encode(input)\n const digest = await subtle.digest('SHA-256', bytes)\n const digestBytes = new Uint8Array(digest)\n return base64url.baseEncode(digestBytes)\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export { type CreateIdentityResolverOptions, createIdentityResolver, } from '@atproto-labs/identity-resolver';
2
+ //# sourceMappingURL=identity-resolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identity-resolver.d.ts","sourceRoot":"","sources":["../src/identity-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,6BAA6B,EAClC,sBAAsB,GACvB,MAAM,iCAAiC,CAAA"}
@@ -0,0 +1,21 @@
1
+ export { createIdentityResolver, } from '@atproto-labs/identity-resolver';
2
+ // @TODO Currently, the `OAuthClient`'s `IdentityResolver` is an instance of
3
+ // `AtprotoIdentityResolver`, which implements the ATProto Identity resolution
4
+ // protocol (did resolution + dns resolution). In the future, we may want to
5
+ // allow using a different `IdentityResolver` implementation, such as one based
6
+ // on XRPC's "com.atproto.identity.resolveIdentity" method. This would be
7
+ // particularly useful for browser based clients, since DNS lookups are not
8
+ // available in browser environments (and require an alternative implementation,
9
+ // such as one based on the "com.atproto.identity.resolveHandle" XRPC method, or
10
+ // using DNS-over-HTTPS). Once we decide to support such a behavior, the
11
+ // `identityResolver` option below should be made mandatory, and the code bellow
12
+ // should be removed from the @atproto/oauth-client package (and moved to the
13
+ // environment specific package, such as @atproto/oauth-client-browser and
14
+ // @atproto/oauth-client-node), allowing the dependency graph to be optimized
15
+ // for the specific environment. When that is done, the
16
+ // `AtprotoIdentityResolver` class should also be moved to its own package.
17
+ // @TODO Once we move to a distinct implementation, we should also introduce a
18
+ // caching layer for the `IdentityResolver` to avoid redundant resolution
19
+ // requests. Once this is done, the caching layers for the did and handle
20
+ // resolvers should be removed as they will be redundant.
21
+ //# sourceMappingURL=identity-resolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identity-resolver.js","sourceRoot":"","sources":["../src/identity-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,sBAAsB,GACvB,MAAM,iCAAiC,CAAA;AAExC,4EAA4E;AAC5E,8EAA8E;AAC9E,4EAA4E;AAC5E,+EAA+E;AAC/E,yEAAyE;AACzE,2EAA2E;AAC3E,gFAAgF;AAChF,gFAAgF;AAChF,wEAAwE;AACxE,gFAAgF;AAChF,6EAA6E;AAC7E,0EAA0E;AAC1E,6EAA6E;AAC7E,uDAAuD;AACvD,2EAA2E;AAE3E,8EAA8E;AAC9E,yEAAyE;AACzE,yEAAyE;AACzE,yDAAyD","sourcesContent":["export {\n type CreateIdentityResolverOptions,\n createIdentityResolver,\n} from '@atproto-labs/identity-resolver'\n\n// @TODO Currently, the `OAuthClient`'s `IdentityResolver` is an instance of\n// `AtprotoIdentityResolver`, which implements the ATProto Identity resolution\n// protocol (did resolution + dns resolution). In the future, we may want to\n// allow using a different `IdentityResolver` implementation, such as one based\n// on XRPC's \"com.atproto.identity.resolveIdentity\" method. This would be\n// particularly useful for browser based clients, since DNS lookups are not\n// available in browser environments (and require an alternative implementation,\n// such as one based on the \"com.atproto.identity.resolveHandle\" XRPC method, or\n// using DNS-over-HTTPS). Once we decide to support such a behavior, the\n// `identityResolver` option below should be made mandatory, and the code bellow\n// should be removed from the @atproto/oauth-client package (and moved to the\n// environment specific package, such as @atproto/oauth-client-browser and\n// @atproto/oauth-client-node), allowing the dependency graph to be optimized\n// for the specific environment. When that is done, the\n// `AtprotoIdentityResolver` class should also be moved to its own package.\n\n// @TODO Once we move to a distinct implementation, we should also introduce a\n// caching layer for the `IdentityResolver` to avoid redundant resolution\n// requests. Once this is done, the caching layers for the did and handle\n// resolvers should be removed as they will be redundant.\n"]}
@@ -0,0 +1,25 @@
1
+ import 'core-js/es/symbol/dispose.js';
2
+ export * from '@atproto-labs/did-resolver';
3
+ export { FetchError, FetchRequestError, FetchResponseError, } from '@atproto-labs/fetch';
4
+ export * from '@atproto-labs/handle-resolver';
5
+ export * from '@atproto/did';
6
+ export * from '@atproto/jwk';
7
+ export * from '@atproto/oauth-types';
8
+ export * from './lock.js';
9
+ export * from './oauth-authorization-server-metadata-resolver.js';
10
+ export * from './oauth-callback-error.js';
11
+ export * from './oauth-client.js';
12
+ export * from './oauth-protected-resource-metadata-resolver.js';
13
+ export * from './oauth-resolver-error.js';
14
+ export * from './oauth-response-error.js';
15
+ export * from './oauth-server-agent.js';
16
+ export * from './oauth-server-factory.js';
17
+ export * from './oauth-session.js';
18
+ export * from './runtime-implementation.js';
19
+ export * from './session-getter.js';
20
+ export * from './state-store.js';
21
+ export * from './types.js';
22
+ export * from './errors/token-invalid-error.js';
23
+ export * from './errors/token-refresh-error.js';
24
+ export * from './errors/token-revoked-error.js';
25
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,8BAA8B,CAAA;AAErC,cAAc,4BAA4B,CAAA;AAC1C,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,qBAAqB,CAAA;AAC5B,cAAc,+BAA+B,CAAA;AAE7C,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,sBAAsB,CAAA;AAEpC,cAAc,WAAW,CAAA;AACzB,cAAc,mDAAmD,CAAA;AACjE,cAAc,2BAA2B,CAAA;AACzC,cAAc,mBAAmB,CAAA;AACjC,cAAc,iDAAiD,CAAA;AAC/D,cAAc,2BAA2B,CAAA;AACzC,cAAc,2BAA2B,CAAA;AACzC,cAAc,yBAAyB,CAAA;AACvC,cAAc,2BAA2B,CAAA;AACzC,cAAc,oBAAoB,CAAA;AAClC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,qBAAqB,CAAA;AACnC,cAAc,kBAAkB,CAAA;AAChC,cAAc,YAAY,CAAA;AAE1B,cAAc,iCAAiC,CAAA;AAC/C,cAAc,iCAAiC,CAAA;AAC/C,cAAc,iCAAiC,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,25 @@
1
+ import 'core-js/es/symbol/dispose.js';
2
+ export * from '@atproto-labs/did-resolver';
3
+ export { FetchError, FetchRequestError, FetchResponseError, } from '@atproto-labs/fetch';
4
+ export * from '@atproto-labs/handle-resolver';
5
+ export * from '@atproto/did';
6
+ export * from '@atproto/jwk';
7
+ export * from '@atproto/oauth-types';
8
+ export * from './lock.js';
9
+ export * from './oauth-authorization-server-metadata-resolver.js';
10
+ export * from './oauth-callback-error.js';
11
+ export * from './oauth-client.js';
12
+ export * from './oauth-protected-resource-metadata-resolver.js';
13
+ export * from './oauth-resolver-error.js';
14
+ export * from './oauth-response-error.js';
15
+ export * from './oauth-server-agent.js';
16
+ export * from './oauth-server-factory.js';
17
+ export * from './oauth-session.js';
18
+ export * from './runtime-implementation.js';
19
+ export * from './session-getter.js';
20
+ export * from './state-store.js';
21
+ export * from './types.js';
22
+ export * from './errors/token-invalid-error.js';
23
+ export * from './errors/token-refresh-error.js';
24
+ export * from './errors/token-revoked-error.js';
25
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,8BAA8B,CAAA;AAErC,cAAc,4BAA4B,CAAA;AAC1C,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,qBAAqB,CAAA;AAC5B,cAAc,+BAA+B,CAAA;AAE7C,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,sBAAsB,CAAA;AAEpC,cAAc,WAAW,CAAA;AACzB,cAAc,mDAAmD,CAAA;AACjE,cAAc,2BAA2B,CAAA;AACzC,cAAc,mBAAmB,CAAA;AACjC,cAAc,iDAAiD,CAAA;AAC/D,cAAc,2BAA2B,CAAA;AACzC,cAAc,2BAA2B,CAAA;AACzC,cAAc,yBAAyB,CAAA;AACvC,cAAc,2BAA2B,CAAA;AACzC,cAAc,oBAAoB,CAAA;AAClC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,qBAAqB,CAAA;AACnC,cAAc,kBAAkB,CAAA;AAChC,cAAc,YAAY,CAAA;AAE1B,cAAc,iCAAiC,CAAA;AAC/C,cAAc,iCAAiC,CAAA;AAC/C,cAAc,iCAAiC,CAAA","sourcesContent":["import 'core-js/es/symbol/dispose.js'\n\nexport * from '@atproto-labs/did-resolver'\nexport {\n FetchError,\n FetchRequestError,\n FetchResponseError,\n} from '@atproto-labs/fetch'\nexport * from '@atproto-labs/handle-resolver'\n\nexport * from '@atproto/did'\nexport * from '@atproto/jwk'\nexport * from '@atproto/oauth-types'\n\nexport * from './lock.js'\nexport * from './oauth-authorization-server-metadata-resolver.js'\nexport * from './oauth-callback-error.js'\nexport * from './oauth-client.js'\nexport * from './oauth-protected-resource-metadata-resolver.js'\nexport * from './oauth-resolver-error.js'\nexport * from './oauth-response-error.js'\nexport * from './oauth-server-agent.js'\nexport * from './oauth-server-factory.js'\nexport * from './oauth-session.js'\nexport * from './runtime-implementation.js'\nexport * from './session-getter.js'\nexport * from './state-store.js'\nexport * from './types.js'\n\nexport * from './errors/token-invalid-error.js'\nexport * from './errors/token-refresh-error.js'\nexport * from './errors/token-revoked-error.js'\n"]}
package/dist/lock.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import type { RuntimeLock } from './runtime-implementation.js';
2
+ export declare const requestLocalLock: RuntimeLock;
3
+ //# sourceMappingURL=lock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lock.d.ts","sourceRoot":"","sources":["../src/lock.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAwB9D,eAAO,MAAM,gBAAgB,EAAE,WAQ9B,CAAA"}
package/dist/lock.js ADDED
@@ -0,0 +1,29 @@
1
+ const locks = new Map();
2
+ function acquireLocalLock(name) {
3
+ return new Promise((resolveAcquire) => {
4
+ const prev = locks.get(name) ?? Promise.resolve();
5
+ const next = prev.then(() => {
6
+ return new Promise((resolveRelease) => {
7
+ const release = () => {
8
+ // Only delete the lock if it is still the current one
9
+ if (locks.get(name) === next)
10
+ locks.delete(name);
11
+ resolveRelease();
12
+ };
13
+ resolveAcquire(release);
14
+ });
15
+ });
16
+ locks.set(name, next);
17
+ });
18
+ }
19
+ export const requestLocalLock = (name, fn) => {
20
+ return acquireLocalLock(name).then(async (release) => {
21
+ try {
22
+ return await fn();
23
+ }
24
+ finally {
25
+ release();
26
+ }
27
+ });
28
+ };
29
+ //# sourceMappingURL=lock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lock.js","sourceRoot":"","sources":["../src/lock.ts"],"names":[],"mappings":"AAEA,MAAM,KAAK,GAAG,IAAI,GAAG,EAA0B,CAAA;AAE/C,SAAS,gBAAgB,CAAC,IAAa;IACrC,OAAO,IAAI,OAAO,CAAC,CAAC,cAAc,EAAE,EAAE;QACpC,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,OAAO,CAAC,OAAO,EAAE,CAAA;QACjD,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE;YAC1B,OAAO,IAAI,OAAO,CAAO,CAAC,cAAc,EAAE,EAAE;gBAC1C,MAAM,OAAO,GAAG,GAAG,EAAE;oBACnB,sDAAsD;oBACtD,IAAI,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,IAAI;wBAAE,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;oBAEhD,cAAc,EAAE,CAAA;gBAClB,CAAC,CAAA;gBAED,cAAc,CAAC,OAAO,CAAC,CAAA;YACzB,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;QAEF,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;IACvB,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAgB,CAAC,IAAI,EAAE,EAAE,EAAE,EAAE;IACxD,OAAO,gBAAgB,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;QACnD,IAAI,CAAC;YACH,OAAO,MAAM,EAAE,EAAE,CAAA;QACnB,CAAC;gBAAS,CAAC;YACT,OAAO,EAAE,CAAA;QACX,CAAC;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA","sourcesContent":["import type { RuntimeLock } from './runtime-implementation.js'\n\nconst locks = new Map<unknown, Promise<void>>()\n\nfunction acquireLocalLock(name: unknown): Promise<() => void> {\n return new Promise((resolveAcquire) => {\n const prev = locks.get(name) ?? Promise.resolve()\n const next = prev.then(() => {\n return new Promise<void>((resolveRelease) => {\n const release = () => {\n // Only delete the lock if it is still the current one\n if (locks.get(name) === next) locks.delete(name)\n\n resolveRelease()\n }\n\n resolveAcquire(release)\n })\n })\n\n locks.set(name, next)\n })\n}\n\nexport const requestLocalLock: RuntimeLock = (name, fn) => {\n return acquireLocalLock(name).then(async (release) => {\n try {\n return await fn()\n } finally {\n release()\n }\n })\n}\n"]}
@@ -0,0 +1,25 @@
1
+ import { type OAuthAuthorizationServerMetadata } from '@atproto/oauth-types';
2
+ import { type Fetch } from '@atproto-labs/fetch';
3
+ import { CachedGetter, type GetCachedOptions, type SimpleStore, type StoreErrorHandler } from '@atproto-labs/simple-store';
4
+ export type { GetCachedOptions, OAuthAuthorizationServerMetadata };
5
+ export type AuthorizationServerMetadataCache = SimpleStore<string, OAuthAuthorizationServerMetadata>;
6
+ export type OAuthAuthorizationServerMetadataResolverConfig = {
7
+ allowHttpIssuer?: boolean;
8
+ /**
9
+ * Called when the metadata cache throws. The cache is best-effort: failures
10
+ * are logged (by default) and degrade to a cache miss + refetch, rather than
11
+ * being propagated.
12
+ */
13
+ onCacheError?: StoreErrorHandler<string>;
14
+ };
15
+ /**
16
+ * @see {@link https://datatracker.ietf.org/doc/html/rfc8414}
17
+ */
18
+ export declare class OAuthAuthorizationServerMetadataResolver extends CachedGetter<string, OAuthAuthorizationServerMetadata> {
19
+ private readonly fetch;
20
+ private readonly allowHttpIssuer;
21
+ constructor(cache: AuthorizationServerMetadataCache, fetch?: Fetch, config?: OAuthAuthorizationServerMetadataResolverConfig);
22
+ get(input: URL | string, options?: GetCachedOptions): Promise<OAuthAuthorizationServerMetadata>;
23
+ private fetchMetadata;
24
+ }
25
+ //# sourceMappingURL=oauth-authorization-server-metadata-resolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth-authorization-server-metadata-resolver.d.ts","sourceRoot":"","sources":["../src/oauth-authorization-server-metadata-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,gCAAgC,EAGtC,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EACL,KAAK,KAAK,EAIX,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EACL,YAAY,EACZ,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,KAAK,iBAAiB,EAEvB,MAAM,4BAA4B,CAAA;AAGnC,YAAY,EAAE,gBAAgB,EAAE,gCAAgC,EAAE,CAAA;AAElE,MAAM,MAAM,gCAAgC,GAAG,WAAW,CACxD,MAAM,EACN,gCAAgC,CACjC,CAAA;AAED,MAAM,MAAM,8CAA8C,GAAG;IAC3D,eAAe,CAAC,EAAE,OAAO,CAAA;IAEzB;;;;OAIG;IACH,YAAY,CAAC,EAAE,iBAAiB,CAAC,MAAM,CAAC,CAAA;CACzC,CAAA;AAED;;GAEG;AACH,qBAAa,wCAAyC,SAAQ,YAAY,CACxE,MAAM,EACN,gCAAgC,CACjC;IACC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAgB;IACtC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;IAEzC,YACE,KAAK,EAAE,gCAAgC,EACvC,KAAK,CAAC,EAAE,KAAK,EACb,MAAM,CAAC,EAAE,8CAA8C,EASxD;IAEK,GAAG,CACP,KAAK,EAAE,GAAG,GAAG,MAAM,EACnB,OAAO,CAAC,EAAE,gBAAgB,GACzB,OAAO,CAAC,gCAAgC,CAAC,CAQ3C;YAEa,aAAa;CAwD5B"}
@@ -0,0 +1,54 @@
1
+ import { oauthAuthorizationServerMetadataValidator, oauthIssuerIdentifierSchema, } from '@atproto/oauth-types';
2
+ import { FetchResponseError, bindFetch, cancelBody, } from '@atproto-labs/fetch';
3
+ import { CachedGetter, swallowStoreErrors, } from '@atproto-labs/simple-store';
4
+ import { contentMime } from './util.js';
5
+ /**
6
+ * @see {@link https://datatracker.ietf.org/doc/html/rfc8414}
7
+ */
8
+ export class OAuthAuthorizationServerMetadataResolver extends CachedGetter {
9
+ constructor(cache, fetch, config) {
10
+ super(async (issuer, options) => this.fetchMetadata(issuer, options), swallowStoreErrors(cache, config?.onCacheError));
11
+ this.fetch = bindFetch(fetch);
12
+ this.allowHttpIssuer = config?.allowHttpIssuer === true;
13
+ }
14
+ async get(input, options) {
15
+ const issuer = oauthIssuerIdentifierSchema.parse(String(input));
16
+ if (!this.allowHttpIssuer && issuer.startsWith('http:')) {
17
+ throw new TypeError('Unsecure issuer URL protocol only allowed in development and test environments');
18
+ }
19
+ return super.get(issuer, options);
20
+ }
21
+ async fetchMetadata(issuer, options) {
22
+ const url = new URL(`/.well-known/oauth-authorization-server`, issuer);
23
+ const request = new Request(url, {
24
+ headers: { accept: 'application/json' },
25
+ cache: options?.noCache ? 'no-cache' : undefined,
26
+ signal: options?.signal,
27
+ redirect: 'manual', // response must be 200 OK
28
+ });
29
+ const response = await this.fetch(request);
30
+ // https://datatracker.ietf.org/doc/html/rfc8414#section-3.2
31
+ if (response.status !== 200) {
32
+ await cancelBody(response, 'log');
33
+ throw await FetchResponseError.from(response, `Unexpected status code ${response.status} for "${url}"`, undefined, { cause: request });
34
+ }
35
+ if (contentMime(response.headers) !== 'application/json') {
36
+ await cancelBody(response, 'log');
37
+ throw await FetchResponseError.from(response, `Unexpected content type for "${url}"`, undefined, { cause: request });
38
+ }
39
+ const metadata = oauthAuthorizationServerMetadataValidator.parse(await response.json());
40
+ // Validate the issuer (MIX-UP attacks)
41
+ // https://datatracker.ietf.org/doc/html/draft-ietf-oauth-security-topics#name-mix-up-attacks
42
+ // https://datatracker.ietf.org/doc/html/rfc8414#section-2
43
+ if (metadata.issuer !== issuer) {
44
+ throw new TypeError(`Invalid issuer ${metadata.issuer}`);
45
+ }
46
+ // ATPROTO requires client_id_metadata_document
47
+ // https://datatracker.ietf.org/doc/draft-ietf-oauth-client-id-metadata-document/
48
+ if (metadata.client_id_metadata_document_supported !== true) {
49
+ throw new TypeError(`Authorization server "${issuer}" does not support client_id_metadata_document`);
50
+ }
51
+ return metadata;
52
+ }
53
+ }
54
+ //# sourceMappingURL=oauth-authorization-server-metadata-resolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth-authorization-server-metadata-resolver.js","sourceRoot":"","sources":["../src/oauth-authorization-server-metadata-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,yCAAyC,EACzC,2BAA2B,GAC5B,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAEL,kBAAkB,EAClB,SAAS,EACT,UAAU,GACX,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EACL,YAAY,EAIZ,kBAAkB,GACnB,MAAM,4BAA4B,CAAA;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAoBvC;;GAEG;AACH,MAAM,OAAO,wCAAyC,SAAQ,YAG7D;IAIC,YACE,KAAuC,EACvC,KAAa,EACb,MAAuD;QAEvD,KAAK,CACH,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE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AK,CAAC,CAAA;YACjC,MAAM,MAAM,kBAAkB,CAAC,IAAI,CACjC,QAAQ,EACR,0BAA0B,QAAQ,CAAC,MAAM,SAAS,GAAG,GAAG,EACxD,SAAS,EACT,EAAE,KAAK,EAAE,OAAO,EAAE,CACnB,CAAA;QACH,CAAC;QAED,IAAI,WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,kBAAkB,EAAE,CAAC;YACzD,MAAM,UAAU,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAA;YACjC,MAAM,MAAM,kBAAkB,CAAC,IAAI,CACjC,QAAQ,EACR,gCAAgC,GAAG,GAAG,EACtC,SAAS,EACT,EAAE,KAAK,EAAE,OAAO,EAAE,CACnB,CAAA;QACH,CAAC;QAED,MAAM,QAAQ,GAAG,yCAAyC,CAAC,KAAK,CAC9D,MAAM,QAAQ,CAAC,IAAI,EAAE,CACtB,CAAA;QAED,uCAAuC;QACvC,6FAA6F;QAC7F,0DAA0D;QAC1D,IAAI,QAAQ,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;YAC/B,MAAM,IAAI,SAAS,CAAC,kBAAkB,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAA;QAC1D,CAAC;QAED,+CAA+C;QAC/C,iFAAiF;QACjF,IAAI,QAAQ,CAAC,qCAAqC,KAAK,IAAI,EAAE,CAAC;YAC5D,MAAM,IAAI,SAAS,CACjB,yBAAyB,MAAM,gDAAgD,CAChF,CAAA;QACH,CAAC;QAED,OAAO,QAAQ,CAAA;IACjB,CAAC;CACF","sourcesContent":["import {\n type OAuthAuthorizationServerMetadata,\n oauthAuthorizationServerMetadataValidator,\n oauthIssuerIdentifierSchema,\n} from '@atproto/oauth-types'\nimport {\n type Fetch,\n FetchResponseError,\n bindFetch,\n cancelBody,\n} from '@atproto-labs/fetch'\nimport {\n CachedGetter,\n type GetCachedOptions,\n type SimpleStore,\n type StoreErrorHandler,\n swallowStoreErrors,\n} from '@atproto-labs/simple-store'\nimport { contentMime } from './util.js'\n\nexport type { GetCachedOptions, OAuthAuthorizationServerMetadata }\n\nexport type AuthorizationServerMetadataCache = SimpleStore<\n string,\n OAuthAuthorizationServerMetadata\n>\n\nexport type OAuthAuthorizationServerMetadataResolverConfig = {\n allowHttpIssuer?: boolean\n\n /**\n * Called when the metadata cache throws. The cache is best-effort: failures\n * are logged (by default) and degrade to a cache miss + refetch, rather than\n * being propagated.\n */\n onCacheError?: StoreErrorHandler<string>\n}\n\n/**\n * @see {@link https://datatracker.ietf.org/doc/html/rfc8414}\n */\nexport class OAuthAuthorizationServerMetadataResolver extends CachedGetter<\n string,\n OAuthAuthorizationServerMetadata\n> {\n private readonly fetch: Fetch<unknown>\n private readonly allowHttpIssuer: boolean\n\n constructor(\n cache: AuthorizationServerMetadataCache,\n fetch?: Fetch,\n config?: OAuthAuthorizationServerMetadataResolverConfig,\n ) {\n super(\n async (issuer, options) => this.fetchMetadata(issuer, options),\n swallowStoreErrors(cache, config?.onCacheError),\n )\n\n this.fetch = bindFetch(fetch)\n this.allowHttpIssuer = config?.allowHttpIssuer === true\n }\n\n async get(\n input: URL | string,\n options?: GetCachedOptions,\n ): Promise<OAuthAuthorizationServerMetadata> {\n const issuer = oauthIssuerIdentifierSchema.parse(String(input))\n if (!this.allowHttpIssuer && issuer.startsWith('http:')) {\n throw new TypeError(\n 'Unsecure issuer URL protocol only allowed in development and test environments',\n )\n }\n return super.get(issuer, options)\n }\n\n private async fetchMetadata(\n issuer: string,\n options?: GetCachedOptions,\n ): Promise<OAuthAuthorizationServerMetadata> {\n const url = new URL(`/.well-known/oauth-authorization-server`, issuer)\n const request = new Request(url, {\n headers: { accept: 'application/json' },\n cache: options?.noCache ? 'no-cache' : undefined,\n signal: options?.signal,\n redirect: 'manual', // response must be 200 OK\n })\n\n const response = await this.fetch(request)\n\n // https://datatracker.ietf.org/doc/html/rfc8414#section-3.2\n if (response.status !== 200) {\n await cancelBody(response, 'log')\n throw await FetchResponseError.from(\n response,\n `Unexpected status code ${response.status} for \"${url}\"`,\n undefined,\n { cause: request },\n )\n }\n\n if (contentMime(response.headers) !== 'application/json') {\n await cancelBody(response, 'log')\n throw await FetchResponseError.from(\n response,\n `Unexpected content type for \"${url}\"`,\n undefined,\n { cause: request },\n )\n }\n\n const metadata = oauthAuthorizationServerMetadataValidator.parse(\n await response.json(),\n )\n\n // Validate the issuer (MIX-UP attacks)\n // https://datatracker.ietf.org/doc/html/draft-ietf-oauth-security-topics#name-mix-up-attacks\n // https://datatracker.ietf.org/doc/html/rfc8414#section-2\n if (metadata.issuer !== issuer) {\n throw new TypeError(`Invalid issuer ${metadata.issuer}`)\n }\n\n // ATPROTO requires client_id_metadata_document\n // https://datatracker.ietf.org/doc/draft-ietf-oauth-client-id-metadata-document/\n if (metadata.client_id_metadata_document_supported !== true) {\n throw new TypeError(\n `Authorization server \"${issuer}\" does not support client_id_metadata_document`,\n )\n }\n\n return metadata\n }\n}\n"]}
@@ -0,0 +1,7 @@
1
+ export declare class OAuthCallbackError extends Error {
2
+ readonly params: URLSearchParams;
3
+ readonly state?: string | undefined;
4
+ static from(err: unknown, params: URLSearchParams, state?: string): OAuthCallbackError;
5
+ constructor(params: URLSearchParams, message?: string, state?: string | undefined, cause?: unknown);
6
+ }
7
+ //# sourceMappingURL=oauth-callback-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth-callback-error.d.ts","sourceRoot":"","sources":["../src/oauth-callback-error.ts"],"names":[],"mappings":"AAAA,qBAAa,kBAAmB,SAAQ,KAAK;aAQzB,MAAM,EAAE,eAAe;aAEvB,KAAK,CAAC,EAAE,MAAM;IAThC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,KAAK,CAAC,EAAE,MAAM,sBAIhE;IAED,YACkB,MAAM,EAAE,eAAe,EACvC,OAAO,SAA4D,EACnD,KAAK,CAAC,EAAE,MAAM,YAAA,EAC9B,KAAK,CAAC,EAAE,OAAO,EAGhB;CACF"}
@@ -0,0 +1,14 @@
1
+ export class OAuthCallbackError extends Error {
2
+ static from(err, params, state) {
3
+ if (err instanceof OAuthCallbackError)
4
+ return err;
5
+ const message = err instanceof Error ? err.message : undefined;
6
+ return new OAuthCallbackError(params, message, state, err);
7
+ }
8
+ constructor(params, message = params.get('error_description') || 'OAuth callback error', state, cause) {
9
+ super(message, { cause });
10
+ this.params = params;
11
+ this.state = state;
12
+ }
13
+ }
14
+ //# sourceMappingURL=oauth-callback-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth-callback-error.js","sourceRoot":"","sources":["../src/oauth-callback-error.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAC3C,MAAM,CAAC,IAAI,CAAC,GAAY,EAAE,MAAuB,EAAE,KAAc;QAC/D,IAAI,GAAG,YAAY,kBAAkB;YAAE,OAAO,GAAG,CAAA;QACjD,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAA;QAC9D,OAAO,IAAI,kBAAkB,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,CAAC,CAAA;IAC5D,CAAC;IAED,YACkB,MAAuB,EACvC,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,mBAAmB,CAAC,IAAI,sBAAsB,EACnD,KAAc,EAC9B,KAAe;QAEf,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;sBALT,MAAM;qBAEN,KAAK;IAIvB,CAAC;CACF","sourcesContent":["export class OAuthCallbackError extends Error {\n static from(err: unknown, params: URLSearchParams, state?: string) {\n if (err instanceof OAuthCallbackError) return err\n const message = err instanceof Error ? err.message : undefined\n return new OAuthCallbackError(params, message, state, err)\n }\n\n constructor(\n public readonly params: URLSearchParams,\n message = params.get('error_description') || 'OAuth callback error',\n public readonly state?: string,\n cause?: unknown,\n ) {\n super(message, { cause })\n }\n}\n"]}
@@ -0,0 +1,23 @@
1
+ import type { Keyset } from '@atproto/jwk';
2
+ import { type OAuthAuthorizationServerMetadata, type OAuthClientCredentials } from '@atproto/oauth-types';
3
+ import type { Runtime } from './runtime.js';
4
+ import type { ClientMetadata } from './types.js';
5
+ import type { Awaitable } from './util.js';
6
+ export type ClientAuthMethod = {
7
+ method: 'none';
8
+ } | {
9
+ method: 'private_key_jwt';
10
+ kid: string;
11
+ };
12
+ export declare function negotiateClientAuthMethod(serverMetadata: OAuthAuthorizationServerMetadata, clientMetadata: ClientMetadata, keyset?: Keyset): ClientAuthMethod;
13
+ export type ClientCredentialsFactory = () => Awaitable<{
14
+ headers?: Record<string, string>;
15
+ payload?: OAuthClientCredentials;
16
+ }>;
17
+ /**
18
+ * @throws {AuthMethodUnsatisfiableError} if the authentication method is no
19
+ * long usable (either because the AS changed, of because the key is no longer
20
+ * available in the keyset).
21
+ */
22
+ export declare function createClientCredentialsFactory(authMethod: ClientAuthMethod, serverMetadata: OAuthAuthorizationServerMetadata, clientMetadata: ClientMetadata, runtime: Runtime, keyset?: Keyset): ClientCredentialsFactory;
23
+ //# sourceMappingURL=oauth-client-auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth-client-auth.d.ts","sourceRoot":"","sources":["../src/oauth-client-auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAC1C,OAAO,EAEL,KAAK,gCAAgC,EACrC,KAAK,sBAAsB,EAC5B,MAAM,sBAAsB,CAAA;AAG7B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAChD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAE1C,MAAM,MAAM,gBAAgB,GAC1B;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,MAAM,EAAE,iBAAiB,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAA;AAEjE,wBAAgB,yBAAyB,CACvC,cAAc,EAAE,gCAAgC,EAChD,cAAc,EAAE,cAAc,EAC9B,MAAM,CAAC,EAAE,MAAM,GACd,gBAAgB,CAkDlB;AAED,MAAM,MAAM,wBAAwB,GAAG,MAAM,SAAS,CAAC;IACrD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAChC,OAAO,CAAC,EAAE,sBAAsB,CAAA;CACjC,CAAC,CAAA;AAEF;;;;GAIG;AACH,wBAAgB,8BAA8B,CAC5C,UAAU,EAAE,gBAAgB,EAC5B,cAAc,EAAE,gCAAgC,EAChD,cAAc,EAAE,cAAc,EAC9B,OAAO,EAAE,OAAO,EAChB,MAAM,CAAC,EAAE,MAAM,GACd,wBAAwB,CAwE1B"}