@schemavaults/auth-common 0.39.1 → 0.41.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.
Files changed (49) hide show
  1. package/dist/api-scopes/api-server-scope.d.ts +1 -0
  2. package/dist/api-scopes/api-server-scope.js +7 -3
  3. package/dist/api-scopes/api-server-scope.js.map +1 -1
  4. package/dist/index.d.ts +2 -0
  5. package/dist/index.js +1 -0
  6. package/dist/index.js.map +1 -1
  7. package/dist/oidc/device-authorization/constants.d.ts +43 -0
  8. package/dist/oidc/device-authorization/constants.js +57 -0
  9. package/dist/oidc/device-authorization/constants.js.map +1 -0
  10. package/dist/oidc/device-authorization/device-authorization-response.d.ts +29 -0
  11. package/dist/oidc/device-authorization/device-authorization-response.js +35 -0
  12. package/dist/oidc/device-authorization/device-authorization-response.js.map +1 -0
  13. package/dist/oidc/device-authorization/index.d.ts +7 -0
  14. package/dist/oidc/device-authorization/index.js +5 -0
  15. package/dist/oidc/device-authorization/index.js.map +1 -0
  16. package/dist/oidc/device-authorization/user-code.d.ts +31 -0
  17. package/dist/oidc/device-authorization/user-code.js +73 -0
  18. package/dist/oidc/device-authorization/user-code.js.map +1 -0
  19. package/dist/oidc/device-authorization/verification-uri.d.ts +10 -0
  20. package/dist/oidc/device-authorization/verification-uri.js +25 -0
  21. package/dist/oidc/device-authorization/verification-uri.js.map +1 -0
  22. package/dist/oidc/endpoints.d.ts +1 -0
  23. package/dist/oidc/endpoints.js +2 -0
  24. package/dist/oidc/endpoints.js.map +1 -1
  25. package/dist/oidc/index.d.ts +3 -1
  26. package/dist/oidc/index.js +1 -0
  27. package/dist/oidc/index.js.map +1 -1
  28. package/dist/oidc/provider-metadata.d.ts +5 -0
  29. package/dist/oidc/provider-metadata.js +6 -1
  30. package/dist/oidc/provider-metadata.js.map +1 -1
  31. package/dist/oidc/scope-names.d.ts +12 -0
  32. package/dist/oidc/scope-names.js +23 -0
  33. package/dist/oidc/scope-names.js.map +1 -0
  34. package/dist/oidc/scope.d.ts +3 -11
  35. package/dist/oidc/scope.js +4 -20
  36. package/dist/oidc/scope.js.map +1 -1
  37. package/dist/scopes/index.d.ts +7 -0
  38. package/dist/scopes/index.js +7 -0
  39. package/dist/scopes/index.js.map +1 -0
  40. package/dist/scopes/oidc-scopes.d.ts +12 -0
  41. package/dist/scopes/oidc-scopes.js +23 -0
  42. package/dist/scopes/oidc-scopes.js.map +1 -0
  43. package/dist/scopes/scope-definition.d.ts +106 -0
  44. package/dist/scopes/scope-definition.js +138 -0
  45. package/dist/scopes/scope-definition.js.map +1 -0
  46. package/dist/scopes/scope-string.d.ts +32 -0
  47. package/dist/scopes/scope-string.js +42 -0
  48. package/dist/scopes/scope-string.js.map +1 -0
  49. package/package.json +6 -1
@@ -19,6 +19,7 @@ export declare const MAX_API_SCOPE_DESCRIPTION_LENGTH: 256;
19
19
  export declare const MAX_API_SCOPES_PER_API_SERVER: 100;
20
20
  /**
21
21
  * One RFC 6749 §3.3 scope-token: printable ASCII except SP, `"` and `\`.
22
+ * The same rule as `SCOPE_TOKEN_REGEX` (scope definitions).
22
23
  */
23
24
  export declare const API_SCOPE_VALUE_REGEX: RegExp;
24
25
  /**
@@ -15,14 +15,18 @@
15
15
  import { z } from "zod";
16
16
  import { apiServerIdSchema } from "@schemavaults/app-definitions";
17
17
  import { isOidcReservedScope } from "../oidc/scope";
18
- export const MAX_API_SCOPE_VALUE_LENGTH = 128;
19
- export const MAX_API_SCOPE_DESCRIPTION_LENGTH = 256;
18
+ import { MAX_SCOPE_DESCRIPTION_LENGTH, MAX_SCOPE_VALUE_LENGTH, SCOPE_TOKEN_REGEX, } from "../scopes/scope-definition";
19
+ // The same limits as scope definitions (`defineScope()`), so every
20
+ // definition can be defined on the auth server as it is.
21
+ export const MAX_API_SCOPE_VALUE_LENGTH = MAX_SCOPE_VALUE_LENGTH;
22
+ export const MAX_API_SCOPE_DESCRIPTION_LENGTH = MAX_SCOPE_DESCRIPTION_LENGTH;
20
23
  /** Upper bound on the scopes one API server may define. */
21
24
  export const MAX_API_SCOPES_PER_API_SERVER = 100;
22
25
  /**
23
26
  * One RFC 6749 §3.3 scope-token: printable ASCII except SP, `"` and `\`.
27
+ * The same rule as `SCOPE_TOKEN_REGEX` (scope definitions).
24
28
  */
25
- export const API_SCOPE_VALUE_REGEX = /^[\x21\x23-\x5B\x5D-\x7E]+$/;
29
+ export const API_SCOPE_VALUE_REGEX = SCOPE_TOKEN_REGEX;
26
30
  /**
27
31
  * A scope value an API server may define: a single RFC 6749 scope-token
28
32
  * that is not one of the OIDC scope names.
@@ -1 +1 @@
1
- {"version":3,"file":"api-server-scope.js","sourceRoot":"","sources":["../../src/api-scopes/api-server-scope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEpD,MAAM,CAAC,MAAM,0BAA0B,GAAG,GAAY,CAAC;AACvD,MAAM,CAAC,MAAM,gCAAgC,GAAG,GAAY,CAAC;AAC7D,2DAA2D;AAC3D,MAAM,CAAC,MAAM,6BAA6B,GAAG,GAAY,CAAC;AAE1D;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAW,6BAA6B,CAAC;AAE3E;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC;KACjC,MAAM,EAAE;KACR,GAAG,CAAC,CAAC,CAAC;KACN,GAAG,CAAC,0BAA0B,CAAC;KAC/B,KAAK,CAAC,qBAAqB,EAAE;IAC5B,OAAO,EACL,6FAA6F;CAChG,CAAC;KACD,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,mBAAmB,CAAC,KAAK,CAAC,EAAE;IAC9C,OAAO,EACL,qHAAqH;CACxH,CAAC,CAAC;AAIL,6DAA6D;AAC7D,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AAC;AAMZ;;;;GAIG;AACH,MAAM,CAAC,MAAM,iCAAiC,GAAG,CAAC;KAC/C,MAAM,CAAC;IACN,WAAW,EAAE,yBAAyB,CAAC,QAAQ,EAAE;IACjD,qBAAqB,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;CAC9C,CAAC;KACD,MAAM,EAAE;KACR,MAAM,CACL,CAAC,MAAM,EAAE,EAAE,CACT,MAAM,CAAC,WAAW,KAAK,SAAS;IAChC,MAAM,CAAC,qBAAqB,KAAK,SAAS,EAC5C,4EAA4E,CAC7E,CAAC"}
package/dist/index.d.ts CHANGED
@@ -15,6 +15,8 @@ export * from "./oidc";
15
15
  export type * from "./oidc";
16
16
  export * from "./api-scopes";
17
17
  export type * from "./api-scopes";
18
+ export { SCOPE_TOKEN_REGEX, isScopeToken, isScopeDefinition, scopeDefinitionProblem, MAX_SCOPE_VALUE_LENGTH, MAX_SCOPE_DESCRIPTION_LENGTH, scopeValue, scopeValues, defineScope, defineScopes, oidcScopes, parseScope, formatScope, missingFromScope, scopeIncludes, } from "./scopes";
19
+ export type { DefinedScopes, GrantedScopeInput, ScopeDefinition, ScopeInput, ScopeRequirement, } from "./scopes";
18
20
  export { sha256_base64url } from "./sha256_digest";
19
21
  export { authenticateResultSchema, authenticatedAuthenticateResultSchema, mfaRequiredAuthenticateResultSchema, authenticateFailureResultSchema, challengeExpiredAuthenticateResultSchema, emailVerificationRequiredAuthenticateResultSchema, availableMfaFactorSchema, collapseWebauthnFactors, type AuthenticateResult, type AuthenticatedAuthenticateResult, type MfaRequiredAuthenticateResult, type AuthenticateFailureResult, type ChallengeExpiredAuthenticateResult, type EmailVerificationRequiredAuthenticateResult, type AvailableMfaFactor, } from "./authenticate_result";
20
22
  export * from "./mfa";
package/dist/index.js CHANGED
@@ -8,6 +8,7 @@ export * from "./middleware";
8
8
  export * from "./pkce";
9
9
  export * from "./oidc";
10
10
  export * from "./api-scopes";
11
+ export { SCOPE_TOKEN_REGEX, isScopeToken, isScopeDefinition, scopeDefinitionProblem, MAX_SCOPE_VALUE_LENGTH, MAX_SCOPE_DESCRIPTION_LENGTH, scopeValue, scopeValues, defineScope, defineScopes, oidcScopes, parseScope, formatScope, missingFromScope, scopeIncludes, } from "./scopes";
11
12
  export { sha256_base64url } from "./sha256_digest";
12
13
  export { authenticateResultSchema, authenticatedAuthenticateResultSchema, mfaRequiredAuthenticateResultSchema, authenticateFailureResultSchema, challengeExpiredAuthenticateResultSchema, emailVerificationRequiredAuthenticateResultSchema, availableMfaFactorSchema, collapseWebauthnFactors, } from "./authenticate_result";
13
14
  export * from "./mfa";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,cAAc,GACf,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EACL,mCAAmC,EACnC,qCAAqC,GACtC,MAAM,gCAAgC,CAAC;AAExC,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,kBAAkB,EAClB,kBAAkB,EAClB,uBAAuB,EAIvB,mBAAmB,EACnB,mBAAmB,EACnB,yBAAyB,EACzB,cAAc,EACd,oBAAoB,EACpB,kBAAkB,EAClB,qBAAqB,EACrB,sBAAsB,EACtB,8BAA8B,EAC9B,yBAAyB,GAK1B,MAAM,aAAa,CAAC;AAErB,cAAc,eAAe,CAAC;AAG9B,mBAAmB;AACnB,cAAc,cAAc,CAAC;AAM7B,cAAc,cAAc,CAAC;AAG7B,cAAc,QAAQ,CAAC;AAGvB,cAAc,QAAQ,CAAC;AAGvB,cAAc,cAAc,CAAC;AAG7B,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEnD,OAAO,EACL,wBAAwB,EACxB,qCAAqC,EACrC,mCAAmC,EACnC,+BAA+B,EAC/B,wCAAwC,EACxC,iDAAiD,EACjD,wBAAwB,EACxB,uBAAuB,GAQxB,MAAM,uBAAuB,CAA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AAE,MAAM,4CAA4C,CAAC;AAEtG,OAAO,EAAE,kCAAkC,EAAE,MAAM,0CAA0C,CAAC;AAE9F,OAAO,EACL,uBAAuB,EACvB,6BAA6B,EAC7B,4BAA4B,EAC5B,wBAAwB,GACzB,MAAM,cAAc,CAAC;AAGtB,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEnE,OAAO,EACL,gBAAgB,EAChB,oBAAoB,GACrB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,qBAAqB,EAAE,MAAM,QAAQ,CAAC;AAE/C,OAAO,EACL,0BAA0B,EAC1B,uBAAuB,EACvB,qBAAqB,EACrB,sBAAsB,EACtB,wBAAwB,EACxB,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAAE,gCAAgC,EAAE,MAAM,UAAU,CAAC;AAE5D,OAAO,EACL,iBAAiB,EACjB,yBAAyB,EACzB,gBAAgB,EAChB,0BAA0B,GAC3B,MAAM,uBAAuB,CAAC"}
@@ -0,0 +1,43 @@
1
+ /** RFC 8628 §3.4 `grant_type` of a device access token request. */
2
+ export declare const OAUTH_DEVICE_CODE_GRANT_TYPE: "urn:ietf:params:oauth:grant-type:device_code";
3
+ /**
4
+ * Lifetime of a device authorization (its `device_code` and `user_code`),
5
+ * in seconds: the `expires_in` of every device authorization response. The
6
+ * user has this long to enter the code and approve the request.
7
+ */
8
+ export declare const DEVICE_AUTHORIZATION_EXPIRES_IN_SECONDS: number;
9
+ /**
10
+ * The minimum number of seconds a client waits between polling requests
11
+ * (RFC 8628 §3.2 `interval`; 5 is also the default a client assumes when
12
+ * the response omits it).
13
+ */
14
+ export declare const DEVICE_AUTHORIZATION_DEFAULT_INTERVAL_SECONDS = 5;
15
+ /**
16
+ * RFC 8628 §3.5: on `slow_down` "the interval MUST be increased by 5 seconds
17
+ * for this and all subsequent requests". The auth server adds it to the
18
+ * interval it enforces, and clients add it to the one they wait.
19
+ */
20
+ export declare const DEVICE_AUTHORIZATION_SLOW_DOWN_INCREMENT_SECONDS = 5;
21
+ /**
22
+ * The auth server page where the user enters a user code (the
23
+ * `verification_uri`, RFC 8628 §3.2), relative to the auth server URL.
24
+ */
25
+ export declare const DEVICE_VERIFICATION_PATH: "/device";
26
+ /** The query parameter of `verification_uri_complete` carrying the user code. */
27
+ export declare const DEVICE_VERIFICATION_USER_CODE_PARAM: "user_code";
28
+ /**
29
+ * The error codes of RFC 8628 §3.5 a device access token request may be
30
+ * answered with, besides those of RFC 6749 §5.2:
31
+ *
32
+ * - `authorization_pending`: the user has not decided yet; poll again after
33
+ * the interval.
34
+ * - `slow_down`: as `authorization_pending`, but the client polled too fast;
35
+ * add 5 seconds to its interval.
36
+ * - `access_denied`: the user denied the request. Stop polling.
37
+ * - `expired_token`: the device code expired. Stop polling; start over with
38
+ * a new device authorization request if the user still wants to.
39
+ */
40
+ export declare const DEVICE_ACCESS_TOKEN_ERRORS: readonly ["authorization_pending", "slow_down", "access_denied", "expired_token"];
41
+ export type DeviceAccessTokenError = (typeof DEVICE_ACCESS_TOKEN_ERRORS)[number];
42
+ /** Whether `error` is one of the RFC 8628 §3.5 device access token errors. */
43
+ export declare function isDeviceAccessTokenError(error: unknown): error is DeviceAccessTokenError;
@@ -0,0 +1,57 @@
1
+ // OAuth 2.0 Device Authorization Grant (RFC 8628) identifiers and timings,
2
+ // shared by the auth server's device authorization and token endpoints, its
3
+ // discovery document, its `/device` verification page and the SDK helpers
4
+ // that run the flow (`requestDeviceAuthorization()` in
5
+ // @schemavaults/auth-client-sdk, `startDeviceAuthorization()` in
6
+ // @schemavaults/auth-server-sdk/confidential-client).
7
+ /** RFC 8628 §3.4 `grant_type` of a device access token request. */
8
+ export const OAUTH_DEVICE_CODE_GRANT_TYPE = "urn:ietf:params:oauth:grant-type:device_code";
9
+ /**
10
+ * Lifetime of a device authorization (its `device_code` and `user_code`),
11
+ * in seconds: the `expires_in` of every device authorization response. The
12
+ * user has this long to enter the code and approve the request.
13
+ */
14
+ export const DEVICE_AUTHORIZATION_EXPIRES_IN_SECONDS = 15 * 60;
15
+ /**
16
+ * The minimum number of seconds a client waits between polling requests
17
+ * (RFC 8628 §3.2 `interval`; 5 is also the default a client assumes when
18
+ * the response omits it).
19
+ */
20
+ export const DEVICE_AUTHORIZATION_DEFAULT_INTERVAL_SECONDS = 5;
21
+ /**
22
+ * RFC 8628 §3.5: on `slow_down` "the interval MUST be increased by 5 seconds
23
+ * for this and all subsequent requests". The auth server adds it to the
24
+ * interval it enforces, and clients add it to the one they wait.
25
+ */
26
+ export const DEVICE_AUTHORIZATION_SLOW_DOWN_INCREMENT_SECONDS = 5;
27
+ /**
28
+ * The auth server page where the user enters a user code (the
29
+ * `verification_uri`, RFC 8628 §3.2), relative to the auth server URL.
30
+ */
31
+ export const DEVICE_VERIFICATION_PATH = "/device";
32
+ /** The query parameter of `verification_uri_complete` carrying the user code. */
33
+ export const DEVICE_VERIFICATION_USER_CODE_PARAM = "user_code";
34
+ /**
35
+ * The error codes of RFC 8628 §3.5 a device access token request may be
36
+ * answered with, besides those of RFC 6749 §5.2:
37
+ *
38
+ * - `authorization_pending`: the user has not decided yet; poll again after
39
+ * the interval.
40
+ * - `slow_down`: as `authorization_pending`, but the client polled too fast;
41
+ * add 5 seconds to its interval.
42
+ * - `access_denied`: the user denied the request. Stop polling.
43
+ * - `expired_token`: the device code expired. Stop polling; start over with
44
+ * a new device authorization request if the user still wants to.
45
+ */
46
+ export const DEVICE_ACCESS_TOKEN_ERRORS = [
47
+ "authorization_pending",
48
+ "slow_down",
49
+ "access_denied",
50
+ "expired_token",
51
+ ];
52
+ /** Whether `error` is one of the RFC 8628 §3.5 device access token errors. */
53
+ export function isDeviceAccessTokenError(error) {
54
+ return (typeof error === "string" &&
55
+ DEVICE_ACCESS_TOKEN_ERRORS.includes(error));
56
+ }
57
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/oidc/device-authorization/constants.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,4EAA4E;AAC5E,0EAA0E;AAC1E,uDAAuD;AACvD,iEAAiE;AACjE,sDAAsD;AAEtD,mEAAmE;AACnE,MAAM,CAAC,MAAM,4BAA4B,GACvC,8CAAuD,CAAC;AAE1D;;;;GAIG;AACH,MAAM,CAAC,MAAM,uCAAuC,GAAG,EAAE,GAAG,EAAE,CAAC;AAE/D;;;;GAIG;AACH,MAAM,CAAC,MAAM,6CAA6C,GAAG,CAAC,CAAC;AAE/D;;;;GAIG;AACH,MAAM,CAAC,MAAM,gDAAgD,GAAG,CAAC,CAAC;AAElE;;;GAGG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,SAAkB,CAAC;AAE3D,iFAAiF;AACjF,MAAM,CAAC,MAAM,mCAAmC,GAAG,WAAoB,CAAC;AAExE;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACxC,uBAAuB;IACvB,WAAW;IACX,eAAe;IACf,eAAe;CACP,CAAC;AAIX,8EAA8E;AAC9E,MAAM,UAAU,wBAAwB,CACtC,KAAc;IAEd,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACxB,0BAAgD,CAAC,QAAQ,CAAC,KAAK,CAAC,CAClE,CAAC;AACJ,CAAC"}
@@ -0,0 +1,29 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * The device authorization response (RFC 8628 §3.2), as the auth server's
4
+ * `POST /api/oidc/device_authorization` answers it:
5
+ *
6
+ * - `device_code`: the client's secret handle on the request; it polls the
7
+ * token endpoint with it. Never show it to the user.
8
+ * - `user_code`: what the user types on the verification page, formatted
9
+ * for display ("BCDF-GHJK").
10
+ * - `verification_uri`: the page where the user enters it (the auth
11
+ * server's `/device`). Show it with the user code.
12
+ * - `verification_uri_complete`: the same page with the code filled in, for
13
+ * a QR code or a link the user can open directly. Still show the user
14
+ * code next to it, so the user can check it against what the page shows.
15
+ * - `expires_in`: seconds until both codes expire.
16
+ * - `interval`: seconds to wait between polls (RFC 8628 §3.5; add 5 on
17
+ * every `slow_down`). Defaults to 5 when omitted.
18
+ *
19
+ * Loose: other fields an authorization server adds are kept.
20
+ */
21
+ export declare const deviceAuthorizationResponseSchema: z.ZodObject<{
22
+ device_code: z.ZodString;
23
+ user_code: z.ZodString;
24
+ verification_uri: z.ZodURL;
25
+ verification_uri_complete: z.ZodOptional<z.ZodURL>;
26
+ expires_in: z.ZodNumber;
27
+ interval: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
28
+ }, z.core.$loose>;
29
+ export type DeviceAuthorizationResponse = z.infer<typeof deviceAuthorizationResponseSchema>;
@@ -0,0 +1,35 @@
1
+ import { z } from "zod";
2
+ import { DEVICE_AUTHORIZATION_DEFAULT_INTERVAL_SECONDS } from "./constants";
3
+ /**
4
+ * The device authorization response (RFC 8628 §3.2), as the auth server's
5
+ * `POST /api/oidc/device_authorization` answers it:
6
+ *
7
+ * - `device_code`: the client's secret handle on the request; it polls the
8
+ * token endpoint with it. Never show it to the user.
9
+ * - `user_code`: what the user types on the verification page, formatted
10
+ * for display ("BCDF-GHJK").
11
+ * - `verification_uri`: the page where the user enters it (the auth
12
+ * server's `/device`). Show it with the user code.
13
+ * - `verification_uri_complete`: the same page with the code filled in, for
14
+ * a QR code or a link the user can open directly. Still show the user
15
+ * code next to it, so the user can check it against what the page shows.
16
+ * - `expires_in`: seconds until both codes expire.
17
+ * - `interval`: seconds to wait between polls (RFC 8628 §3.5; add 5 on
18
+ * every `slow_down`). Defaults to 5 when omitted.
19
+ *
20
+ * Loose: other fields an authorization server adds are kept.
21
+ */
22
+ export const deviceAuthorizationResponseSchema = z.looseObject({
23
+ device_code: z.string().min(1),
24
+ user_code: z.string().min(1),
25
+ verification_uri: z.url(),
26
+ verification_uri_complete: z.url().optional(),
27
+ expires_in: z.number().int().positive(),
28
+ interval: z
29
+ .number()
30
+ .int()
31
+ .positive()
32
+ .optional()
33
+ .default(DEVICE_AUTHORIZATION_DEFAULT_INTERVAL_SECONDS),
34
+ });
35
+ //# sourceMappingURL=device-authorization-response.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"device-authorization-response.js","sourceRoot":"","sources":["../../../src/oidc/device-authorization/device-authorization-response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,6CAA6C,EAAE,MAAM,aAAa,CAAC;AAE5E;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,iCAAiC,GAAG,CAAC,CAAC,WAAW,CAAC;IAC7D,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC9B,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC5B,gBAAgB,EAAE,CAAC,CAAC,GAAG,EAAE;IACzB,yBAAyB,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE;IAC7C,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE;IACvC,QAAQ,EAAE,CAAC;SACR,MAAM,EAAE;SACR,GAAG,EAAE;SACL,QAAQ,EAAE;SACV,QAAQ,EAAE;SACV,OAAO,CAAC,6CAA6C,CAAC;CAC1D,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ export { OAUTH_DEVICE_CODE_GRANT_TYPE, DEVICE_AUTHORIZATION_EXPIRES_IN_SECONDS, DEVICE_AUTHORIZATION_DEFAULT_INTERVAL_SECONDS, DEVICE_AUTHORIZATION_SLOW_DOWN_INCREMENT_SECONDS, DEVICE_VERIFICATION_PATH, DEVICE_VERIFICATION_USER_CODE_PARAM, DEVICE_ACCESS_TOKEN_ERRORS, isDeviceAccessTokenError, } from "./constants";
2
+ export type { DeviceAccessTokenError } from "./constants";
3
+ export { USER_CODE_ALPHABET, USER_CODE_LENGTH, USER_CODE_GROUP_SIZE, MAX_USER_CODE_INPUT_LENGTH, generateUserCode, isNormalizedUserCode, normalizeUserCode, formatUserCode, } from "./user-code";
4
+ export type { RandomBytesSource } from "./user-code";
5
+ export { deviceAuthorizationResponseSchema } from "./device-authorization-response";
6
+ export type { DeviceAuthorizationResponse } from "./device-authorization-response";
7
+ export { getDeviceVerificationUri, getDeviceVerificationUriComplete, } from "./verification-uri";
@@ -0,0 +1,5 @@
1
+ export { OAUTH_DEVICE_CODE_GRANT_TYPE, DEVICE_AUTHORIZATION_EXPIRES_IN_SECONDS, DEVICE_AUTHORIZATION_DEFAULT_INTERVAL_SECONDS, DEVICE_AUTHORIZATION_SLOW_DOWN_INCREMENT_SECONDS, DEVICE_VERIFICATION_PATH, DEVICE_VERIFICATION_USER_CODE_PARAM, DEVICE_ACCESS_TOKEN_ERRORS, isDeviceAccessTokenError, } from "./constants";
2
+ export { USER_CODE_ALPHABET, USER_CODE_LENGTH, USER_CODE_GROUP_SIZE, MAX_USER_CODE_INPUT_LENGTH, generateUserCode, isNormalizedUserCode, normalizeUserCode, formatUserCode, } from "./user-code";
3
+ export { deviceAuthorizationResponseSchema } from "./device-authorization-response";
4
+ export { getDeviceVerificationUri, getDeviceVerificationUriComplete, } from "./verification-uri";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/oidc/device-authorization/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,EAC5B,uCAAuC,EACvC,6CAA6C,EAC7C,gDAAgD,EAChD,wBAAwB,EACxB,mCAAmC,EACnC,0BAA0B,EAC1B,wBAAwB,GACzB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,oBAAoB,EACpB,0BAA0B,EAC1B,gBAAgB,EAChB,oBAAoB,EACpB,iBAAiB,EACjB,cAAc,GACf,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,iCAAiC,EAAE,MAAM,iCAAiC,CAAC;AAGpF,OAAO,EACL,wBAAwB,EACxB,gCAAgC,GACjC,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,31 @@
1
+ /** The characters of a user code (RFC 8628 §6.1's base-20 example). */
2
+ export declare const USER_CODE_ALPHABET: "BCDFGHJKLMNPQRSTVWXZ";
3
+ /** Number of characters in a user code, without its separator. */
4
+ export declare const USER_CODE_LENGTH: 8;
5
+ /** Characters per displayed group ("BCDF-GHJK"). */
6
+ export declare const USER_CODE_GROUP_SIZE: 4;
7
+ /** Longest raw input `normalizeUserCode()` looks at. */
8
+ export declare const MAX_USER_CODE_INPUT_LENGTH: 32;
9
+ /** Fills a byte array with cryptographically secure random values. */
10
+ export type RandomBytesSource = (bytes: Uint8Array) => Uint8Array;
11
+ /**
12
+ * Generates a new user code, in normalized form (8 characters, no
13
+ * separator). Uses rejection sampling so each character is uniform over the
14
+ * alphabet.
15
+ */
16
+ export declare function generateUserCode(randomBytes?: RandomBytesSource): string;
17
+ /** Whether `value` is a user code in normalized form. */
18
+ export declare function isNormalizedUserCode(value: unknown): value is string;
19
+ /**
20
+ * Normalizes what a user typed into a user code (RFC 8628 §6.1): upper-cases
21
+ * it and drops dashes and whitespace. Null when the result is not a
22
+ * well-formed user code (wrong length, or a character outside the alphabet),
23
+ * so a typo is caught before any lookup.
24
+ */
25
+ export declare function normalizeUserCode(input: unknown): string | null;
26
+ /**
27
+ * Formats a user code for display, in groups of four separated by a dash
28
+ * ("BCDF-GHJK"). Accepts any form `normalizeUserCode()` accepts; returns the
29
+ * input unchanged when it is not a user code.
30
+ */
31
+ export declare function formatUserCode(code: string): string;
@@ -0,0 +1,73 @@
1
+ // The end-user verification code of the device authorization grant
2
+ // (RFC 8628 §3.2 `user_code`, §6.1 "User Code Recommendations").
3
+ //
4
+ // A user code is 8 characters from a base-20 alphabet of upper-case
5
+ // consonants: easy to read off a screen and type on a phone, and free of
6
+ // vowels so no code spells a word. That is 20^8 ≈ 2^34.6 codes, so with the
7
+ // rate limits on the verification page and the codes' short lifetime a guess
8
+ // is hopeless (§5.1). It is shown and entered as two groups of four
9
+ // ("BCDF-GHJK"); entry is case-insensitive and ignores dashes and spaces.
10
+ /** The characters of a user code (RFC 8628 §6.1's base-20 example). */
11
+ export const USER_CODE_ALPHABET = "BCDFGHJKLMNPQRSTVWXZ";
12
+ /** Number of characters in a user code, without its separator. */
13
+ export const USER_CODE_LENGTH = 8;
14
+ /** Characters per displayed group ("BCDF-GHJK"). */
15
+ export const USER_CODE_GROUP_SIZE = 4;
16
+ /** Longest raw input `normalizeUserCode()` looks at. */
17
+ export const MAX_USER_CODE_INPUT_LENGTH = 32;
18
+ const USER_CODE_REGEX = new RegExp(`^[${USER_CODE_ALPHABET}]{${USER_CODE_LENGTH}}$`);
19
+ // Largest multiple of the alphabet size that fits a byte: bytes at or above
20
+ // it are discarded so every character is equally likely.
21
+ const UNBIASED_BYTE_LIMIT = Math.floor(256 / USER_CODE_ALPHABET.length) * USER_CODE_ALPHABET.length;
22
+ function defaultRandomBytes(bytes) {
23
+ return crypto.getRandomValues(bytes);
24
+ }
25
+ /**
26
+ * Generates a new user code, in normalized form (8 characters, no
27
+ * separator). Uses rejection sampling so each character is uniform over the
28
+ * alphabet.
29
+ */
30
+ export function generateUserCode(randomBytes = defaultRandomBytes) {
31
+ let code = "";
32
+ while (code.length < USER_CODE_LENGTH) {
33
+ const bytes = randomBytes(new Uint8Array(USER_CODE_LENGTH * 2));
34
+ for (const byte of bytes) {
35
+ if (byte >= UNBIASED_BYTE_LIMIT)
36
+ continue;
37
+ code += USER_CODE_ALPHABET[byte % USER_CODE_ALPHABET.length];
38
+ if (code.length === USER_CODE_LENGTH)
39
+ break;
40
+ }
41
+ }
42
+ return code;
43
+ }
44
+ /** Whether `value` is a user code in normalized form. */
45
+ export function isNormalizedUserCode(value) {
46
+ return typeof value === "string" && USER_CODE_REGEX.test(value);
47
+ }
48
+ /**
49
+ * Normalizes what a user typed into a user code (RFC 8628 §6.1): upper-cases
50
+ * it and drops dashes and whitespace. Null when the result is not a
51
+ * well-formed user code (wrong length, or a character outside the alphabet),
52
+ * so a typo is caught before any lookup.
53
+ */
54
+ export function normalizeUserCode(input) {
55
+ if (typeof input !== "string" || input.length > MAX_USER_CODE_INPUT_LENGTH) {
56
+ return null;
57
+ }
58
+ const normalized = input.toUpperCase().replace(/[\s-]+/g, "");
59
+ return isNormalizedUserCode(normalized) ? normalized : null;
60
+ }
61
+ /**
62
+ * Formats a user code for display, in groups of four separated by a dash
63
+ * ("BCDF-GHJK"). Accepts any form `normalizeUserCode()` accepts; returns the
64
+ * input unchanged when it is not a user code.
65
+ */
66
+ export function formatUserCode(code) {
67
+ const normalized = normalizeUserCode(code);
68
+ if (normalized === null) {
69
+ return code;
70
+ }
71
+ return `${normalized.slice(0, USER_CODE_GROUP_SIZE)}-${normalized.slice(USER_CODE_GROUP_SIZE)}`;
72
+ }
73
+ //# sourceMappingURL=user-code.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user-code.js","sourceRoot":"","sources":["../../../src/oidc/device-authorization/user-code.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,iEAAiE;AACjE,EAAE;AACF,oEAAoE;AACpE,yEAAyE;AACzE,4EAA4E;AAC5E,6EAA6E;AAC7E,oEAAoE;AACpE,0EAA0E;AAE1E,uEAAuE;AACvE,MAAM,CAAC,MAAM,kBAAkB,GAAG,sBAA+B,CAAC;AAElE,kEAAkE;AAClE,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAU,CAAC;AAE3C,oDAAoD;AACpD,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAU,CAAC;AAE/C,wDAAwD;AACxD,MAAM,CAAC,MAAM,0BAA0B,GAAG,EAAW,CAAC;AAEtD,MAAM,eAAe,GAAG,IAAI,MAAM,CAAC,KAAK,kBAAkB,KAAK,gBAAgB,IAAI,CAAC,CAAC;AAErF,4EAA4E;AAC5E,yDAAyD;AACzD,MAAM,mBAAmB,GACvB,IA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AC,IAAI,CAAC;AAC9D,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,IAAY;IACzC,MAAM,UAAU,GAAkB,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAC1D,IAAI,UAAU,KAAK,IAAI,EAAE,CAAC;QACxB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,oBAAoB,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,oBAAoB,CAAC,EAAE,CAAC;AAClG,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The `verification_uri` (RFC 8628 §3.2) of the auth server at `issuer`:
3
+ * its `/device` page, where the user enters the user code.
4
+ */
5
+ export declare function getDeviceVerificationUri(issuer: string): string;
6
+ /**
7
+ * The `verification_uri_complete` (RFC 8628 §3.3.1) for `user_code`: the
8
+ * `/device` page with the code filled in (in its display form).
9
+ */
10
+ export declare function getDeviceVerificationUriComplete(issuer: string, user_code: string): string;
@@ -0,0 +1,25 @@
1
+ import { DEVICE_VERIFICATION_PATH, DEVICE_VERIFICATION_USER_CODE_PARAM, } from "./constants";
2
+ import { formatUserCode } from "./user-code";
3
+ function stripTrailingSlash(issuer) {
4
+ if (typeof issuer !== "string" || issuer.length === 0) {
5
+ throw new TypeError("Expected 'issuer' to be a non-empty string!");
6
+ }
7
+ return issuer.endsWith("/") ? issuer.slice(0, -1) : issuer;
8
+ }
9
+ /**
10
+ * The `verification_uri` (RFC 8628 §3.2) of the auth server at `issuer`:
11
+ * its `/device` page, where the user enters the user code.
12
+ */
13
+ export function getDeviceVerificationUri(issuer) {
14
+ return `${stripTrailingSlash(issuer)}${DEVICE_VERIFICATION_PATH}`;
15
+ }
16
+ /**
17
+ * The `verification_uri_complete` (RFC 8628 §3.3.1) for `user_code`: the
18
+ * `/device` page with the code filled in (in its display form).
19
+ */
20
+ export function getDeviceVerificationUriComplete(issuer, user_code) {
21
+ const url = new URL(getDeviceVerificationUri(issuer));
22
+ url.searchParams.set(DEVICE_VERIFICATION_USER_CODE_PARAM, formatUserCode(user_code));
23
+ return url.toString();
24
+ }
25
+ //# sourceMappingURL=verification-uri.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verification-uri.js","sourceRoot":"","sources":["../../../src/oidc/device-authorization/verification-uri.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,mCAAmC,GACpC,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,SAAS,kBAAkB,CAAC,MAAc;IACxC,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtD,MAAM,IAAI,SAAS,CAAC,6CAA6C,CAAC,CAAC;IACrE,CAAC;IACD,OAAO,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;AAC7D,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,wBAAwB,CAAC,MAAc;IACrD,OAAO,GAAG,kBAAkB,CAAC,MAAM,CAAC,GAAG,wBAAwB,EAAE,CAAC;AACpE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gCAAgC,CAC9C,MAAc,EACd,SAAiB;IAEjB,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,wBAAwB,CAAC,MAAM,CAAC,CAAC,CAAC;IACtD,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,mCAAmC,EAAE,cAAc,CAAC,SAAS,CAAC,CAAC,CAAC;IACrF,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC;AACxB,CAAC"}
@@ -20,6 +20,7 @@ export declare const OIDC_ENDPOINT_PATHS: {
20
20
  readonly userinfo: "/api/oidc/userinfo";
21
21
  readonly introspection: "/api/oidc/introspect";
22
22
  readonly revocation: "/api/oidc/revoke";
23
+ readonly device_authorization: "/api/oidc/device_authorization";
23
24
  readonly jwks: "/api/oidc/jwks";
24
25
  readonly registration: "/api/oidc/register";
25
26
  };
@@ -21,6 +21,8 @@ export const OIDC_ENDPOINT_PATHS = {
21
21
  introspection: "/api/oidc/introspect",
22
22
  // RFC 7009 token revocation.
23
23
  revocation: "/api/oidc/revoke",
24
+ // RFC 8628 device authorization (the device grant's first leg).
25
+ device_authorization: "/api/oidc/device_authorization",
24
26
  jwks: "/api/oidc/jwks",
25
27
  // RFC 7591 dynamic client registration; advertised in the discovery
26
28
  // document only when the server setting enabling it is on.
@@ -1 +1 @@
1
- {"version":3,"file":"endpoints.js","sourceRoot":"","sources":["../../src/oidc/endpoints.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,SAAS,EAAE,mCAAmC;IAC9C,aAAa,EAAE,qBAAqB;IACpC,KAAK,EAAE,iBAAiB;IACxB,QAAQ,EAAE,oBAAoB;IAC9B,aAAa,EAAE,sBAAsB;IACrC,6BAA6B;IAC7B,UAAU,EAAE,kBAAkB;IAC9B,IAAI,EAAE,gBAAgB;IACtB,oEAAoE;IACpE,2DAA2D;IAC3D,YAAY,EAAE,oBAAoB;CACa,CAAC;AAIlD;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAChC,MAAc,EACd,QAA0B;IAE1B,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtD,MAAM,IAAI,SAAS,CAAC,6CAA6C,CAAC,CAAC;IACrE,CAAC;IACD,MAAM,IAAI,GAA6B,mBAAmB,CAAC,QAAQ,CAAC,CAAC;IACrE,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7B,MAAM,IAAI,UAAU,CAAC,0BAA0B,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;IACtE,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C,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IACzE,OAAO,GAAG,IAAI,GAAG,IAAI,EAAE,CAAC;AAC1B,CAAC"}
@@ -1,5 +1,5 @@
1
1
  export { OIDC_OPENID_SCOPE, OIDC_SUPPORTED_SCOPES, OIDC_RESERVED_SCOPES, isOidcReservedScope, DEFAULT_AUTH_SCOPE, OIDC_SCOPE_REGEX, MAX_OIDC_SCOPE_LENGTH, oidcScopeSchema, parseAndGrantScopes, grantRequestedScopes, partitionGrantedScopes, serializeOidcScopes, serializeOidcScopesOrNull, } from "./scope";
2
- export type { OidcSupportedScope, OidcScope, ParsedOidcScopes, GrantedScopes, } from "./scope";
2
+ export type { OidcReservedScope, OidcSupportedScope, OidcScope, ParsedOidcScopes, GrantedScopes, } from "./scope";
3
3
  export { oidcNonceSchema, OIDC_NONCE_VSCHAR_REGEX, parseOidcNonce, OidcNonceValidationError, } from "./nonce";
4
4
  export type { OidcNonce } from "./nonce";
5
5
  export { OIDC_SUB_CLAIM_DELIMITER, formatOidcSubClaim, parseOidcSubClaim, } from "./sub-claim";
@@ -9,6 +9,8 @@ export { OIDC_ENDPOINT_PATHS, getOidcEndpointUrl } from "./endpoints";
9
9
  export { OAUTH_JWT_BEARER_CLIENT_ASSERTION_TYPE } from "./client-assertion";
10
10
  export { OAUTH_TOKEN_EXCHANGE_GRANT_TYPE, OAUTH_ACCESS_TOKEN_TYPE, } from "./token-exchange";
11
11
  export type { OidcEndpointName } from "./endpoints";
12
+ export * from "./device-authorization";
13
+ export type * from "./device-authorization";
12
14
  export { OIDC_TOKEN_RESOURCE_PARAM, OIDC_TOKEN_REFRESH_TOKEN_DELIVERY_PARAM, OIDC_REFRESH_TOKEN_DELIVERY_MODES, oidcRefreshTokenDeliveryModeSchema, DEFAULT_OIDC_REFRESH_TOKEN_DELIVERY_MODE, OIDC_TOKEN_REFRESH_TOKEN_EXPIRES_IN_FIELD, oidcTokenResponseExtensionsSchema, } from "./token-endpoint-extensions";
13
15
  export type { OidcRefreshTokenDeliveryMode, OidcTokenResponseExtensions, } from "./token-endpoint-extensions";
14
16
  export { buildOidcProviderMetadata } from "./provider-metadata";
@@ -5,6 +5,7 @@ export { buildOidcProfileClaims } from "./profile-claims";
5
5
  export { OIDC_ENDPOINT_PATHS, getOidcEndpointUrl } from "./endpoints";
6
6
  export { OAUTH_JWT_BEARER_CLIENT_ASSERTION_TYPE } from "./client-assertion";
7
7
  export { OAUTH_TOKEN_EXCHANGE_GRANT_TYPE, OAUTH_ACCESS_TOKEN_TYPE, } from "./token-exchange";
8
+ export * from "./device-authorization";
8
9
  export { OIDC_TOKEN_RESOURCE_PARAM, OIDC_TOKEN_REFRESH_TOKEN_DELIVERY_PARAM, OIDC_REFRESH_TOKEN_DELIVERY_MODES, oidcRefreshTokenDeliveryModeSchema, DEFAULT_OIDC_REFRESH_TOKEN_DELIVERY_MODE, OIDC_TOKEN_REFRESH_TOKEN_EXPIRES_IN_FIELD, oidcTokenResponseExtensionsSchema, } from "./token-endpoint-extensions";
9
10
  export { buildOidcProviderMetadata } from "./provider-metadata";
10
11
  export { DYNAMIC_CLIENT_REGISTRATION_ERRORS, DYNAMIC_CLIENT_MAX_REDIRECT_URIS, DYNAMIC_CLIENT_UNSUPPORTED_METADATA_FIELDS, dynamicClientRegistrationErrorSchema, dynamicClientRegistrationResponseSchema, parseDynamicClientRegistrationRequest, classifyDynamicClientRedirectUri, deriveDynamicClientNameFromRedirectUri, } from "./dynamic-client-registration";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/oidc/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,oBAAoB,EACpB,mBAAmB,EACnB,kBAAkB,EAClB,gBAAgB,EAChB,qBAAqB,EACrB,eAAe,EACf,mBAAmB,EACnB,oBAAoB,EACpB,sBAAsB,EACtB,mBAAmB,EACnB,yBAAyB,GAC1B,MAAM,SAAS,CAAC;AAQjB,OAAO,EACL,eAAe,EACf,uBAAuB,EACvB,cAAc,EACd,wBAAwB,GACzB,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,wBAAwB,EACxB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAM1D,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEtE,OAAO,EAAE,sCAAsC,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EACL,+BAA+B,EAC/B,uBAAuB,GACxB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,yBAAyB,EACzB,uCAAuC,EACvC,iCAAiC,EACjC,kCAAkC,EAClC,wCAAwC,EACxC,yCAAyC,EACzC,iCAAiC,GAClC,MAAM,6BAA6B,CAAC;AAMrC,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAMhE,OAAO,EACL,kCAAkC,EAClC,gCAAgC,EAChC,0CAA0C,EAC1C,oCAAoC,EACpC,uCAAuC,EACvC,qCAAqC,EACrC,gCAAgC,EAChC,sCAAsC,GACvC,MAAM,+BAA+B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/oidc/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,oBAAoB,EACpB,mBAAmB,EACnB,kBAAkB,EAClB,gBAAgB,EAChB,qBAAqB,EACrB,eAAe,EACf,mBAAmB,EACnB,oBAAoB,EACpB,sBAAsB,EACtB,mBAAmB,EACnB,yBAAyB,GAC1B,MAAM,SAAS,CAAC;AASjB,OAAO,EACL,eAAe,EACf,uBAAuB,EACvB,cAAc,EACd,wBAAwB,GACzB,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,wBAAwB,EACxB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAM1D,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEtE,OAAO,EAAE,sCAAsC,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EACL,+BAA+B,EAC/B,uBAAuB,GACxB,MAAM,kBAAkB,CAAC;AAG1B,cAAc,wBAAwB,CAAC;AAGvC,OAAO,EACL,yBAAyB,EACzB,uCAAuC,EACvC,iCAAiC,EACjC,kCAAkC,EAClC,wCAAwC,EACxC,yCAAyC,EACzC,iCAAiC,GAClC,MAAM,6BAA6B,CAAC;AAMrC,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAMhE,OAAO,EACL,kCAAkC,EAClC,gCAAgC,EAChC,0CAA0C,EAC1C,oCAAoC,EACpC,uCAAuC,EACvC,qCAAqC,EACrC,gCAAgC,EAChC,sCAAsC,GACvC,MAAM,+BAA+B,CAAC"}
@@ -29,6 +29,11 @@ export type OidcProviderMetadata = {
29
29
  introspection_endpoint: string;
30
30
  /** RFC 7009 token revocation endpoint (RFC 8414 §2). */
31
31
  revocation_endpoint: string;
32
+ /**
33
+ * RFC 8628 §4 device authorization endpoint, where a device (a CLI, a TV
34
+ * app) starts the device authorization grant.
35
+ */
36
+ device_authorization_endpoint: string;
32
37
  jwks_uri: string;
33
38
  response_types_supported: string[];
34
39
  response_modes_supported: string[];
@@ -17,6 +17,7 @@
17
17
  import { getOidcEndpointUrl } from "./endpoints";
18
18
  import { OIDC_SUPPORTED_SCOPES } from "./scope";
19
19
  import { OAUTH_TOKEN_EXCHANGE_GRANT_TYPE } from "./token-exchange";
20
+ import { OAUTH_DEVICE_CODE_GRANT_TYPE } from "./device-authorization/constants";
20
21
  /**
21
22
  * Builds the provider metadata for the auth server at `issuer`. A
22
23
  * trailing slash on `issuer` is stripped so the endpoints and the
@@ -36,6 +37,7 @@ export function buildOidcProviderMetadata(issuer, options = {}) {
36
37
  userinfo_endpoint: getOidcEndpointUrl(normalized_issuer, "userinfo"),
37
38
  introspection_endpoint: getOidcEndpointUrl(normalized_issuer, "introspection"),
38
39
  revocation_endpoint: getOidcEndpointUrl(normalized_issuer, "revocation"),
40
+ device_authorization_endpoint: getOidcEndpointUrl(normalized_issuer, "device_authorization"),
39
41
  jwks_uri: getOidcEndpointUrl(normalized_issuer, "jwks"),
40
42
  response_types_supported: ["code"],
41
43
  response_modes_supported: ["query"],
@@ -44,12 +46,15 @@ export function buildOidcProviderMetadata(issuer, options = {}) {
44
46
  // machine-to-machine access tokens for the app's service account.
45
47
  // The RFC 8693 token exchange is restricted to them too: it swaps one
46
48
  // of their users' access tokens for a delegated token on which the
47
- // app's service account acts for the user (e.g. an agent).
49
+ // app's service account acts for the user (e.g. an agent). The RFC 8628
50
+ // device grant signs a user in on a device that cannot show the login
51
+ // page (a CLI, a TV app); only apps whose managers enabled it may use it.
48
52
  grant_types_supported: [
49
53
  "authorization_code",
50
54
  "refresh_token",
51
55
  "client_credentials",
52
56
  OAUTH_TOKEN_EXCHANGE_GRANT_TYPE,
57
+ OAUTH_DEVICE_CODE_GRANT_TYPE,
53
58
  ],
54
59
  subject_types_supported: ["public"],
55
60
  id_token_signing_alg_values_supported: ["RS256"],
@@ -1 +1 @@
1
- {"version":3,"file":"provider-metadata.js","sourceRoot":"","sources":["../../src/oidc/provider-metadata.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,+BAA+B,EAAE,MAAM,kBAAkB,CAAC;AA0DnE;;;;GAIG;AACH,MAAM,UAAU,yBAAyB,CACvC,MAAc,EACd,UAA4C,EAAE;IAE9C,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtD,MAAM,IAAI,SAAS,CAAC,6CAA6C,CAA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BAAiB;SAClB;QACD,wDAAwD,EAAE,CAAC,OAAO,CAAC;QACnE,kEAAkE;QAClE,kEAAkE;QAClE,gEAAgE;QAChE,0CAA0C,EAAE;YAC1C,MAAM;YACN,qBAAqB;YACrB,oBAAoB;SACrB;QACD,gCAAgC,EAAE,CAAC,MAAM,CAAC;QAC1C,gBAAgB,EAAE;YAChB,KAAK;YACL,KAAK;YACL,KAAK;YACL,KAAK;YACL,KAAK;YACL,OAAO;YACP,OAAO;YACP,gBAAgB;YAChB,kEAAkE;YAClE,qDAAqD;YACrD,MAAM;YACN,YAAY;YACZ,aAAa;YACb,aAAa;YACb,oBAAoB;SACrB;QACD,8DAA8D;QAC9D,mEAAmE;QACnE,+DAA+D;QAC/D,+DAA+D;QAC/D,8CAA8C,EAAE,IAAI;QACpD,sEAAsE;QACtE,8DAA8D;QAC9D,8DAA8D;QAC9D,gDAAgD;QAChD,oEAAoE;QACpE,uCAAuC;QACvC,2BAA2B,EAAE,KAAK;QAClC,+BAA+B,EAAE,KAAK;QACtC,GAAG,CAAC,OAAO,CAAC,qBAAqB,KAAK,IAAI;YACxC,CAAC,CAAC;gBACE,qBAAqB,EAAE,kBAAkB,CACvC,iBAAiB,EACjB,cAAc,CACf;aACF;YACH,CAAC,CAAC,EAAE,CAAC;KACR,CAAC;AACJ,CAAC;AAED,eAAe,yBAAyB,CAAC"}
1
+ {"version":3,"file":"provider-metadata.js","sourceRoot":"","sources":["../../src/oidc/provider-metadata.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,+BAA+B,EAAE,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAAE,4BAA4B,EAAE,MAAM,kCAAkC,CAAC;AA+DhF;;;;GAIG;AACH,MAAM,UAAU,yBAAyB,CACvC,MAAc,EACd,UAA4C,EAA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AC5D,8DAA8D;QAC9D,sDAAsD;QACtD,qCAAqC,EAAE;YACrC,MAAM;YACN,qBAAqB;YACrB,oBAAoB;SACrB;QACD,oEAAoE;QACpE,2DAA2D;QAC3D,sEAAsE;QACtE,kEAAkE;QAClE,oEAAoE;QACpE,iCAAiC;QACjC,6CAA6C,EAAE;YAC7C,qBAAqB;YACrB,oBAAoB;YACpB,iBAAiB;SAClB;QACD,wDAAwD,EAAE,CAAC,OAAO,CAAC;QACnE,kEAAkE;QAClE,kEAAkE;QAClE,gEAAgE;QAChE,0CAA0C,EAAE;YAC1C,MAAM;YACN,qBAAqB;YACrB,oBAAoB;SACrB;QACD,gCAAgC,EAAE,CAAC,MAAM,CAAC;QAC1C,gBAAgB,EAAE;YAChB,KAAK;YACL,KAAK;YACL,KAAK;YACL,KAAK;YACL,KAAK;YACL,OAAO;YACP,OAAO;YACP,gBAAgB;YAChB,kEAAkE;YAClE,qDAAqD;YACrD,MAAM;YACN,YAAY;YACZ,aAAa;YACb,aAAa;YACb,oBAAoB;SACrB;QACD,8DAA8D;QAC9D,mEAAmE;QACnE,+DAA+D;QAC/D,+DAA+D;QAC/D,8CAA8C,EAAE,IAAI;QACpD,sEAAsE;QACtE,8DAA8D;QAC9D,8DAA8D;QAC9D,gDAAgD;QAChD,oEAAoE;QACpE,uCAAuC;QACvC,2BAA2B,EAAE,KAAK;QAClC,+BAA+B,EAAE,KAAK;QACtC,GAAG,CAAC,OAAO,CAAC,qBAAqB,KAAK,IAAI;YACxC,CAAC,CAAC;gBACE,qBAAqB,EAAE,kBAAkB,CACvC,iBAAiB,EACjB,cAAc,CACf;aACF;YACH,CAAC,CAAC,EAAE,CAAC;KACR,CAAC;AACJ,CAAC;AAED,eAAe,yBAAyB,CAAC"}
@@ -0,0 +1,12 @@
1
+ export declare const OIDC_OPENID_SCOPE: "openid";
2
+ export declare const OIDC_SUPPORTED_SCOPES: readonly ["openid", "email", "profile"];
3
+ /**
4
+ * The scope values OpenID Connect Core §5.4 / §11 standardize. No API
5
+ * server may define one of them as an API scope (even those this server
6
+ * does not support yet), so a granted scope string always splits
7
+ * unambiguously into its OIDC part and its API part
8
+ * (`partitionGrantedScopes`).
9
+ */
10
+ export declare const OIDC_RESERVED_SCOPES: readonly ["openid", "profile", "email", "address", "phone", "offline_access"];
11
+ export type OidcReservedScope = (typeof OIDC_RESERVED_SCOPES)[number];
12
+ export declare function isOidcReservedScope(scope: string): boolean;
@@ -0,0 +1,23 @@
1
+ // The OpenID Connect scope names, without zod: imported by the
2
+ // dependency-free `scopes/` module as well as `./scope`.
3
+ export const OIDC_OPENID_SCOPE = "openid";
4
+ export const OIDC_SUPPORTED_SCOPES = ["openid", "email", "profile"];
5
+ /**
6
+ * The scope values OpenID Connect Core §5.4 / §11 standardize. No API
7
+ * server may define one of them as an API scope (even those this server
8
+ * does not support yet), so a granted scope string always splits
9
+ * unambiguously into its OIDC part and its API part
10
+ * (`partitionGrantedScopes`).
11
+ */
12
+ export const OIDC_RESERVED_SCOPES = [
13
+ "openid",
14
+ "profile",
15
+ "email",
16
+ "address",
17
+ "phone",
18
+ "offline_access",
19
+ ];
20
+ export function isOidcReservedScope(scope) {
21
+ return OIDC_RESERVED_SCOPES.includes(scope);
22
+ }
23
+ //# sourceMappingURL=scope-names.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope-names.js","sourceRoot":"","sources":["../../src/oidc/scope-names.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,yDAAyD;AAEzD,MAAM,CAAC,MAAM,iBAAiB,GAAG,QAAiB,CAAC;AAEnD,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAU,CAAC;AAE7E;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,QAAQ;IACR,SAAS;IACT,OAAO;IACP,SAAS;IACT,OAAO;IACP,gBAAgB;CACR,CAAC;AAIX,MAAM,UAAU,mBAAmB,CAAC,KAAa;IAC/C,OAAQ,oBAA0C,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACrE,CAAC"}
@@ -25,17 +25,9 @@
25
25
  * unknown scopes and dropped exactly as before.
26
26
  */
27
27
  import { z } from "zod";
28
- export declare const OIDC_OPENID_SCOPE: "openid";
29
- export declare const OIDC_SUPPORTED_SCOPES: readonly ["openid", "email", "profile"];
30
- /**
31
- * The scope values OpenID Connect Core §5.4 / §11 standardize. No API
32
- * server may define one of them as an API scope (even those this server
33
- * does not support yet), so a granted scope string always splits
34
- * unambiguously into its OIDC part and its API part
35
- * (`partitionGrantedScopes`).
36
- */
37
- export declare const OIDC_RESERVED_SCOPES: readonly ["openid", "profile", "email", "address", "phone", "offline_access"];
38
- export declare function isOidcReservedScope(scope: string): boolean;
28
+ import { OIDC_OPENID_SCOPE, OIDC_SUPPORTED_SCOPES, OIDC_RESERVED_SCOPES, isOidcReservedScope } from "./scope-names";
29
+ export { OIDC_OPENID_SCOPE, OIDC_SUPPORTED_SCOPES, OIDC_RESERVED_SCOPES, isOidcReservedScope };
30
+ export type { OidcReservedScope } from "./scope-names";
39
31
  /**
40
32
  * Scope requested by default when a flow does not name one explicitly:
41
33
  * the SDK's `authenticateWithRedirect`/`sendAuthenticateRequest`
@@ -25,26 +25,10 @@
25
25
  * unknown scopes and dropped exactly as before.
26
26
  */
27
27
  import { z } from "zod";
28
- export const OIDC_OPENID_SCOPE = "openid";
29
- export const OIDC_SUPPORTED_SCOPES = ["openid", "email", "profile"];
30
- /**
31
- * The scope values OpenID Connect Core §5.4 / §11 standardize. No API
32
- * server may define one of them as an API scope (even those this server
33
- * does not support yet), so a granted scope string always splits
34
- * unambiguously into its OIDC part and its API part
35
- * (`partitionGrantedScopes`).
36
- */
37
- export const OIDC_RESERVED_SCOPES = [
38
- "openid",
39
- "profile",
40
- "email",
41
- "address",
42
- "phone",
43
- "offline_access",
44
- ];
45
- export function isOidcReservedScope(scope) {
46
- return OIDC_RESERVED_SCOPES.includes(scope);
47
- }
28
+ import { OIDC_OPENID_SCOPE, OIDC_SUPPORTED_SCOPES, OIDC_RESERVED_SCOPES, isOidcReservedScope, } from "./scope-names";
29
+ // The scope names live in ./scope-names (no zod) so the dependency-free
30
+ // `@schemavaults/auth-common/scopes` entry point can build on them.
31
+ export { OIDC_OPENID_SCOPE, OIDC_SUPPORTED_SCOPES, OIDC_RESERVED_SCOPES, isOidcReservedScope };
48
32
  /**
49
33
  * Scope requested by default when a flow does not name one explicitly:
50
34
  * the SDK's `authenticateWithRedirect`/`sendAuthenticateRequest`
@@ -1 +1 @@
1
- {"version":3,"file":"scope.js","sourceRoot":"","sources":["../../src/oidc/scope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,iBAAiB,GAAG,QAAiB,CAAC;AAEnD,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAU,CAAC;AAE7E;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,QAAQ;IACR,SAAS;IACT,OAAO;IACP,SAAS;IACT,OAAO;IACP,gBAAgB;CACR,CAAC;AAEX,MAAM,UAAU,mBAAmB,CAAC,KAAa;IAC/C,OAAQ,oBAA0C,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACrE,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,sBAA+B,CAAC;AAElE;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAa,CAAC;AAEnD;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAC3B,4DAA4D,CAAC;AAE/D;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC;KAC7B,MAAM,EAAE;KACR,GAAG,CAAC,CAAC,CAAC;K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K,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;AACvB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAyB;IAC3D,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC1B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,yBAAyB,CACvC,MAAyB;IAEzB,OAAO,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC;AAClE,CAAC"}
@@ -0,0 +1,7 @@
1
+ export { SCOPE_TOKEN_REGEX, isScopeToken, isScopeDefinition, scopeDefinitionProblem, MAX_SCOPE_VALUE_LENGTH, MAX_SCOPE_DESCRIPTION_LENGTH, scopeValue, scopeValues, defineScope, defineScopes, } from "./scope-definition";
2
+ export type { DefinedScopes, ScopeDefinition, ScopeRequirement } from "./scope-definition";
3
+ export { oidcScopes } from "./oidc-scopes";
4
+ export { parseScope, formatScope, missingFromScope, scopeIncludes } from "./scope-string";
5
+ export type { GrantedScopeInput, ScopeInput } from "./scope-string";
6
+ export { OIDC_OPENID_SCOPE, OIDC_SUPPORTED_SCOPES, OIDC_RESERVED_SCOPES, isOidcReservedScope, } from "../oidc/scope-names";
7
+ export type { OidcReservedScope } from "../oidc/scope-names";
@@ -0,0 +1,7 @@
1
+ // `@schemavaults/auth-common/scopes`: scope definitions and scope-string
2
+ // helpers with no runtime dependencies (no zod), safe in client bundles.
3
+ export { SCOPE_TOKEN_REGEX, isScopeToken, isScopeDefinition, scopeDefinitionProblem, MAX_SCOPE_VALUE_LENGTH, MAX_SCOPE_DESCRIPTION_LENGTH, scopeValue, scopeValues, defineScope, defineScopes, } from "./scope-definition";
4
+ export { oidcScopes } from "./oidc-scopes";
5
+ export { parseScope, formatScope, missingFromScope, scopeIncludes } from "./scope-string";
6
+ export { OIDC_OPENID_SCOPE, OIDC_SUPPORTED_SCOPES, OIDC_RESERVED_SCOPES, isOidcReservedScope, } from "../oidc/scope-names";
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/scopes/index.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,yEAAyE;AACzE,OAAO,EACL,iBAAiB,EACjB,YAAY,EACZ,iBAAiB,EACjB,sBAAsB,EACtB,sBAAsB,EACtB,4BAA4B,EAC5B,UAAU,EACV,WAAW,EACX,WAAW,EACX,YAAY,GACb,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE1F,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { type OidcReservedScope } from "../oidc/scope-names";
2
+ import { type ScopeDefinition } from "./scope-definition";
3
+ /**
4
+ * The OpenID Connect scopes (`OIDC_RESERVED_SCOPES`, OpenID Connect Core
5
+ * §5.4, §11) as definitions, keyed by their value: `oidcScopes.email`.
6
+ *
7
+ * Their values are reserved, so they never belong in an API server's scope
8
+ * manifest: sync your own `defineScopes()` catalogue, not these.
9
+ */
10
+ export declare const oidcScopes: {
11
+ readonly [K in OidcReservedScope]: ScopeDefinition<K>;
12
+ };
@@ -0,0 +1,23 @@
1
+ import { OIDC_RESERVED_SCOPES } from "../oidc/scope-names";
2
+ import { defineScopes } from "./scope-definition";
3
+ /** What each OpenID Connect scope allows, as a person granting it reads it. */
4
+ const OIDC_SCOPE_DESCRIPTIONS = {
5
+ openid: "Sign you in with OpenID Connect",
6
+ profile: "Read your basic profile, such as your name",
7
+ email: "Read your email address",
8
+ address: "Read your postal address",
9
+ phone: "Read your phone number",
10
+ offline_access: "Keep access while you are not using the app (refresh tokens)",
11
+ };
12
+ /**
13
+ * The OpenID Connect scopes (`OIDC_RESERVED_SCOPES`, OpenID Connect Core
14
+ * §5.4, §11) as definitions, keyed by their value: `oidcScopes.email`.
15
+ *
16
+ * Their values are reserved, so they never belong in an API server's scope
17
+ * manifest: sync your own `defineScopes()` catalogue, not these.
18
+ */
19
+ export const oidcScopes = defineScopes(Object.fromEntries(OIDC_RESERVED_SCOPES.map((scope) => [
20
+ scope,
21
+ { scope, description: OIDC_SCOPE_DESCRIPTIONS[scope] },
22
+ ])));
23
+ //# sourceMappingURL=oidc-scopes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oidc-scopes.js","sourceRoot":"","sources":["../../src/scopes/oidc-scopes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAA0B,MAAM,qBAAqB,CAAC;AACnF,OAAO,EAAE,YAAY,EAAwB,MAAM,oBAAoB,CAAC;AAExE,+EAA+E;AAC/E,MAAM,uBAAuB,GAAG;IAC9B,MAAM,EAAE,iCAAiC;IACzC,OAAO,EAAE,4CAA4C;IACrD,KAAK,EAAE,yBAAyB;IAChC,OAAO,EAAE,0BAA0B;IACnC,KAAK,EAAE,wBAAwB;IAC/B,cAAc,EAAE,8DAA8D;CAC1B,CAAC;AAEvD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,UAAU,GAA8D,YAAY,CAC/F,MAAM,CAAC,WAAW,CAChB,oBAAoB,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC;IAClC,KAAK;IACL,EAAE,KAAK,EAAE,WAAW,EAAE,uBAAuB,CAAC,KAAK,CAAC,EAAE;CACvD,CAAC,CAC0D,CAC/D,CAAC"}
@@ -0,0 +1,106 @@
1
+ /**
2
+ * OAuth 2.0 scopes as first-class values: a scope is declared once, as a
3
+ * {@link ScopeDefinition} saying what it allows, and that definition is
4
+ * what everything else takes:
5
+ *
6
+ * - `@schemavaults/openapi-operations`: `requireAuth({ requiredScopes })`,
7
+ * the OpenAPI document's `x-schemavaults-scopes` and the docs UI;
8
+ * - `@schemavaults/auth-client-sdk`: `login({ scope })` / `register()`, the
9
+ * client's `authorization_params.scope`, `sendAuthenticateRequest()`;
10
+ * - `@schemavaults/auth-server-sdk`: route guards' `required_scopes`,
11
+ * `exchangeTokenForDelegatedToken({ scope })`, and a scope manifest
12
+ * (`syncApiServerScopes({ scopes })`), whose entries definitions are.
13
+ *
14
+ * Bare scope strings are accepted wherever a definition is. This module
15
+ * (`@schemavaults/auth-common/scopes`) has no runtime dependencies, so
16
+ * client components can import a scope catalogue without pulling zod in.
17
+ */
18
+ /**
19
+ * RFC 6749 §3.3 `scope-token`: one or more printable ASCII characters other
20
+ * than space, `"` and `\`. A token's `scope` claim is a space separated list
21
+ * of them, so a required scope outside this grammar could never be granted.
22
+ */
23
+ export declare const SCOPE_TOKEN_REGEX: RegExp;
24
+ /** Whether `value` is a single RFC 6749 scope-token (e.g. `notes:read`, `email`). */
25
+ export declare function isScopeToken(value: unknown): value is string;
26
+ /**
27
+ * Longest scope value a definition may have: the most an API server may
28
+ * define on the auth server (`MAX_API_SCOPE_VALUE_LENGTH` is this value).
29
+ */
30
+ export declare const MAX_SCOPE_VALUE_LENGTH: 128;
31
+ /**
32
+ * Longest description a definition may have, once trimmed: the most a
33
+ * consent screen shows (`MAX_API_SCOPE_DESCRIPTION_LENGTH` is this value).
34
+ */
35
+ export declare const MAX_SCOPE_DESCRIPTION_LENGTH: 256;
36
+ /**
37
+ * A scope value plus what it allows. Exactly `{ scope, description }`, the
38
+ * shape of a SchemaVaults scope manifest entry, so a list of definitions can
39
+ * be handed to `syncApiServerScopes({ scopes })` from
40
+ * `@schemavaults/auth-server-sdk/api-scopes` as it is.
41
+ */
42
+ export interface ScopeDefinition<TScope extends string = string> {
43
+ /** The scope value as it appears in a token's space separated `scope` claim. */
44
+ readonly scope: TScope;
45
+ /**
46
+ * What the scope lets a token do, written for the person granting it
47
+ * ("Read your notes"): shown in API docs and, once synced, on the auth
48
+ * server's consent screen.
49
+ */
50
+ readonly description: string;
51
+ }
52
+ /** A required scope: a bare scope value, or a {@link ScopeDefinition} describing it. */
53
+ export type ScopeRequirement<TScope extends string = string> = TScope | ScopeDefinition<TScope>;
54
+ /**
55
+ * Why `value` is not a valid scope definition, or null when it is one: an
56
+ * object whose `scope` is a single RFC 6749 scope-token of at most
57
+ * {@link MAX_SCOPE_VALUE_LENGTH} characters and whose `description`, once
58
+ * trimmed, has 1 to {@link MAX_SCOPE_DESCRIPTION_LENGTH} characters (the
59
+ * rules the auth server applies to the scopes an API server defines).
60
+ * `defineScope()` throws this message; {@link isScopeDefinition} is it as a
61
+ * type guard.
62
+ */
63
+ export declare function scopeDefinitionProblem(value: unknown): string | null;
64
+ /**
65
+ * Whether `value` is a valid {@link ScopeDefinition}: see
66
+ * {@link scopeDefinitionProblem} for the rules. Every definition
67
+ * `defineScope()` returns passes it, and so does a hand-written
68
+ * `{ scope, description }` that follows the same rules.
69
+ */
70
+ export declare function isScopeDefinition(value: unknown): value is ScopeDefinition;
71
+ /** The scope value of a requirement. */
72
+ export declare function scopeValue(requirement: ScopeRequirement): string;
73
+ /** The scope values of a list of requirements, in order (empty for `undefined`). */
74
+ export declare function scopeValues(requirements: readonly ScopeRequirement[] | undefined): string[];
75
+ /**
76
+ * Declares one scope. Throws a `TypeError` naming the problem when the
77
+ * definition breaks the rules of {@link scopeDefinitionProblem} (a single
78
+ * RFC 6749 scope-token of at most 128 characters, a description of 1 to 256
79
+ * characters once trimmed); the description is stored trimmed.
80
+ *
81
+ * ```ts
82
+ * export const notesRead = defineScope({ scope: "notes:read", description: "Read your notes" });
83
+ * ```
84
+ */
85
+ export declare function defineScope<const TScope extends string>(definition: ScopeDefinition<TScope>): ScopeDefinition<TScope>;
86
+ /** The result of {@link defineScopes}: the same keys, each a frozen {@link ScopeDefinition}. */
87
+ export type DefinedScopes<T extends Readonly<Record<string, ScopeDefinition>>> = {
88
+ readonly [K in keyof T]: ScopeDefinition<T[K]["scope"]>;
89
+ };
90
+ /**
91
+ * Declares an API's scopes at once, keyed by a name of your choosing, and
92
+ * refuses a scope value listed twice:
93
+ *
94
+ * ```ts
95
+ * export const notesScopes = defineScopes({
96
+ * read: { scope: "notes:read", description: "Read your notes" },
97
+ * write: { scope: "notes:write", description: "Create and edit your notes" },
98
+ * });
99
+ *
100
+ * requireAuth({ schemes, requiredScopes: [notesScopes.read] });
101
+ * ```
102
+ *
103
+ * `Object.values(notesScopes)` lists them all, e.g. for
104
+ * `buildOpenApiDocument({ additionalScopes })` or a scope manifest.
105
+ */
106
+ export declare function defineScopes<const T extends Readonly<Record<string, ScopeDefinition>>>(definitions: T): DefinedScopes<T>;
@@ -0,0 +1,138 @@
1
+ /**
2
+ * OAuth 2.0 scopes as first-class values: a scope is declared once, as a
3
+ * {@link ScopeDefinition} saying what it allows, and that definition is
4
+ * what everything else takes:
5
+ *
6
+ * - `@schemavaults/openapi-operations`: `requireAuth({ requiredScopes })`,
7
+ * the OpenAPI document's `x-schemavaults-scopes` and the docs UI;
8
+ * - `@schemavaults/auth-client-sdk`: `login({ scope })` / `register()`, the
9
+ * client's `authorization_params.scope`, `sendAuthenticateRequest()`;
10
+ * - `@schemavaults/auth-server-sdk`: route guards' `required_scopes`,
11
+ * `exchangeTokenForDelegatedToken({ scope })`, and a scope manifest
12
+ * (`syncApiServerScopes({ scopes })`), whose entries definitions are.
13
+ *
14
+ * Bare scope strings are accepted wherever a definition is. This module
15
+ * (`@schemavaults/auth-common/scopes`) has no runtime dependencies, so
16
+ * client components can import a scope catalogue without pulling zod in.
17
+ */
18
+ /**
19
+ * RFC 6749 §3.3 `scope-token`: one or more printable ASCII characters other
20
+ * than space, `"` and `\`. A token's `scope` claim is a space separated list
21
+ * of them, so a required scope outside this grammar could never be granted.
22
+ */
23
+ export const SCOPE_TOKEN_REGEX = /^[\x21\x23-\x5B\x5D-\x7E]+$/;
24
+ /** Whether `value` is a single RFC 6749 scope-token (e.g. `notes:read`, `email`). */
25
+ export function isScopeToken(value) {
26
+ return typeof value === "string" && SCOPE_TOKEN_REGEX.test(value);
27
+ }
28
+ /**
29
+ * Longest scope value a definition may have: the most an API server may
30
+ * define on the auth server (`MAX_API_SCOPE_VALUE_LENGTH` is this value).
31
+ */
32
+ export const MAX_SCOPE_VALUE_LENGTH = 128;
33
+ /**
34
+ * Longest description a definition may have, once trimmed: the most a
35
+ * consent screen shows (`MAX_API_SCOPE_DESCRIPTION_LENGTH` is this value).
36
+ */
37
+ export const MAX_SCOPE_DESCRIPTION_LENGTH = 256;
38
+ /** A scope value shortened for an error message. */
39
+ function quoteScope(scope) {
40
+ return scope.length > 64 ? `"${scope.slice(0, 64)}…"` : `"${scope}"`;
41
+ }
42
+ /**
43
+ * Why `value` is not a valid scope definition, or null when it is one: an
44
+ * object whose `scope` is a single RFC 6749 scope-token of at most
45
+ * {@link MAX_SCOPE_VALUE_LENGTH} characters and whose `description`, once
46
+ * trimmed, has 1 to {@link MAX_SCOPE_DESCRIPTION_LENGTH} characters (the
47
+ * rules the auth server applies to the scopes an API server defines).
48
+ * `defineScope()` throws this message; {@link isScopeDefinition} is it as a
49
+ * type guard.
50
+ */
51
+ export function scopeDefinitionProblem(value) {
52
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
53
+ return "A scope definition must be an object { scope, description }";
54
+ }
55
+ const { scope, description } = value;
56
+ if (typeof scope !== "string") {
57
+ return "A scope definition's scope must be a string";
58
+ }
59
+ if (!isScopeToken(scope)) {
60
+ return `Scope ${quoteScope(scope)} is not a single RFC 6749 scope-token (printable ASCII without spaces, '"' or '\\')`;
61
+ }
62
+ if (scope.length > MAX_SCOPE_VALUE_LENGTH) {
63
+ return `Scope ${quoteScope(scope)} is ${scope.length} characters long; a scope is at most ${MAX_SCOPE_VALUE_LENGTH}`;
64
+ }
65
+ if (typeof description !== "string" || description.trim().length === 0) {
66
+ return `Scope "${scope}" needs a non-empty description`;
67
+ }
68
+ const trimmed = description.trim().length;
69
+ if (trimmed > MAX_SCOPE_DESCRIPTION_LENGTH) {
70
+ return `The description of scope "${scope}" is ${trimmed} characters long; a description is at most ${MAX_SCOPE_DESCRIPTION_LENGTH}`;
71
+ }
72
+ return null;
73
+ }
74
+ /**
75
+ * Whether `value` is a valid {@link ScopeDefinition}: see
76
+ * {@link scopeDefinitionProblem} for the rules. Every definition
77
+ * `defineScope()` returns passes it, and so does a hand-written
78
+ * `{ scope, description }` that follows the same rules.
79
+ */
80
+ export function isScopeDefinition(value) {
81
+ return scopeDefinitionProblem(value) === null;
82
+ }
83
+ /** The scope value of a requirement. */
84
+ export function scopeValue(requirement) {
85
+ return typeof requirement === "string" ? requirement : requirement.scope;
86
+ }
87
+ /** The scope values of a list of requirements, in order (empty for `undefined`). */
88
+ export function scopeValues(requirements) {
89
+ return (requirements ?? []).map(scopeValue);
90
+ }
91
+ /**
92
+ * Declares one scope. Throws a `TypeError` naming the problem when the
93
+ * definition breaks the rules of {@link scopeDefinitionProblem} (a single
94
+ * RFC 6749 scope-token of at most 128 characters, a description of 1 to 256
95
+ * characters once trimmed); the description is stored trimmed.
96
+ *
97
+ * ```ts
98
+ * export const notesRead = defineScope({ scope: "notes:read", description: "Read your notes" });
99
+ * ```
100
+ */
101
+ export function defineScope(definition) {
102
+ const problem = scopeDefinitionProblem(definition);
103
+ if (problem !== null) {
104
+ throw new TypeError(problem);
105
+ }
106
+ return Object.freeze({ scope: definition.scope, description: definition.description.trim() });
107
+ }
108
+ /**
109
+ * Declares an API's scopes at once, keyed by a name of your choosing, and
110
+ * refuses a scope value listed twice:
111
+ *
112
+ * ```ts
113
+ * export const notesScopes = defineScopes({
114
+ * read: { scope: "notes:read", description: "Read your notes" },
115
+ * write: { scope: "notes:write", description: "Create and edit your notes" },
116
+ * });
117
+ *
118
+ * requireAuth({ schemes, requiredScopes: [notesScopes.read] });
119
+ * ```
120
+ *
121
+ * `Object.values(notesScopes)` lists them all, e.g. for
122
+ * `buildOpenApiDocument({ additionalScopes })` or a scope manifest.
123
+ */
124
+ export function defineScopes(definitions) {
125
+ const seen = new Map();
126
+ const result = {};
127
+ for (const [key, definition] of Object.entries(definitions)) {
128
+ const defined = defineScope(definition);
129
+ const previous = seen.get(defined.scope);
130
+ if (previous !== undefined) {
131
+ throw new TypeError(`Scope "${defined.scope}" is defined twice (as "${previous}" and "${key}")`);
132
+ }
133
+ seen.set(defined.scope, key);
134
+ result[key] = defined;
135
+ }
136
+ return Object.freeze(result);
137
+ }
138
+ //# sourceMappingURL=scope-definition.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope-definition.js","sourceRoot":"","sources":["../../src/scopes/scope-definition.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAW,6BAA6B,CAAC;AAEvE,qFAAqF;AACrF,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AACpE,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAY,CAAC;AAEnD;;;GAGG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,GAAY,CAAC;AAsBzD,oDAAoD;AACpD,SAAS,UAAU,CAAC,KAAa;IAC/B,OAAO,KAAK,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,KAAK,GAAG,CAAC;AACvE,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,sBAAsB,CAAC,KAAc;IACnD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACxE,OAAO,6DAA6D,CAAC;I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ire form
4
+ * (`"openid notes:read"`), or a list of scope values and definitions
5
+ * (`[oidcScopes.openid, notesScopes.read]`).
6
+ */
7
+ export type ScopeInput = string | readonly ScopeRequirement[];
8
+ /** A granted scope: a token's space-delimited `scope` claim, or its values. */
9
+ export type GrantedScopeInput = string | readonly string[] | null | undefined;
10
+ /**
11
+ * The values of a scope, in order and each once: a space-delimited string
12
+ * (RFC 6749 §3.3) is split, a list is taken as it is. `null` / `undefined`
13
+ * (a token without a `scope` claim) is the empty scope.
14
+ */
15
+ export declare function parseScope(scope: GrantedScopeInput): string[];
16
+ /**
17
+ * The space-delimited wire form of a scope (RFC 6749 §3.3): its values
18
+ * joined by single spaces, in order, each once. An empty list is `""`.
19
+ *
20
+ * ```ts
21
+ * formatScope([oidcScopes.openid, notesScopes.read, "email"]); // "openid notes:read email"
22
+ * ```
23
+ */
24
+ export declare function formatScope(scope: ScopeInput): string;
25
+ /** The `required` scope values the granted scope lacks, in order. */
26
+ export declare function missingFromScope(granted: GrantedScopeInput, required: readonly ScopeRequirement[]): string[];
27
+ /**
28
+ * Whether the granted scope includes every one of the required scopes
29
+ * (values or definitions). With none required it is true, even for a token
30
+ * without a scope claim.
31
+ */
32
+ export declare function scopeIncludes(granted: GrantedScopeInput, ...required: readonly ScopeRequirement[]): boolean;
@@ -0,0 +1,42 @@
1
+ import { scopeValues } from "./scope-definition";
2
+ function splitScope(value) {
3
+ return value.split(/\s+/).filter((token) => token.length > 0);
4
+ }
5
+ function unique(values) {
6
+ return [...new Set(values)];
7
+ }
8
+ /**
9
+ * The values of a scope, in order and each once: a space-delimited string
10
+ * (RFC 6749 §3.3) is split, a list is taken as it is. `null` / `undefined`
11
+ * (a token without a `scope` claim) is the empty scope.
12
+ */
13
+ export function parseScope(scope) {
14
+ if (scope === null || scope === undefined)
15
+ return [];
16
+ return unique(typeof scope === "string" ? splitScope(scope) : scope.flatMap(splitScope));
17
+ }
18
+ /**
19
+ * The space-delimited wire form of a scope (RFC 6749 §3.3): its values
20
+ * joined by single spaces, in order, each once. An empty list is `""`.
21
+ *
22
+ * ```ts
23
+ * formatScope([oidcScopes.openid, notesScopes.read, "email"]); // "openid notes:read email"
24
+ * ```
25
+ */
26
+ export function formatScope(scope) {
27
+ return parseScope(typeof scope === "string" ? scope : scopeValues(scope)).join(" ");
28
+ }
29
+ /** The `required` scope values the granted scope lacks, in order. */
30
+ export function missingFromScope(granted, required) {
31
+ const values = new Set(parseScope(granted));
32
+ return scopeValues(required).filter((scope) => !values.has(scope));
33
+ }
34
+ /**
35
+ * Whether the granted scope includes every one of the required scopes
36
+ * (values or definitions). With none required it is true, even for a token
37
+ * without a scope claim.
38
+ */
39
+ export function scopeIncludes(granted, ...required) {
40
+ return missingFromScope(granted, required).length === 0;
41
+ }
42
+ //# sourceMappingURL=scope-string.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope-string.js","sourceRoot":"","sources":["../../src/scopes/scope-string.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAyB,MAAM,oBAAoB,CAAC;AAYxE,SAAS,UAAU,CAAC,KAAa;IAC/B,OAAO,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AAChE,CAAC;AAED,SAAS,MAAM,CAAC,MAAyB;IACvC,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;AAC9B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,KAAwB;IACjD,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,EAAE,CAAC;IACrD,OAAO,MAAM,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC;AAC3F,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAC,KAAiB;IAC3C,OAAO,UAAU,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACtF,CAAC;AAED,qEAAqE;AACrE,MAAM,UAAU,gBAAgB,CAC9B,OAA0B,EAC1B,QAAqC;IAErC,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC;IAC5C,OAAO,WAAW,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;AACrE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAC3B,OAA0B,EAC1B,GAAG,QAAqC;IAExC,OAAO,gBAAgB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC;AAC1D,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@schemavaults/auth-common",
3
3
  "description": "Types and utility functions for authentication and authorization",
4
- "version": "0.39.1",
4
+ "version": "0.41.0",
5
5
  "license": "UNLICENSED",
6
6
  "private": false,
7
7
  "repository": {
@@ -72,6 +72,11 @@
72
72
  "import": "./dist/auth-error-message-catalog.js",
73
73
  "require": "./dist/auth-error-message-catalog.js"
74
74
  },
75
+ "./scopes": {
76
+ "types": "./dist/scopes/index.d.ts",
77
+ "import": "./dist/scopes/index.js",
78
+ "require": "./dist/scopes/index.js"
79
+ },
75
80
  "./organizations": {
76
81
  "types": "./dist/organizations/index.d.ts",
77
82
  "import": "./dist/organizations/index.js",