@atproto/oauth-types 0.7.3 → 0.7.4

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 (59) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/util.d.ts +1 -1
  3. package/dist/util.d.ts.map +1 -1
  4. package/dist/util.js.map +1 -1
  5. package/package.json +11 -7
  6. package/src/atproto-loopback-client-id.ts +0 -78
  7. package/src/atproto-loopback-client-metadata.ts +0 -47
  8. package/src/atproto-loopback-client-redirect-uris.ts +0 -4
  9. package/src/atproto-oauth-scope.ts +0 -34
  10. package/src/atproto-oauth-token-response.ts +0 -16
  11. package/src/constants.ts +0 -2
  12. package/src/index.ts +0 -50
  13. package/src/oauth-access-token.ts +0 -4
  14. package/src/oauth-authorization-code-grant-token-request.ts +0 -19
  15. package/src/oauth-authorization-details.ts +0 -48
  16. package/src/oauth-authorization-request-jar.ts +0 -16
  17. package/src/oauth-authorization-request-par.ts +0 -12
  18. package/src/oauth-authorization-request-parameters.ts +0 -100
  19. package/src/oauth-authorization-request-query.ts +0 -21
  20. package/src/oauth-authorization-request-uri.ts +0 -10
  21. package/src/oauth-authorization-response-error.ts +0 -25
  22. package/src/oauth-authorization-server-metadata.ts +0 -120
  23. package/src/oauth-client-credentials-grant-token-request.ts +0 -9
  24. package/src/oauth-client-credentials.ts +0 -53
  25. package/src/oauth-client-id-discoverable.ts +0 -130
  26. package/src/oauth-client-id-loopback.ts +0 -164
  27. package/src/oauth-client-id.ts +0 -4
  28. package/src/oauth-client-metadata.ts +0 -80
  29. package/src/oauth-code-challenge-method.ts +0 -3
  30. package/src/oauth-endpoint-auth-method.ts +0 -13
  31. package/src/oauth-endpoint-name.ts +0 -8
  32. package/src/oauth-grant-type.ts +0 -13
  33. package/src/oauth-introspection-response.ts +0 -23
  34. package/src/oauth-issuer-identifier.ts +0 -47
  35. package/src/oauth-par-response.ts +0 -8
  36. package/src/oauth-password-grant-token-request.ts +0 -11
  37. package/src/oauth-prompt-mode.ts +0 -18
  38. package/src/oauth-protected-resource-metadata.ts +0 -94
  39. package/src/oauth-redirect-uri.ts +0 -73
  40. package/src/oauth-refresh-token-grant-token-request.ts +0 -11
  41. package/src/oauth-refresh-token.ts +0 -4
  42. package/src/oauth-request-uri.ts +0 -5
  43. package/src/oauth-response-mode.ts +0 -9
  44. package/src/oauth-response-type.ts +0 -17
  45. package/src/oauth-scope.ts +0 -21
  46. package/src/oauth-token-identification.ts +0 -12
  47. package/src/oauth-token-request.ts +0 -14
  48. package/src/oauth-token-response.ts +0 -29
  49. package/src/oauth-token-type.ts +0 -15
  50. package/src/oidc-authorization-error-response.ts +0 -29
  51. package/src/oidc-claims-parameter.ts +0 -40
  52. package/src/oidc-claims-properties.ts +0 -11
  53. package/src/oidc-entity-type.ts +0 -5
  54. package/src/oidc-userinfo.ts +0 -15
  55. package/src/uri.ts +0 -221
  56. package/src/util.ts +0 -170
  57. package/tsconfig.build.json +0 -8
  58. package/tsconfig.build.tsbuildinfo +0 -1
  59. package/tsconfig.json +0 -4
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @atproto/oauth-types
2
2
 
3
+ ## 0.7.4
4
+
5
+ ### Patch Changes
6
+
7
+ - [#5099](https://github.com/bluesky-social/atproto/pull/5099) [`b43ec31`](https://github.com/bluesky-social/atproto/commit/b43ec31f247f4461725b01226885f88bd430ca07) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Update TypeScript build to rely on references to composite internal projects
8
+
9
+ - [#5099](https://github.com/bluesky-social/atproto/pull/5099) [`b43ec31`](https://github.com/bluesky-social/atproto/commit/b43ec31f247f4461725b01226885f88bd430ca07) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Bundle only necessary files in the NPM tarball, including the `CHANGELOG.md` and `README.md` files (if present).
10
+
11
+ - [#5099](https://github.com/bluesky-social/atproto/pull/5099) [`b43ec31`](https://github.com/bluesky-social/atproto/commit/b43ec31f247f4461725b01226885f88bd430ca07) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Build with `noImplicitAny` enabled
12
+
13
+ - Updated dependencies [[`b43ec31`](https://github.com/bluesky-social/atproto/commit/b43ec31f247f4461725b01226885f88bd430ca07), [`b43ec31`](https://github.com/bluesky-social/atproto/commit/b43ec31f247f4461725b01226885f88bd430ca07), [`b43ec31`](https://github.com/bluesky-social/atproto/commit/b43ec31f247f4461725b01226885f88bd430ca07)]:
14
+ - @atproto/jwk@0.7.3
15
+ - @atproto/did@0.5.3
16
+
3
17
  ## 0.7.3
4
18
 
5
19
  ### Patch Changes
package/dist/util.d.ts CHANGED
@@ -4,7 +4,7 @@ export type LoopbackHost = 'localhost' | '127.0.0.1' | '[::1]';
4
4
  export declare function isLoopbackHost(host: unknown): host is LoopbackHost;
5
5
  export declare function isLocalHostname(hostname: string): boolean;
6
6
  export declare function safeUrl(input: URL | string): URL | null;
7
- export declare function extractUrlPath(url: any): any;
7
+ export declare function extractUrlPath(url: string): string;
8
8
  export declare const jsonObjectPreprocess: (val: unknown) => any;
9
9
  export declare const numberPreprocess: (val: unknown) => unknown;
10
10
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,qDAWpB,CAAA;AAEJ,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,WAQ5C;AAED,MAAM,MAAM,YAAY,GAAG,WAAW,GAAG,WAAW,GAAG,OAAO,CAAA;AAE9D,wBAAgB,cAAc,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,YAAY,CAElE;AAED,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAYzD;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,GAAG,GAAG,MAAM,GAAG,GAAG,GAAG,IAAI,CAMvD;AAED,wBAAgB,cAAc,CAAC,GAAG,KAAA,OAsCjC;AAED,eAAO,MAAM,oBAAoB,QAAS,OAAO,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AAM,IAAI,SAAS,CAAC,uBAAuB,CAAC,CAAA;IACpE,IAAI,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,MAAM,IAAI,SAAS,CAAC,6BAA6B,CAAC,CAAA;IAE3E,wBAAwB;IACxB,0CAA0C;IAE1C,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,CAAA;IAChC,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,CAAA;IAEhC,IAAI,WAAW,GAAG,WAAW;QAAE,OAAO,KAAK,CAAA;IAE3C,IAAI,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IAC9B,IAAI,MAAc,CAAA;IAElB,OAAO,GAAG,KAAK,CAAC,CAAC,EAAE,CAAC;QAClB,MAAM,GAAG,GAAG,GAAG,WAAW,CAAA;QAE1B;QACE,oCAAoC;QACpC,CAAC,GAAG,KAAK,CAAC,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC;YAC/C,8BAA8B;YAC9B,CAAC,MAAM,KAAK,WAAW,IAAI,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,EAC3D,CAAC;YACD,OAAO,IAAI,CAAA;QACb,CAAC;QAED,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,CAAC,CAAA;IACxC,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC,CAAA","sourcesContent":["export const canParseUrl =\n // eslint-disable-next-line n/no-unsupported-features/node-builtins\n URL.canParse?.bind(URL) ??\n // URL.canParse is not available in Node.js < 18.7.0\n ((urlStr: string): boolean => {\n try {\n new URL(urlStr)\n return true\n } catch {\n return false\n }\n })\n\nexport function isHostnameIP(hostname: string) {\n // IPv4\n if (hostname.match(/^\\d+\\.\\d+\\.\\d+\\.\\d+$/)) return true\n\n // IPv6\n if (hostname.startsWith('[') && hostname.endsWith(']')) return true\n\n return false\n}\n\nexport type LoopbackHost = 'localhost' | '127.0.0.1' | '[::1]'\n\nexport function isLoopbackHost(host: unknown): host is LoopbackHost {\n return host === 'localhost' || host === '127.0.0.1' || host === '[::1]'\n}\n\nexport function isLocalHostname(hostname: string): boolean {\n const parts = hostname.split('.')\n if (parts.length < 2) return true\n\n const tld = parts.at(-1)!.toLowerCase()\n return (\n tld === 'test' ||\n tld === 'local' ||\n tld === 'localhost' ||\n tld === 'invalid' ||\n tld === 'example'\n )\n}\n\nexport function safeUrl(input: URL | string): URL | null {\n try {\n return new URL(input)\n } catch {\n return null\n }\n}\n\nexport function extractUrlPath(url) {\n // Extracts the path from a URL, without relying on the URL constructor\n // (because it normalizes the URL)\n const endOfProtocol = url.startsWith('https://')\n ? 8\n : url.startsWith('http://')\n ? 7\n : -1\n if (endOfProtocol === -1) {\n throw new TypeError('URL must use the \"https:\" or \"http:\" protocol')\n }\n\n const hashIdx = url.indexOf('#', endOfProtocol)\n const questionIdx = url.indexOf('?', endOfProtocol)\n\n const queryStrIdx =\n questionIdx !== -1 && (hashIdx === -1 || questionIdx < hashIdx)\n ? questionIdx\n : -1\n\n const pathEnd =\n hashIdx === -1\n ? queryStrIdx === -1\n ? url.length\n : queryStrIdx\n : queryStrIdx === -1\n ? hashIdx\n : Math.min(hashIdx, queryStrIdx)\n\n const slashIdx = url.indexOf('/', endOfProtocol)\n\n const pathStart = slashIdx === -1 || slashIdx > pathEnd ? pathEnd : slashIdx\n\n if (endOfProtocol === pathStart) {\n throw new TypeError('URL must contain a host')\n }\n\n return url.substring(pathStart, pathEnd)\n}\n\nexport const jsonObjectPreprocess = (val: unknown) => {\n if (typeof val === 'string' && val.startsWith('{') && val.endsWith('}')) {\n try {\n return JSON.parse(val)\n } catch {\n return val\n }\n }\n\n return val\n}\n\nexport const numberPreprocess = (val: unknown): unknown => {\n if (typeof val === 'string') {\n const number = Number(val)\n if (!Number.isNaN(number)) return number\n }\n return val\n}\n\n/**\n * Returns true if the two arrays contain the same elements, regardless of order\n * or duplicates.\n */\nexport function arrayEquivalent<T>(a: readonly T[], b: readonly T[]) {\n if (a === b) return true\n return a.every(includedIn, b) && b.every(includedIn, a)\n}\n\nexport function includedIn<T>(this: readonly T[], item: T) {\n return this.includes(item)\n}\n\nexport function asArray<T>(\n value: Iterable<T> | undefined,\n): undefined | readonly T[] {\n if (value == null) return undefined\n if (Array.isArray(value)) return value // already a (possibly readonly) array\n return Array.from(value)\n}\n\nexport type SpaceSeparatedValue<Value extends string> =\n `${'' | `${string} `}${Value}${'' | ` ${string}`}`\n\nexport const isSpaceSeparatedValue = <Value extends string>(\n value: Value,\n input: string,\n): input is SpaceSeparatedValue<Value> => {\n if (value.length === 0) throw new TypeError('Value cannot be empty')\n if (value.includes(' ')) throw new TypeError('Value cannot contain spaces')\n\n // Optimized version of:\n // return input.split(' ').includes(value)\n\n const inputLength = input.length\n const valueLength = value.length\n\n if (inputLength < valueLength) return false\n\n let idx = input.indexOf(value)\n let idxEnd: number\n\n while (idx !== -1) {\n idxEnd = idx + valueLength\n\n if (\n // at beginning or preceded by space\n (idx === 0 || input.charCodeAt(idx - 1) === 32) &&\n // at end or followed by space\n (idxEnd === inputLength || input.charCodeAt(idxEnd) === 32)\n ) {\n return true\n }\n\n idx = input.indexOf(value, idxEnd + 1)\n }\n\n return false\n}\n"]}
1
+ {"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW;AACtB,mEAAmE;AACnE,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,GAAG,CAAC;IACvB,oDAAoD;IACpD,CAAC,CAAC,MAAc,EAAW,EAAE;QAC3B,IAAI,CAAC;YACH,IAAI,GAAG,CAAC,MAAM,CAAC,CAAA;YACf,OAAO,IAAI,CAAA;QACb,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAA;QACd,CAAC;IACH,CAAC,CAAC,CAAA;AAEJ,MAAM,UAAU,YAAY,CAAC,QAA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,KAAa,EACwB,EAAE;IACvC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,MAAM,IAAI,SAAS,CAAC,uBAAuB,CAAC,CAAA;IACpE,IAAI,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,MAAM,IAAI,SAAS,CAAC,6BAA6B,CAAC,CAAA;IAE3E,wBAAwB;IACxB,0CAA0C;IAE1C,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,CAAA;IAChC,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,CAAA;IAEhC,IAAI,WAAW,GAAG,WAAW;QAAE,OAAO,KAAK,CAAA;IAE3C,IAAI,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IAC9B,IAAI,MAAc,CAAA;IAElB,OAAO,GAAG,KAAK,CAAC,CAAC,EAAE,CAAC;QAClB,MAAM,GAAG,GAAG,GAAG,WAAW,CAAA;QAE1B;QACE,oCAAoC;QACpC,CAAC,GAAG,KAAK,CAAC,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC;YAC/C,8BAA8B;YAC9B,CAAC,MAAM,KAAK,WAAW,IAAI,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,EAC3D,CAAC;YACD,OAAO,IAAI,CAAA;QACb,CAAC;QAED,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,CAAC,CAAA;IACxC,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC,CAAA","sourcesContent":["export const canParseUrl =\n // eslint-disable-next-line n/no-unsupported-features/node-builtins\n URL.canParse?.bind(URL) ??\n // URL.canParse is not available in Node.js < 18.7.0\n ((urlStr: string): boolean => {\n try {\n new URL(urlStr)\n return true\n } catch {\n return false\n }\n })\n\nexport function isHostnameIP(hostname: string) {\n // IPv4\n if (hostname.match(/^\\d+\\.\\d+\\.\\d+\\.\\d+$/)) return true\n\n // IPv6\n if (hostname.startsWith('[') && hostname.endsWith(']')) return true\n\n return false\n}\n\nexport type LoopbackHost = 'localhost' | '127.0.0.1' | '[::1]'\n\nexport function isLoopbackHost(host: unknown): host is LoopbackHost {\n return host === 'localhost' || host === '127.0.0.1' || host === '[::1]'\n}\n\nexport function isLocalHostname(hostname: string): boolean {\n const parts = hostname.split('.')\n if (parts.length < 2) return true\n\n const tld = parts.at(-1)!.toLowerCase()\n return (\n tld === 'test' ||\n tld === 'local' ||\n tld === 'localhost' ||\n tld === 'invalid' ||\n tld === 'example'\n )\n}\n\nexport function safeUrl(input: URL | string): URL | null {\n try {\n return new URL(input)\n } catch {\n return null\n }\n}\n\nexport function extractUrlPath(url: string) {\n // Extracts the path from a URL, without relying on the URL constructor\n // (because it normalizes the URL)\n const endOfProtocol = url.startsWith('https://')\n ? 8\n : url.startsWith('http://')\n ? 7\n : -1\n if (endOfProtocol === -1) {\n throw new TypeError('URL must use the \"https:\" or \"http:\" protocol')\n }\n\n const hashIdx = url.indexOf('#', endOfProtocol)\n const questionIdx = url.indexOf('?', endOfProtocol)\n\n const queryStrIdx =\n questionIdx !== -1 && (hashIdx === -1 || questionIdx < hashIdx)\n ? questionIdx\n : -1\n\n const pathEnd =\n hashIdx === -1\n ? queryStrIdx === -1\n ? url.length\n : queryStrIdx\n : queryStrIdx === -1\n ? hashIdx\n : Math.min(hashIdx, queryStrIdx)\n\n const slashIdx = url.indexOf('/', endOfProtocol)\n\n const pathStart = slashIdx === -1 || slashIdx > pathEnd ? pathEnd : slashIdx\n\n if (endOfProtocol === pathStart) {\n throw new TypeError('URL must contain a host')\n }\n\n return url.substring(pathStart, pathEnd)\n}\n\nexport const jsonObjectPreprocess = (val: unknown) => {\n if (typeof val === 'string' && val.startsWith('{') && val.endsWith('}')) {\n try {\n return JSON.parse(val)\n } catch {\n return val\n }\n }\n\n return val\n}\n\nexport const numberPreprocess = (val: unknown): unknown => {\n if (typeof val === 'string') {\n const number = Number(val)\n if (!Number.isNaN(number)) return number\n }\n return val\n}\n\n/**\n * Returns true if the two arrays contain the same elements, regardless of order\n * or duplicates.\n */\nexport function arrayEquivalent<T>(a: readonly T[], b: readonly T[]) {\n if (a === b) return true\n return a.every(includedIn, b) && b.every(includedIn, a)\n}\n\nexport function includedIn<T>(this: readonly T[], item: T) {\n return this.includes(item)\n}\n\nexport function asArray<T>(\n value: Iterable<T> | undefined,\n): undefined | readonly T[] {\n if (value == null) return undefined\n if (Array.isArray(value)) return value // already a (possibly readonly) array\n return Array.from(value)\n}\n\nexport type SpaceSeparatedValue<Value extends string> =\n `${'' | `${string} `}${Value}${'' | ` ${string}`}`\n\nexport const isSpaceSeparatedValue = <Value extends string>(\n value: Value,\n input: string,\n): input is SpaceSeparatedValue<Value> => {\n if (value.length === 0) throw new TypeError('Value cannot be empty')\n if (value.includes(' ')) throw new TypeError('Value cannot contain spaces')\n\n // Optimized version of:\n // return input.split(' ').includes(value)\n\n const inputLength = input.length\n const valueLength = value.length\n\n if (inputLength < valueLength) return false\n\n let idx = input.indexOf(value)\n let idxEnd: number\n\n while (idx !== -1) {\n idxEnd = idx + valueLength\n\n if (\n // at beginning or preceded by space\n (idx === 0 || input.charCodeAt(idx - 1) === 32) &&\n // at end or followed by space\n (idxEnd === inputLength || input.charCodeAt(idxEnd) === 32)\n ) {\n return true\n }\n\n idx = input.indexOf(value, idxEnd + 1)\n }\n\n return false\n}\n"]}
package/package.json CHANGED
@@ -1,9 +1,6 @@
1
1
  {
2
2
  "name": "@atproto/oauth-types",
3
- "version": "0.7.3",
4
- "engines": {
5
- "node": ">=22"
6
- },
3
+ "version": "0.7.4",
7
4
  "license": "MIT",
8
5
  "description": "OAuth typing & validation library",
9
6
  "keywords": [
@@ -18,6 +15,11 @@
18
15
  "url": "https://github.com/bluesky-social/atproto",
19
16
  "directory": "packages/oauth/oauth-types"
20
17
  },
18
+ "files": [
19
+ "./dist",
20
+ "./README.md",
21
+ "./CHANGELOG.md"
22
+ ],
21
23
  "type": "module",
22
24
  "exports": {
23
25
  ".": {
@@ -25,12 +27,14 @@
25
27
  "default": "./dist/index.js"
26
28
  }
27
29
  },
30
+ "engines": {
31
+ "node": ">=22"
32
+ },
28
33
  "dependencies": {
29
34
  "zod": "^3.23.8",
30
- "@atproto/did": "^0.5.2",
31
- "@atproto/jwk": "^0.7.2"
35
+ "@atproto/did": "^0.5.3",
36
+ "@atproto/jwk": "^0.7.3"
32
37
  },
33
- "devDependencies": {},
34
38
  "scripts": {
35
39
  "build": "tsgo --build tsconfig.build.json"
36
40
  }
@@ -1,78 +0,0 @@
1
- import { DEFAULT_LOOPBACK_CLIENT_REDIRECT_URIS } from './atproto-loopback-client-redirect-uris.js'
2
- import {
3
- AtprotoOAuthScope,
4
- DEFAULT_ATPROTO_OAUTH_SCOPE,
5
- asAtprotoOAuthScope,
6
- isAtprotoOAuthScope,
7
- } from './atproto-oauth-scope.js'
8
- import {
9
- LOOPBACK_CLIENT_ID_ORIGIN,
10
- OAuthClientIdLoopback,
11
- parseOAuthLoopbackClientId,
12
- } from './oauth-client-id-loopback.js'
13
- import {
14
- OAuthLoopbackRedirectURI,
15
- oauthLoopbackClientRedirectUriSchema,
16
- } from './oauth-redirect-uri.js'
17
- import { arrayEquivalent, asArray } from './util.js'
18
-
19
- export type OAuthLoopbackClientIdConfig = {
20
- scope?: string
21
- redirect_uris?: Iterable<string>
22
- }
23
-
24
- export function buildAtprotoLoopbackClientId(
25
- config?: OAuthLoopbackClientIdConfig,
26
- ): OAuthClientIdLoopback {
27
- if (config) {
28
- const params = new URLSearchParams()
29
-
30
- const { scope } = config
31
- if (scope != null && scope !== DEFAULT_ATPROTO_OAUTH_SCOPE) {
32
- params.set('scope', asAtprotoOAuthScope(scope))
33
- }
34
-
35
- const redirectUris = asArray(config.redirect_uris)
36
- if (
37
- redirectUris &&
38
- !arrayEquivalent(redirectUris, DEFAULT_LOOPBACK_CLIENT_REDIRECT_URIS)
39
- ) {
40
- if (!redirectUris.length) {
41
- throw new TypeError(`Unexpected empty "redirect_uris" config`)
42
- }
43
- for (const uri of redirectUris) {
44
- params.append(
45
- 'redirect_uri',
46
- oauthLoopbackClientRedirectUriSchema.parse(uri),
47
- )
48
- }
49
- }
50
-
51
- if (params.size) {
52
- return `${LOOPBACK_CLIENT_ID_ORIGIN}?${params.toString()}`
53
- }
54
- }
55
-
56
- return LOOPBACK_CLIENT_ID_ORIGIN
57
- }
58
-
59
- export type AtprotoLoopbackClientIdParams = {
60
- scope: AtprotoOAuthScope
61
- redirect_uris: [OAuthLoopbackRedirectURI, ...OAuthLoopbackRedirectURI[]]
62
- }
63
-
64
- export function parseAtprotoLoopbackClientId(
65
- clientId: string,
66
- ): AtprotoLoopbackClientIdParams {
67
- const { scope = DEFAULT_ATPROTO_OAUTH_SCOPE, redirect_uris } =
68
- parseOAuthLoopbackClientId(clientId)
69
- if (!isAtprotoOAuthScope(scope)) {
70
- throw new TypeError(
71
- 'ATProto Loopback ClientID must include "atproto" scope',
72
- )
73
- }
74
- return {
75
- scope,
76
- redirect_uris: redirect_uris ?? [...DEFAULT_LOOPBACK_CLIENT_REDIRECT_URIS],
77
- }
78
- }
@@ -1,47 +0,0 @@
1
- import {
2
- AtprotoLoopbackClientIdParams,
3
- OAuthLoopbackClientIdConfig,
4
- buildAtprotoLoopbackClientId,
5
- parseAtprotoLoopbackClientId,
6
- } from './atproto-loopback-client-id.js'
7
- import { AtprotoOAuthScope } from './atproto-oauth-scope.js'
8
- import { OAuthClientIdLoopback } from './oauth-client-id-loopback.js'
9
- import { OAuthClientMetadataInput } from './oauth-client-metadata.js'
10
- import { OAuthLoopbackRedirectURI } from './oauth-redirect-uri.js'
11
-
12
- export type AtprotoLoopbackClientMetadata = OAuthClientMetadataInput & {
13
- client_id: OAuthClientIdLoopback
14
- scope: AtprotoOAuthScope
15
- redirect_uris: [OAuthLoopbackRedirectURI, ...OAuthLoopbackRedirectURI[]]
16
- }
17
-
18
- export function atprotoLoopbackClientMetadata(
19
- clientId: string,
20
- ): AtprotoLoopbackClientMetadata {
21
- const params = parseAtprotoLoopbackClientId(clientId)
22
- // Safe to cast because parseAtprotoLoopbackClientId ensures it's a loopback ID
23
- return buildMetadataInternal(clientId as OAuthClientIdLoopback, params)
24
- }
25
-
26
- export function buildAtprotoLoopbackClientMetadata(
27
- config: OAuthLoopbackClientIdConfig,
28
- ): AtprotoLoopbackClientMetadata {
29
- const clientId = buildAtprotoLoopbackClientId(config)
30
- return buildMetadataInternal(clientId, parseAtprotoLoopbackClientId(clientId))
31
- }
32
-
33
- function buildMetadataInternal(
34
- clientId: OAuthClientIdLoopback,
35
- clientParams: AtprotoLoopbackClientIdParams,
36
- ): AtprotoLoopbackClientMetadata {
37
- return {
38
- client_id: clientId,
39
- scope: clientParams.scope,
40
- redirect_uris: clientParams.redirect_uris,
41
- response_types: ['code'],
42
- grant_types: ['authorization_code', 'refresh_token'],
43
- token_endpoint_auth_method: 'none',
44
- application_type: 'native',
45
- dpop_bound_access_tokens: true,
46
- }
47
- }
@@ -1,4 +0,0 @@
1
- export const DEFAULT_LOOPBACK_CLIENT_REDIRECT_URIS = Object.freeze([
2
- `http://127.0.0.1/`,
3
- `http://[::1]/`,
4
- ] as const)
@@ -1,34 +0,0 @@
1
- import { z } from 'zod'
2
- import { OAuthScope, isOAuthScope } from './oauth-scope.js'
3
- import { SpaceSeparatedValue, isSpaceSeparatedValue } from './util.js'
4
-
5
- export const ATPROTO_SCOPE_VALUE = 'atproto'
6
- export type AtprotoScopeValue = typeof ATPROTO_SCOPE_VALUE
7
-
8
- export type AtprotoOAuthScope = OAuthScope &
9
- SpaceSeparatedValue<AtprotoScopeValue>
10
-
11
- export function isAtprotoOAuthScope(input: string): input is AtprotoOAuthScope {
12
- return (
13
- isOAuthScope(input) && isSpaceSeparatedValue(ATPROTO_SCOPE_VALUE, input)
14
- )
15
- }
16
-
17
- export function asAtprotoOAuthScope<I extends string>(input: I) {
18
- if (isAtprotoOAuthScope(input)) return input
19
- throw new TypeError(`Value must contain "${ATPROTO_SCOPE_VALUE}" scope value`)
20
- }
21
-
22
- export function assertAtprotoOAuthScope(
23
- input: string,
24
- ): asserts input is AtprotoOAuthScope {
25
- void asAtprotoOAuthScope(input)
26
- }
27
-
28
- export const atprotoOAuthScopeSchema = z.string().refine(isAtprotoOAuthScope, {
29
- message: 'Invalid ATProto OAuth scope',
30
- })
31
-
32
- // Default scope is for reading identity (did) only
33
- export const DEFAULT_ATPROTO_OAUTH_SCOPE =
34
- ATPROTO_SCOPE_VALUE satisfies AtprotoOAuthScope
@@ -1,16 +0,0 @@
1
- import { TypeOf, z } from 'zod'
2
- import { atprotoDidSchema } from '@atproto/did'
3
- import { atprotoOAuthScopeSchema } from './atproto-oauth-scope.js'
4
- import { oauthTokenResponseSchema } from './oauth-token-response.js'
5
-
6
- export const atprotoOAuthTokenResponseSchema = oauthTokenResponseSchema.extend({
7
- token_type: z.literal('DPoP'),
8
- sub: atprotoDidSchema,
9
- scope: atprotoOAuthScopeSchema,
10
- // OpenID is not compatible with atproto identities
11
- id_token: z.never().optional(),
12
- })
13
-
14
- export type AtprotoOAuthTokenResponse = TypeOf<
15
- typeof atprotoOAuthTokenResponseSchema
16
- >
package/src/constants.ts DELETED
@@ -1,2 +0,0 @@
1
- export const CLIENT_ASSERTION_TYPE_JWT_BEARER =
2
- 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer'
package/src/index.ts DELETED
@@ -1,50 +0,0 @@
1
- export * from './constants.js'
2
- export * from './uri.js'
3
- export * from './util.js'
4
-
5
- export * from './atproto-loopback-client-id.js'
6
- export * from './atproto-loopback-client-metadata.js'
7
- export * from './atproto-loopback-client-redirect-uris.js'
8
- export * from './atproto-oauth-scope.js'
9
- export * from './atproto-oauth-token-response.js'
10
- export * from './oauth-access-token.js'
11
- export * from './oauth-authorization-code-grant-token-request.js'
12
- export * from './oauth-authorization-details.js'
13
- export * from './oauth-authorization-request-jar.js'
14
- export * from './oauth-authorization-request-par.js'
15
- export * from './oauth-authorization-request-parameters.js'
16
- export * from './oauth-authorization-request-query.js'
17
- export * from './oauth-authorization-request-uri.js'
18
- export * from './oauth-authorization-response-error.js'
19
- export * from './oauth-authorization-server-metadata.js'
20
- export * from './oauth-client-credentials-grant-token-request.js'
21
- export * from './oauth-client-credentials.js'
22
- export * from './oauth-client-id-discoverable.js'
23
- export * from './oauth-client-id-loopback.js'
24
- export * from './oauth-client-id.js'
25
- export * from './oauth-client-metadata.js'
26
- export * from './oauth-endpoint-auth-method.js'
27
- export * from './oauth-endpoint-name.js'
28
- export * from './oauth-grant-type.js'
29
- export * from './oauth-introspection-response.js'
30
- export * from './oauth-issuer-identifier.js'
31
- export * from './oauth-par-response.js'
32
- export * from './oauth-password-grant-token-request.js'
33
- export * from './oauth-prompt-mode.js'
34
- export * from './oauth-protected-resource-metadata.js'
35
- export * from './oauth-redirect-uri.js'
36
- export * from './oauth-refresh-token-grant-token-request.js'
37
- export * from './oauth-refresh-token.js'
38
- export * from './oauth-request-uri.js'
39
- export * from './oauth-response-mode.js'
40
- export * from './oauth-response-type.js'
41
- export * from './oauth-scope.js'
42
- export * from './oauth-token-identification.js'
43
- export * from './oauth-token-request.js'
44
- export * from './oauth-token-response.js'
45
- export * from './oauth-token-type.js'
46
- export * from './oidc-authorization-error-response.js'
47
- export * from './oidc-claims-parameter.js'
48
- export * from './oidc-claims-properties.js'
49
- export * from './oidc-entity-type.js'
50
- export * from './oidc-userinfo.js'
@@ -1,4 +0,0 @@
1
- import { z } from 'zod'
2
-
3
- export const oauthAccessTokenSchema = z.string().min(1)
4
- export type OAuthAccessToken = z.infer<typeof oauthAccessTokenSchema>
@@ -1,19 +0,0 @@
1
- import { z } from 'zod'
2
- import { oauthRedirectUriSchema } from './oauth-redirect-uri.js'
3
-
4
- export const oauthAuthorizationCodeGrantTokenRequestSchema = z.object({
5
- grant_type: z.literal('authorization_code'),
6
- code: z.string().min(1),
7
- redirect_uri: oauthRedirectUriSchema,
8
- /** @see {@link https://datatracker.ietf.org/doc/html/rfc7636#section-4.1} */
9
- code_verifier: z
10
- .string()
11
- .min(43)
12
- .max(128)
13
- .regex(/^[a-zA-Z0-9-._~]+$/)
14
- .optional(),
15
- })
16
-
17
- export type OAuthAuthorizationCodeGrantTokenRequest = z.infer<
18
- typeof oauthAuthorizationCodeGrantTokenRequestSchema
19
- >
@@ -1,48 +0,0 @@
1
- import { z } from 'zod'
2
- import { dangerousUriSchema } from './uri.js'
3
-
4
- /**
5
- * @see {@link https://datatracker.ietf.org/doc/html/rfc9396#section-2 | RFC 9396, Section 2}
6
- */
7
- export const oauthAuthorizationDetailSchema = z.object({
8
- type: z.string(),
9
- /**
10
- * An array of strings representing the location of the resource or RS. These
11
- * strings are typically URIs identifying the location of the RS.
12
- */
13
- locations: z.array(dangerousUriSchema).optional(),
14
- /**
15
- * An array of strings representing the kinds of actions to be taken at the
16
- * resource.
17
- */
18
- actions: z.array(z.string()).optional(),
19
- /**
20
- * An array of strings representing the kinds of data being requested from the
21
- * resource.
22
- */
23
- datatypes: z.array(z.string()).optional(),
24
- /**
25
- * A string identifier indicating a specific resource available at the API.
26
- */
27
- identifier: z.string().optional(),
28
- /**
29
- * An array of strings representing the types or levels of privilege being
30
- * requested at the resource.
31
- */
32
- privileges: z.array(z.string()).optional(),
33
- })
34
-
35
- export type OAuthAuthorizationDetail = z.infer<
36
- typeof oauthAuthorizationDetailSchema
37
- >
38
-
39
- /**
40
- * @see {@link https://datatracker.ietf.org/doc/html/rfc9396#section-2 | RFC 9396, Section 2}
41
- */
42
- export const oauthAuthorizationDetailsSchema = z.array(
43
- oauthAuthorizationDetailSchema,
44
- )
45
-
46
- export type OAuthAuthorizationDetails = z.infer<
47
- typeof oauthAuthorizationDetailsSchema
48
- >
@@ -1,16 +0,0 @@
1
- import { z } from 'zod'
2
- import { signedJwtSchema, unsignedJwtSchema } from '@atproto/jwk'
3
-
4
- export const oauthAuthorizationRequestJarSchema = z.object({
5
- /**
6
- * AuthorizationRequest inside a JWT:
7
- * - "iat" is required and **MUST** be less than one minute
8
- *
9
- * @see {@link https://datatracker.ietf.org/doc/html/rfc9101}
10
- */
11
- request: z.union([signedJwtSchema, unsignedJwtSchema]),
12
- })
13
-
14
- export type OAuthAuthorizationRequestJar = z.infer<
15
- typeof oauthAuthorizationRequestJarSchema
16
- >
@@ -1,12 +0,0 @@
1
- import { z } from 'zod'
2
- import { oauthAuthorizationRequestJarSchema } from './oauth-authorization-request-jar.js'
3
- import { oauthAuthorizationRequestParametersSchema } from './oauth-authorization-request-parameters.js'
4
-
5
- export const oauthAuthorizationRequestParSchema = z.union([
6
- oauthAuthorizationRequestParametersSchema,
7
- oauthAuthorizationRequestJarSchema,
8
- ])
9
-
10
- export type OAuthAuthorizationRequestPar = z.infer<
11
- typeof oauthAuthorizationRequestParSchema
12
- >
@@ -1,100 +0,0 @@
1
- import { z } from 'zod'
2
- import { signedJwtSchema } from '@atproto/jwk'
3
- import { oauthAuthorizationDetailsSchema } from './oauth-authorization-details.js'
4
- import { oauthClientIdSchema } from './oauth-client-id.js'
5
- import { oauthCodeChallengeMethodSchema } from './oauth-code-challenge-method.js'
6
- import { oauthPromptModeSchema } from './oauth-prompt-mode.js'
7
- import { oauthRedirectUriSchema } from './oauth-redirect-uri.js'
8
- import { oauthResponseModeSchema } from './oauth-response-mode.js'
9
- import { oauthResponseTypeSchema } from './oauth-response-type.js'
10
- import { oauthScopeSchema } from './oauth-scope.js'
11
- import { oidcClaimsParameterSchema } from './oidc-claims-parameter.js'
12
- import { oidcClaimsPropertiesSchema } from './oidc-claims-properties.js'
13
- import { oidcEntityTypeSchema } from './oidc-entity-type.js'
14
- import { jsonObjectPreprocess, numberPreprocess } from './util.js'
15
-
16
- /**
17
- * @note non string parameters will be converted from their string
18
- * representation since oauth request parameters are typically sent as URL
19
- * encoded form data or URL encoded query string.
20
- * @see {@link https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest | OIDC}
21
- */
22
- export const oauthAuthorizationRequestParametersSchema = z.object({
23
- client_id: oauthClientIdSchema,
24
- state: z.string().optional(),
25
- redirect_uri: oauthRedirectUriSchema.optional(),
26
- scope: oauthScopeSchema.optional(),
27
- response_type: oauthResponseTypeSchema,
28
-
29
- // PKCE
30
-
31
- // https://datatracker.ietf.org/doc/html/rfc7636#section-4.3
32
- code_challenge: z.string().optional(),
33
- code_challenge_method: oauthCodeChallengeMethodSchema.optional(),
34
-
35
- // DPOP
36
-
37
- // https://datatracker.ietf.org/doc/html/rfc9449#section-12.3
38
- dpop_jkt: z.string().optional(),
39
-
40
- // OIDC
41
-
42
- // Default depend on response_type
43
- response_mode: oauthResponseModeSchema.optional(),
44
-
45
- nonce: z.string().optional(),
46
-
47
- // Specifies the allowable elapsed time in seconds since the last time the
48
- // End-User was actively authenticated by the OP. If the elapsed time is
49
- // greater than this value, the OP MUST attempt to actively re-authenticate
50
- // the End-User. (The max_age request parameter corresponds to the OpenID 2.0
51
- // PAPE [OpenID.PAPE] max_auth_age request parameter.) When max_age is used,
52
- // the ID Token returned MUST include an auth_time Claim Value. Note that
53
- // max_age=0 is equivalent to prompt=login.
54
- max_age: z.preprocess(numberPreprocess, z.number().int().min(0)).optional(),
55
-
56
- claims: z
57
- .preprocess(
58
- jsonObjectPreprocess,
59
- z.record(
60
- oidcEntityTypeSchema,
61
- z.record(
62
- oidcClaimsParameterSchema,
63
- z.union([z.literal(null), oidcClaimsPropertiesSchema]),
64
- ),
65
- ),
66
- )
67
- .optional(),
68
-
69
- // https://openid.net/specs/openid-connect-core-1_0.html#RegistrationParameter
70
- // Not supported by this library (yet?)
71
- // registration: clientMetadataSchema.optional(),
72
-
73
- login_hint: z.string().min(1).optional(),
74
-
75
- ui_locales: z
76
- .string()
77
- .regex(/^[a-z]{2,3}(-[A-Z]{2})?( [a-z]{2,3}(-[A-Z]{2})?)*$/) // fr-CA fr en
78
- .optional(),
79
-
80
- // Previous ID Token, should be provided when prompt=none is used
81
- id_token_hint: signedJwtSchema.optional(),
82
-
83
- // Type of UI the AS is displayed on
84
- display: z.enum(['page', 'popup', 'touch', 'wap']).optional(),
85
-
86
- // How the AS should prompt the user for authorization:
87
- prompt: oauthPromptModeSchema.optional(),
88
-
89
- // https://datatracker.ietf.org/doc/html/rfc9396
90
- authorization_details: z
91
- .preprocess(jsonObjectPreprocess, oauthAuthorizationDetailsSchema)
92
- .optional(),
93
- })
94
-
95
- /**
96
- * @see {oauthAuthorizationRequestParametersSchema}
97
- */
98
- export type OAuthAuthorizationRequestParameters = z.infer<
99
- typeof oauthAuthorizationRequestParametersSchema
100
- >
@@ -1,21 +0,0 @@
1
- import { z } from 'zod'
2
- import { oauthAuthorizationRequestJarSchema } from './oauth-authorization-request-jar.js'
3
- import { oauthAuthorizationRequestParametersSchema } from './oauth-authorization-request-parameters.js'
4
- import { oauthAuthorizationRequestUriSchema } from './oauth-authorization-request-uri.js'
5
- import { oauthClientIdSchema } from './oauth-client-id.js'
6
-
7
- export const oauthAuthorizationRequestQuerySchema = z.intersection(
8
- z.object({
9
- // REQUIRED. OAuth 2.0 [RFC6749] client_id.
10
- client_id: oauthClientIdSchema,
11
- }),
12
- z.union([
13
- oauthAuthorizationRequestParametersSchema,
14
- oauthAuthorizationRequestJarSchema,
15
- oauthAuthorizationRequestUriSchema,
16
- ]),
17
- )
18
-
19
- export type OAuthAuthorizationRequestQuery = z.infer<
20
- typeof oauthAuthorizationRequestQuerySchema
21
- >
@@ -1,10 +0,0 @@
1
- import { z } from 'zod'
2
- import { oauthRequestUriSchema } from './oauth-request-uri.js'
3
-
4
- export const oauthAuthorizationRequestUriSchema = z.object({
5
- request_uri: oauthRequestUriSchema,
6
- })
7
-
8
- export type OAuthAuthorizationRequestUri = z.infer<
9
- typeof oauthAuthorizationRequestUriSchema
10
- >
@@ -1,25 +0,0 @@
1
- import { z } from 'zod'
2
-
3
- /**
4
- * @see {@link https://datatracker.ietf.org/doc/html/draft-ietf-oauth-v2-1-12#name-error-response-2}
5
- */
6
- export const oauthAuthorizationResponseErrorSchema = z.enum([
7
- // The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed.
8
- 'invalid_request',
9
- // The client is not authorized to request an authorization code using this method.
10
- 'unauthorized_client',
11
- // The resource owner or authorization server denied the request.
12
- 'access_denied',
13
- // The authorization server does not support obtaining an authorization code using this method.
14
- 'unsupported_response_type',
15
- // The requested scope is invalid, unknown, or malformed.
16
- 'invalid_scope',
17
- // The authorization server encountered an unexpected condition that prevented it from fulfilling the request. (This error code is needed because a 500 Internal Server Error HTTP status code cannot be returned to the client via an HTTP redirect.)
18
- 'server_error',
19
- // The authorization server is currently unable to handle the request due to a temporary overloading or maintenance of the server. (This error code is needed because a 503 Service Unavailable HTTP status code cannot be returned to the client via an HTTP redirect.)
20
- 'temporarily_unavailable',
21
- ])
22
-
23
- export type OAuthAuthorizationResponseError = z.infer<
24
- typeof oauthAuthorizationResponseErrorSchema
25
- >