@schemavaults/auth-common 0.40.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.
- package/dist/oidc/device-authorization/constants.d.ts +43 -0
- package/dist/oidc/device-authorization/constants.js +57 -0
- package/dist/oidc/device-authorization/constants.js.map +1 -0
- package/dist/oidc/device-authorization/device-authorization-response.d.ts +29 -0
- package/dist/oidc/device-authorization/device-authorization-response.js +35 -0
- package/dist/oidc/device-authorization/device-authorization-response.js.map +1 -0
- package/dist/oidc/device-authorization/index.d.ts +7 -0
- package/dist/oidc/device-authorization/index.js +5 -0
- package/dist/oidc/device-authorization/index.js.map +1 -0
- package/dist/oidc/device-authorization/user-code.d.ts +31 -0
- package/dist/oidc/device-authorization/user-code.js +73 -0
- package/dist/oidc/device-authorization/user-code.js.map +1 -0
- package/dist/oidc/device-authorization/verification-uri.d.ts +10 -0
- package/dist/oidc/device-authorization/verification-uri.js +25 -0
- package/dist/oidc/device-authorization/verification-uri.js.map +1 -0
- package/dist/oidc/endpoints.d.ts +1 -0
- package/dist/oidc/endpoints.js +2 -0
- package/dist/oidc/endpoints.js.map +1 -1
- package/dist/oidc/index.d.ts +2 -0
- package/dist/oidc/index.js +1 -0
- package/dist/oidc/index.js.map +1 -1
- package/dist/oidc/provider-metadata.d.ts +5 -0
- package/dist/oidc/provider-metadata.js +6 -1
- package/dist/oidc/provider-metadata.js.map +1 -1
- package/package.json +1 -1
|
@@ -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,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,kBAAkB,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;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"}
|
package/dist/oidc/endpoints.d.ts
CHANGED
|
@@ -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
|
};
|
package/dist/oidc/endpoints.js
CHANGED
|
@@ -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;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,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,CAAC;IACD,MAAM,IAAI,GAAW,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IACzE,OAAO,GAAG,IAAI,GAAG,IAAI,EAAE,CAAC;AAC1B,CAAC"}
|
package/dist/oidc/index.d.ts
CHANGED
|
@@ -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";
|
package/dist/oidc/index.js
CHANGED
|
@@ -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";
|
package/dist/oidc/index.js.map
CHANGED
|
@@ -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;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,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;;;;;;;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