@atproto/oauth-client 0.6.1 → 0.7.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 +28 -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.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.js +13 -29
- 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.js +15 -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/runtime-implementation.ts +2 -2
- package/tsconfig.build.tsbuildinfo +1 -1
|
@@ -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,gBAAgB,CAAA;AAC7C,OAAO,EAAkB,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAEjE,MAAM,UAAU,sBAAsB,CACpC,KAA+B,EAC/B,MAAe;IAEf,+DAA+D;IAC/D,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ,IAAI,MAAM,EAAE,IAAI,EAAE,CAAC;QACnD,KAAK,GAAG,EAAE,GAAG,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,EAAE,CAAA;IAC7C,CA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AAM,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",
|
|
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/fetch": "^0.
|
|
33
|
-
"@atproto-labs/handle-resolver": "^0.
|
|
34
|
-
"@atproto-labs/identity-resolver": "^0.
|
|
35
|
-
"@atproto-labs/simple-store": "^0.
|
|
36
|
-
"@atproto
|
|
37
|
-
"@atproto/
|
|
38
|
-
"@atproto/
|
|
39
|
-
"@atproto/
|
|
40
|
-
"@atproto/
|
|
32
|
+
"@atproto-labs/did-resolver": "^0.3.0",
|
|
33
|
+
"@atproto-labs/fetch": "^0.3.0",
|
|
34
|
+
"@atproto-labs/handle-resolver": "^0.4.0",
|
|
35
|
+
"@atproto-labs/identity-resolver": "^0.4.0",
|
|
36
|
+
"@atproto-labs/simple-store": "^0.4.0",
|
|
37
|
+
"@atproto/jwk": "^0.7.0",
|
|
38
|
+
"@atproto/oauth-types": "^0.7.0",
|
|
39
|
+
"@atproto-labs/simple-store-memory": "^0.2.0",
|
|
40
|
+
"@atproto/xrpc": "^0.8.0",
|
|
41
|
+
"@atproto/did": "^0.4.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
|
@@ -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"}
|