@atproto/oauth-client 0.6.0 → 0.7.0-next.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/CHANGELOG.md +34 -0
- package/dist/constants.js +1 -4
- package/dist/constants.js.map +1 -1
- package/dist/errors/auth-method-unsatisfiable-error.js +1 -5
- package/dist/errors/auth-method-unsatisfiable-error.js.map +1 -1
- package/dist/errors/token-invalid-error.js +2 -11
- package/dist/errors/token-invalid-error.js.map +1 -1
- package/dist/errors/token-refresh-error.js +2 -11
- package/dist/errors/token-refresh-error.js.map +1 -1
- package/dist/errors/token-revoked-error.js +2 -11
- package/dist/errors/token-revoked-error.js.map +1 -1
- package/dist/fetch-dpop.js +6 -9
- package/dist/fetch-dpop.js.map +1 -1
- package/dist/identity-resolver.js +1 -5
- package/dist/identity-resolver.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +24 -44
- package/dist/index.js.map +1 -1
- package/dist/lock.js +1 -5
- package/dist/lock.js.map +1 -1
- package/dist/oauth-authorization-server-metadata-resolver.d.ts +1 -1
- package/dist/oauth-authorization-server-metadata-resolver.d.ts.map +1 -1
- package/dist/oauth-authorization-server-metadata-resolver.js +13 -29
- package/dist/oauth-authorization-server-metadata-resolver.js.map +1 -1
- package/dist/oauth-callback-error.js +3 -17
- package/dist/oauth-callback-error.js.map +1 -1
- package/dist/oauth-client-auth.js +13 -17
- package/dist/oauth-client-auth.js.map +1 -1
- package/dist/oauth-client.js +49 -111
- package/dist/oauth-client.js.map +1 -1
- package/dist/oauth-protected-resource-metadata-resolver.d.ts +3 -3
- package/dist/oauth-protected-resource-metadata-resolver.d.ts.map +1 -1
- package/dist/oauth-protected-resource-metadata-resolver.js +16 -28
- package/dist/oauth-protected-resource-metadata-resolver.js.map +1 -1
- package/dist/oauth-resolver-error.js +3 -7
- package/dist/oauth-resolver-error.js.map +1 -1
- package/dist/oauth-resolver.d.ts +1 -1
- package/dist/oauth-resolver.d.ts.map +1 -1
- package/dist/oauth-resolver.js +18 -34
- package/dist/oauth-resolver.js.map +1 -1
- package/dist/oauth-response-error.js +6 -32
- package/dist/oauth-response-error.js.map +1 -1
- package/dist/oauth-server-agent.js +23 -79
- package/dist/oauth-server-agent.js.map +1 -1
- package/dist/oauth-server-factory.js +9 -43
- package/dist/oauth-server-factory.js.map +1 -1
- package/dist/oauth-session.js +12 -37
- package/dist/oauth-session.js.map +1 -1
- package/dist/runtime-implementation.d.ts +1 -1
- package/dist/runtime-implementation.d.ts.map +1 -1
- package/dist/runtime-implementation.js +1 -2
- package/dist/runtime-implementation.js.map +1 -1
- package/dist/runtime.js +8 -29
- package/dist/runtime.js.map +1 -1
- package/dist/session-getter.js +23 -38
- package/dist/session-getter.js.map +1 -1
- package/dist/state-store.js +1 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +6 -9
- package/dist/types.js.map +1 -1
- package/dist/util.js +3 -9
- package/dist/util.js.map +1 -1
- package/dist/validate-client-metadata.js +9 -12
- package/dist/validate-client-metadata.js.map +1 -1
- package/package.json +17 -16
- package/src/core-js.d.ts +1 -0
- package/src/index.ts +1 -1
- package/src/oauth-authorization-server-metadata-resolver.ts +2 -2
- package/src/oauth-protected-resource-metadata-resolver.ts +9 -4
- package/src/oauth-resolver.ts +5 -1
- package/src/runtime-implementation.ts +2 -2
- package/tsconfig.build.tsbuildinfo +1 -1
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,CAAC,EAAE,MAAM,KAAK,CAAA;AAC/B,OAAO,EAEL,+BAA+B,EAC/B,2BAA2B,EAC3B,yBAAyB,GAC1B,MAAM,sBAAsB,CAAA;AAyB7B,MAAM,CAAC,MAAM,oBAAoB,GAAG,yBAAyB,CAAC,MAAM,CAAC;IACnE,SAAS,EAAE,CAAC,CAAC,KAAK,CAAC;QACjB,+BAA+B;QAC/B,2BAA2B;KAC5B,CAAC;CACH,CAAC,CAAA","sourcesContent":["import { TypeOf, z } from 'zod'\nimport {\n OAuthAuthorizationRequestParameters,\n oauthClientIdDiscoverableSchema,\n oauthClientIdLoopbackSchema,\n oauthClientMetadataSchema,\n} from '@atproto/oauth-types'\nimport { Simplify } from './util.js'\n\n// Note: These types are not prefixed with `OAuth` because they are not specific\n// to OAuth. They are specific to this packages. OAuth specific types are in\n// `@atproto/oauth-types`.\n\nexport type AuthorizeOptions = Simplify<\n Omit<\n OAuthAuthorizationRequestParameters,\n | 'client_id'\n | 'response_mode'\n | 'response_type'\n | 'login_hint'\n | 'code_challenge'\n | 'code_challenge_method'\n > & {\n signal?: AbortSignal\n }\n>\n\nexport type CallbackOptions = Simplify<\n Partial<Pick<OAuthAuthorizationRequestParameters, 'redirect_uri'>>\n>\n\nexport const clientMetadataSchema = oauthClientMetadataSchema.extend({\n client_id: z.union([\n oauthClientIdDiscoverableSchema,\n oauthClientIdLoopbackSchema,\n ]),\n})\n\nexport type ClientMetadata = TypeOf<typeof clientMetadataSchema>\n"]}
|
package/dist/util.js
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.ifString = void 0;
|
|
4
|
-
exports.contentMime = contentMime;
|
|
5
|
-
exports.combineSignals = combineSignals;
|
|
6
|
-
const ifString = (v) => (typeof v === 'string' ? v : undefined);
|
|
7
|
-
exports.ifString = ifString;
|
|
8
|
-
function contentMime(headers) {
|
|
1
|
+
export const ifString = (v) => (typeof v === 'string' ? v : undefined);
|
|
2
|
+
export function contentMime(headers) {
|
|
9
3
|
return headers.get('content-type')?.split(';')[0].trim();
|
|
10
4
|
}
|
|
11
|
-
function combineSignals(signals) {
|
|
5
|
+
export function combineSignals(signals) {
|
|
12
6
|
const controller = new DisposableAbortController();
|
|
13
7
|
const onAbort = function (_event) {
|
|
14
8
|
const reason = new Error('This operation was aborted', {
|
package/dist/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAI,CAAI,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;AAE5E,MAAM,UAAU,WAAW,CAAC,OAAgB;IAC1C,OAAO,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAE,CAAC,IAAI,EAAE,CAAA;AAC3D,CAAC;AAED,MAAM,UAAU,cAAc,CAC5B,OAA6C;IAE7C,MAAM,UAAU,GAAG,IAAI,yBAAyB,EAAE,CAAA;IAElD,MAAM,OAAO,GAAG,UAA6B,MAAa;QACxD,MAAM,MAAM,GAAG,IAAI,KAAK,CAAC,4BAA4B,EAAE;YACrD,KAAK,EAAE,IAAI,CAAC,MAAM;SACnB,CAAC,CAAA;QAEF,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;IAC1B,CAAC,CAAA;IAED,IAAI,CAAC;QACH,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;YAC1B,IAAI,GAAG,EAAE,CAAC;gBACR,GAAG,CAAC,cAAc,EAAE,CAAA;gBACpB,GAAG,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,UAAU,CAAC,MAAM,EAAE,CAAC,CAAA;YACvE,CAAC;QACH,CAAC;QAED,OAAO,UAAU,CAAA;IACnB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QACrB,MAAM,GAAG,CAAA;IACX,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,yBAA0B,SAAQ,eAAe;IACrD,CAAC,MAAM,CAAC,OAAO,CAAC;QACd,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC,CAAA;IACvD,CAAC;CACF","sourcesContent":["export type Awaitable<T> = T | PromiseLike<T>\nexport type Simplify<T> = { [K in keyof T]: T[K] } & NonNullable<unknown>\n\nexport const ifString = <V>(v: V) => (typeof v === 'string' ? v : undefined)\n\nexport function contentMime(headers: Headers): string | undefined {\n return headers.get('content-type')?.split(';')[0]!.trim()\n}\n\nexport function combineSignals(\n signals: readonly (AbortSignal | undefined)[],\n): AbortController & Disposable {\n const controller = new DisposableAbortController()\n\n const onAbort = function (this: AbortSignal, _event: Event) {\n const reason = new Error('This operation was aborted', {\n cause: this.reason,\n })\n\n controller.abort(reason)\n }\n\n try {\n for (const sig of signals) {\n if (sig) {\n sig.throwIfAborted()\n sig.addEventListener('abort', onAbort, { signal: controller.signal })\n }\n }\n\n return controller\n } catch (err) {\n controller.abort(err)\n throw err\n }\n}\n\n/**\n * Allows using {@link AbortController} with the `using` keyword, in order to\n * automatically abort them once the execution block ends.\n */\nclass DisposableAbortController extends AbortController implements Disposable {\n [Symbol.dispose]() {\n this.abort(new Error('AbortController was disposed'))\n }\n}\n"]}
|
|
@@ -1,21 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const constants_js_1 = require("./constants.js");
|
|
6
|
-
const types_js_1 = require("./types.js");
|
|
7
|
-
function validateClientMetadata(input, keyset) {
|
|
1
|
+
import { assertOAuthDiscoverableClientId, assertOAuthLoopbackClientId, } from '@atproto/oauth-types';
|
|
2
|
+
import { FALLBACK_ALG } from './constants.js';
|
|
3
|
+
import { clientMetadataSchema } from './types.js';
|
|
4
|
+
export function validateClientMetadata(input, keyset) {
|
|
8
5
|
// Allow to pass a keyset and omit the jwks/jwks_uri properties
|
|
9
6
|
if (!input.jwks && !input.jwks_uri && keyset?.size) {
|
|
10
7
|
input = { ...input, jwks: keyset.toJSON() };
|
|
11
8
|
}
|
|
12
|
-
const metadata =
|
|
9
|
+
const metadata = clientMetadataSchema.parse(input);
|
|
13
10
|
// Validate client ID
|
|
14
11
|
if (metadata.client_id.startsWith('http:')) {
|
|
15
|
-
|
|
12
|
+
assertOAuthLoopbackClientId(metadata.client_id);
|
|
16
13
|
}
|
|
17
14
|
else {
|
|
18
|
-
|
|
15
|
+
assertOAuthDiscoverableClientId(metadata.client_id);
|
|
19
16
|
}
|
|
20
17
|
const scopes = metadata.scope?.split(' ');
|
|
21
18
|
if (!scopes?.includes('atproto')) {
|
|
@@ -49,8 +46,8 @@ function validateClientMetadata(input, keyset) {
|
|
|
49
46
|
if (!signingKeys.length) {
|
|
50
47
|
throw new TypeError(`Client authentication method "${method}" requires at least one active signing key with a "kid" property`);
|
|
51
48
|
}
|
|
52
|
-
if (!signingKeys.some((key) => key.algorithms.includes(
|
|
53
|
-
throw new TypeError(`Client authentication method "${method}" requires at least one active "${
|
|
49
|
+
if (!signingKeys.some((key) => key.algorithms.includes(FALLBACK_ALG))) {
|
|
50
|
+
throw new TypeError(`Client authentication method "${method}" requires at least one active "${FALLBACK_ALG}" signing key`);
|
|
54
51
|
}
|
|
55
52
|
if (metadata.jwks) {
|
|
56
53
|
// Ensure that all the signing keys that could end-up being used are
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate-client-metadata.js","sourceRoot":"","sources":["../src/validate-client-metadata.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"validate-client-metadata.js","sourceRoot":"","sources":["../src/validate-client-metadata.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,+BAA+B,EAC/B,2BAA2B,GAC5B,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,gB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,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,EAChE,CAAC;wBACD,MAAM,IAAI,SAAS,CACjB,4BAA4B,GAAG,CAAC,GAAG,gHAAgH,CACpJ,CAAA;oBACH,CAAC;gBACH,CAAC;YACH,CAAC;iBAAM,IAAI,QAAQ,CAAC,QAAQ,EAAE,CAAC;gBAC7B,wEAAwE;gBACxE,wEAAwE;gBACxE,2CAA2C;YAC7C,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,SAAS,CACjB,iCAAiC,MAAM,mBAAmB,CAC3D,CAAA;YACH,CAAC;YAED,MAAK;QACP,CAAC;QAED;YACE,MAAM,IAAI,SAAS,CACjB,mDAAmD,MAAM,EAAE,CAC5D,CAAA;IACL,CAAC;IAED,OAAO,QAAQ,CAAA;AACjB,CAAC","sourcesContent":["import { Keyset } from '@atproto/jwk'\nimport {\n OAuthClientMetadataInput,\n assertOAuthDiscoverableClientId,\n assertOAuthLoopbackClientId,\n} from '@atproto/oauth-types'\nimport { FALLBACK_ALG } from './constants.js'\nimport { ClientMetadata, clientMetadataSchema } from './types.js'\n\nexport function validateClientMetadata(\n input: OAuthClientMetadataInput,\n keyset?: Keyset,\n): ClientMetadata {\n // Allow to pass a keyset and omit the jwks/jwks_uri properties\n if (!input.jwks && !input.jwks_uri && keyset?.size) {\n input = { ...input, jwks: keyset.toJSON() }\n }\n\n const metadata = clientMetadataSchema.parse(input)\n\n // Validate client ID\n if (metadata.client_id.startsWith('http:')) {\n assertOAuthLoopbackClientId(metadata.client_id)\n } else {\n assertOAuthDiscoverableClientId(metadata.client_id)\n }\n\n const scopes = metadata.scope?.split(' ')\n if (!scopes?.includes('atproto')) {\n throw new TypeError(`Client metadata must include the \"atproto\" scope`)\n }\n\n if (!metadata.response_types.includes('code')) {\n throw new TypeError(`\"response_types\" must include \"code\"`)\n }\n\n if (!metadata.grant_types.includes('authorization_code')) {\n throw new TypeError(`\"grant_types\" must include \"authorization_code\"`)\n }\n\n const method = metadata.token_endpoint_auth_method\n const methodAlg = metadata.token_endpoint_auth_signing_alg\n switch (method) {\n case 'none':\n if (methodAlg) {\n throw new TypeError(\n `\"token_endpoint_auth_signing_alg\" must not be provided when \"token_endpoint_auth_method\" is \"${method}\"`,\n )\n }\n break\n\n case 'private_key_jwt': {\n if (!methodAlg) {\n throw new TypeError(\n `\"token_endpoint_auth_signing_alg\" must be provided when \"token_endpoint_auth_method\" is \"${method}\"`,\n )\n }\n\n if (!keyset) {\n throw new TypeError(\n `Client authentication method \"${method}\" requires a keyset`,\n )\n }\n\n // @NOTE This reproduces the logic from `negotiateClientAuthMethod` at\n // initialization time to ensure that every key that might end-up being\n // used is indeed valid & advertised in the metadata.\n const signingKeys = Array.from(keyset.list({ usage: 'sign' })).filter(\n (key) => key.kid,\n )\n\n if (!signingKeys.length) {\n throw new TypeError(\n `Client authentication method \"${method}\" requires at least one active signing key with a \"kid\" property`,\n )\n }\n\n if (!signingKeys.some((key) => key.algorithms.includes(FALLBACK_ALG))) {\n throw new TypeError(\n `Client authentication method \"${method}\" requires at least one active \"${FALLBACK_ALG}\" signing key`,\n )\n }\n\n if (metadata.jwks) {\n // Ensure that all the signing keys that could end-up being used are\n // advertised in the JWKS.\n for (const key of signingKeys) {\n if (\n !metadata.jwks.keys.some((k) => k.kid === key.kid && !k.revoked)\n ) {\n throw new TypeError(\n `Missing or inactive key \"${key.kid}\" in jwks. Make sure that every signing key of the Keyset is declared as an active key in the Metadata's JWKS.`,\n )\n }\n }\n } else if (metadata.jwks_uri) {\n // @NOTE we only ensure that all the signing keys are referenced in JWKS\n // when it is available (see previous \"if\") as we don't want to download\n // that file here (for efficiency reasons).\n } else {\n throw new TypeError(\n `Client authentication method \"${method}\" requires a JWKS`,\n )\n }\n\n break\n }\n\n default:\n throw new TypeError(\n `Unsupported \"token_endpoint_auth_method\" value: ${method}`,\n )\n }\n\n return metadata\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atproto/oauth-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0-next.0",
|
|
4
|
+
"engines": {
|
|
5
|
+
"node": ">=22"
|
|
6
|
+
},
|
|
4
7
|
"license": "MIT",
|
|
5
8
|
"description": "OAuth client for ATPROTO PDS. This package serves as common base for environment-specific implementations (NodeJS, Browser, React-Native).",
|
|
6
9
|
"keywords": [
|
|
@@ -15,9 +18,7 @@
|
|
|
15
18
|
"url": "https://github.com/bluesky-social/atproto",
|
|
16
19
|
"directory": "packages/oauth/oauth-client"
|
|
17
20
|
},
|
|
18
|
-
"type": "
|
|
19
|
-
"main": "dist/index.js",
|
|
20
|
-
"types": "dist/index.d.ts",
|
|
21
|
+
"type": "module",
|
|
21
22
|
"exports": {
|
|
22
23
|
".": {
|
|
23
24
|
"types": "./dist/index.d.ts",
|
|
@@ -26,21 +27,21 @@
|
|
|
26
27
|
},
|
|
27
28
|
"dependencies": {
|
|
28
29
|
"core-js": "^3",
|
|
29
|
-
"multiformats": "^
|
|
30
|
+
"multiformats": "^13.0.0",
|
|
30
31
|
"zod": "^3.23.8",
|
|
31
|
-
"@atproto-labs/did-resolver": "^0.
|
|
32
|
-
"@atproto-labs/
|
|
33
|
-
"@atproto-labs/
|
|
34
|
-
"@atproto-labs/
|
|
35
|
-
"@atproto-labs/
|
|
36
|
-
"@atproto-labs/simple-store-memory": "^0.
|
|
37
|
-
"@atproto/did": "^0.
|
|
38
|
-
"@atproto/
|
|
39
|
-
"@atproto/
|
|
40
|
-
"@atproto/xrpc": "^0.
|
|
32
|
+
"@atproto-labs/did-resolver": "^0.3.0-next.0",
|
|
33
|
+
"@atproto-labs/handle-resolver": "^0.4.0-next.0",
|
|
34
|
+
"@atproto-labs/simple-store": "^0.4.0-next.0",
|
|
35
|
+
"@atproto-labs/fetch": "^0.3.0-next.0",
|
|
36
|
+
"@atproto-labs/identity-resolver": "^0.4.0-next.0",
|
|
37
|
+
"@atproto-labs/simple-store-memory": "^0.2.0-next.0",
|
|
38
|
+
"@atproto/did": "^0.4.0-next.0",
|
|
39
|
+
"@atproto/oauth-types": "^0.7.0-next.0",
|
|
40
|
+
"@atproto/jwk": "^0.7.0-next.0",
|
|
41
|
+
"@atproto/xrpc": "^0.8.0-next.0"
|
|
41
42
|
},
|
|
42
43
|
"devDependencies": {
|
|
43
|
-
"typescript": "^
|
|
44
|
+
"typescript": "^6.0.3"
|
|
44
45
|
},
|
|
45
46
|
"scripts": {
|
|
46
47
|
"build": "tsc --build tsconfig.build.json"
|
package/src/core-js.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
declare module 'core-js/es/symbol/dispose.js'
|
package/src/index.ts
CHANGED
|
@@ -49,10 +49,10 @@ export class OAuthAuthorizationServerMetadataResolver extends CachedGetter<
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
async get(
|
|
52
|
-
input: string,
|
|
52
|
+
input: URL | string,
|
|
53
53
|
options?: GetCachedOptions,
|
|
54
54
|
): Promise<OAuthAuthorizationServerMetadata> {
|
|
55
|
-
const issuer = oauthIssuerIdentifierSchema.parse(input)
|
|
55
|
+
const issuer = oauthIssuerIdentifierSchema.parse(String(input))
|
|
56
56
|
if (!this.allowHttpIssuer && issuer.startsWith('http:')) {
|
|
57
57
|
throw new TypeError(
|
|
58
58
|
'Unsecure issuer URL protocol only allowed in development and test environments',
|
|
@@ -19,7 +19,7 @@ export type { GetCachedOptions, OAuthProtectedResourceMetadata }
|
|
|
19
19
|
|
|
20
20
|
export type ProtectedResourceMetadataCache = SimpleStore<
|
|
21
21
|
string,
|
|
22
|
-
OAuthProtectedResourceMetadata
|
|
22
|
+
OAuthProtectedResourceMetadata | null
|
|
23
23
|
>
|
|
24
24
|
|
|
25
25
|
export type OAuthProtectedResourceMetadataResolverConfig = {
|
|
@@ -31,7 +31,7 @@ export type OAuthProtectedResourceMetadataResolverConfig = {
|
|
|
31
31
|
*/
|
|
32
32
|
export class OAuthProtectedResourceMetadataResolver extends CachedGetter<
|
|
33
33
|
string,
|
|
34
|
-
OAuthProtectedResourceMetadata
|
|
34
|
+
OAuthProtectedResourceMetadata | null
|
|
35
35
|
> {
|
|
36
36
|
private readonly fetch: Fetch<unknown>
|
|
37
37
|
private readonly allowHttpResource: boolean
|
|
@@ -50,7 +50,7 @@ export class OAuthProtectedResourceMetadataResolver extends CachedGetter<
|
|
|
50
50
|
async get(
|
|
51
51
|
resource: string | URL,
|
|
52
52
|
options?: GetCachedOptions,
|
|
53
|
-
): Promise<OAuthProtectedResourceMetadata> {
|
|
53
|
+
): Promise<OAuthProtectedResourceMetadata | null> {
|
|
54
54
|
const { protocol, origin } = new URL(resource)
|
|
55
55
|
|
|
56
56
|
if (protocol !== 'https:' && protocol !== 'http:') {
|
|
@@ -71,7 +71,7 @@ export class OAuthProtectedResourceMetadataResolver extends CachedGetter<
|
|
|
71
71
|
private async fetchMetadata(
|
|
72
72
|
origin: string,
|
|
73
73
|
options?: GetCachedOptions,
|
|
74
|
-
): Promise<OAuthProtectedResourceMetadata> {
|
|
74
|
+
): Promise<OAuthProtectedResourceMetadata | null> {
|
|
75
75
|
const url = new URL(`/.well-known/oauth-protected-resource`, origin)
|
|
76
76
|
const request = new Request(url, {
|
|
77
77
|
signal: options?.signal,
|
|
@@ -82,6 +82,11 @@ export class OAuthProtectedResourceMetadataResolver extends CachedGetter<
|
|
|
82
82
|
|
|
83
83
|
const response = await this.fetch(request)
|
|
84
84
|
|
|
85
|
+
if (response.status === 404) {
|
|
86
|
+
await cancelBody(response, 'log')
|
|
87
|
+
return null
|
|
88
|
+
}
|
|
89
|
+
|
|
85
90
|
// https://www.rfc-editor.org/rfc/rfc9728.html#section-3.2
|
|
86
91
|
if (response.status !== 200) {
|
|
87
92
|
await cancelBody(response, 'log')
|
package/src/oauth-resolver.ts
CHANGED
|
@@ -112,7 +112,7 @@ export class OAuthResolver {
|
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
public async getAuthorizationServerMetadata(
|
|
115
|
-
issuer: string,
|
|
115
|
+
issuer: string | URL,
|
|
116
116
|
options?: GetCachedOptions,
|
|
117
117
|
): Promise<OAuthAuthorizationServerMetadata> {
|
|
118
118
|
try {
|
|
@@ -135,6 +135,10 @@ export class OAuthResolver {
|
|
|
135
135
|
options,
|
|
136
136
|
)
|
|
137
137
|
|
|
138
|
+
if (!rsMetadata) {
|
|
139
|
+
return this.getAuthorizationServerMetadata(pdsUrl, options)
|
|
140
|
+
}
|
|
141
|
+
|
|
138
142
|
// ATPROTO requires one, and only one, authorization server entry
|
|
139
143
|
if (rsMetadata.authorization_servers?.length !== 1) {
|
|
140
144
|
throw new OAuthResolverError(
|
|
@@ -8,9 +8,9 @@ export type RuntimeRandomValues = (length: number) => Awaitable<Uint8Array>
|
|
|
8
8
|
|
|
9
9
|
export type DigestAlgorithm = { name: 'sha256' | 'sha384' | 'sha512' }
|
|
10
10
|
export type RuntimeDigest = (
|
|
11
|
-
data: Uint8Array
|
|
11
|
+
data: Uint8Array<ArrayBuffer>,
|
|
12
12
|
alg: DigestAlgorithm,
|
|
13
|
-
) => Awaitable<Uint8Array
|
|
13
|
+
) => Awaitable<Uint8Array<ArrayBuffer>>
|
|
14
14
|
|
|
15
15
|
export type RuntimeLock = <T>(
|
|
16
16
|
name: string,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["./src/constants.ts","./src/fetch-dpop.ts","./src/identity-resolver.ts","./src/index.ts","./src/lock.ts","./src/oauth-authorization-server-metadata-resolver.ts","./src/oauth-callback-error.ts","./src/oauth-client-auth.ts","./src/oauth-client.ts","./src/oauth-protected-resource-metadata-resolver.ts","./src/oauth-resolver-error.ts","./src/oauth-resolver.ts","./src/oauth-response-error.ts","./src/oauth-server-agent.ts","./src/oauth-server-factory.ts","./src/oauth-session.ts","./src/runtime-implementation.ts","./src/runtime.ts","./src/session-getter.ts","./src/state-store.ts","./src/types.ts","./src/util.ts","./src/validate-client-metadata.ts","./src/errors/auth-method-unsatisfiable-error.ts","./src/errors/token-invalid-error.ts","./src/errors/token-refresh-error.ts","./src/errors/token-revoked-error.ts"],"version":"
|
|
1
|
+
{"root":["./src/constants.ts","./src/core-js.d.ts","./src/fetch-dpop.ts","./src/identity-resolver.ts","./src/index.ts","./src/lock.ts","./src/oauth-authorization-server-metadata-resolver.ts","./src/oauth-callback-error.ts","./src/oauth-client-auth.ts","./src/oauth-client.ts","./src/oauth-protected-resource-metadata-resolver.ts","./src/oauth-resolver-error.ts","./src/oauth-resolver.ts","./src/oauth-response-error.ts","./src/oauth-server-agent.ts","./src/oauth-server-factory.ts","./src/oauth-session.ts","./src/runtime-implementation.ts","./src/runtime.ts","./src/session-getter.ts","./src/state-store.ts","./src/types.ts","./src/util.ts","./src/validate-client-metadata.ts","./src/errors/auth-method-unsatisfiable-error.ts","./src/errors/token-invalid-error.ts","./src/errors/token-refresh-error.ts","./src/errors/token-revoked-error.ts"],"version":"6.0.3"}
|