@monocloud/auth-core 0.1.3 → 0.1.5
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/README.md +19 -3
- package/dist/index.cjs +101 -65
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +72 -35
- package/dist/index.mjs +75 -40
- package/dist/index.mjs.map +1 -1
- package/dist/types-hokU85Zr.d.mts +1243 -0
- package/dist/utils/index.cjs +19 -19
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.d.mts +5 -7
- package/dist/utils/index.mjs +5 -6
- package/dist/utils/index.mjs.map +1 -1
- package/dist/utils/internal.cjs +365 -23
- package/dist/utils/internal.cjs.map +1 -0
- package/dist/utils/internal.d.mts +5 -6
- package/dist/utils/internal.mjs +342 -2
- package/dist/utils/internal.mjs.map +1 -0
- package/package.json +4 -4
- package/dist/index.d.cts +0 -274
- package/dist/internal-DXHuqjJJ.mjs +0 -343
- package/dist/internal-DXHuqjJJ.mjs.map +0 -1
- package/dist/internal-DytuO03E.cjs +0 -475
- package/dist/internal-DytuO03E.cjs.map +0 -1
- package/dist/types-CnxqWHwA.d.cts +0 -481
- package/dist/types-DwJl9ZUf.d.mts +0 -481
- package/dist/utils/index.d.cts +0 -106
- package/dist/utils/internal.d.cts +0 -209
package/dist/index.d.cts
DELETED
|
@@ -1,274 +0,0 @@
|
|
|
1
|
-
import { A as ResponseTypes, C as ParResponse, D as RefreshGrantOptions, E as RefetchUserInfoOptions, M as UserinfoResponse, O as RefreshSessionOptions, S as OnSessionCreating, T as PushedAuthorizationParams, _ as Jwks, a as Authenticators, b as MonoCloudSession, c as ClientAuthMethod, d as EndSessionParameters, f as Group, g as Jwk, h as JWSAlgorithm, i as AuthenticateOptions, j as Tokens, k as ResponseModes, l as CodeChallengeMethod, m as IssuerMetadata, n as Address, o as AuthorizationParams, p as IdTokenClaims, r as AuthState, s as CallbackParams, t as AccessToken, u as DisplayOptions, v as JwsHeaderParameters, w as Prompt, x as MonoCloudUser, y as MonoCloudClientOptions } from "./types-CnxqWHwA.cjs";
|
|
2
|
-
|
|
3
|
-
//#region src/errors/monocloud-auth-base-error.d.ts
|
|
4
|
-
declare class MonoCloudAuthBaseError extends Error {}
|
|
5
|
-
//#endregion
|
|
6
|
-
//#region src/errors/monocloud-op-error.d.ts
|
|
7
|
-
declare class MonoCloudOPError extends MonoCloudAuthBaseError {
|
|
8
|
-
error: string;
|
|
9
|
-
errorDescription?: string;
|
|
10
|
-
constructor(error: string, errorDescription?: string);
|
|
11
|
-
}
|
|
12
|
-
//#endregion
|
|
13
|
-
//#region src/errors/monocloud-http-error.d.ts
|
|
14
|
-
declare class MonoCloudHttpError extends MonoCloudAuthBaseError {}
|
|
15
|
-
//#endregion
|
|
16
|
-
//#region src/errors/monocloud-token-error.d.ts
|
|
17
|
-
declare class MonoCloudTokenError extends MonoCloudAuthBaseError {}
|
|
18
|
-
//#endregion
|
|
19
|
-
//#region src/errors/monocloud-validation-error.d.ts
|
|
20
|
-
declare class MonoCloudValidationError extends MonoCloudAuthBaseError {}
|
|
21
|
-
//#endregion
|
|
22
|
-
//#region src/monocloud-oidc-client.d.ts
|
|
23
|
-
declare class MonoCloudOidcClient {
|
|
24
|
-
private readonly tenantDomain;
|
|
25
|
-
private readonly clientId;
|
|
26
|
-
private readonly clientSecret?;
|
|
27
|
-
private readonly authMethod;
|
|
28
|
-
private readonly idTokenSigningAlgorithm;
|
|
29
|
-
private jwks?;
|
|
30
|
-
private jwksCacheExpiry;
|
|
31
|
-
private jwksCacheDuration;
|
|
32
|
-
private metadata?;
|
|
33
|
-
private metadataCacheExpiry;
|
|
34
|
-
private metadataCacheDuration;
|
|
35
|
-
constructor(tenantDomain: string, clientId: string, options?: MonoCloudClientOptions);
|
|
36
|
-
/**
|
|
37
|
-
* Generates an authorization URL with specified parameters.
|
|
38
|
-
*
|
|
39
|
-
* If no values are provided for `responseType`, or `codeChallengeMethod`, they default to `code`, and `S256`, respectively.
|
|
40
|
-
*
|
|
41
|
-
* @param params Authorization URL parameters
|
|
42
|
-
*
|
|
43
|
-
* @returns Tenant's authorization url.
|
|
44
|
-
*
|
|
45
|
-
* @throws {@link MonoCloudHttpError} - Thrown if there is a network error during the request or
|
|
46
|
-
* unexpected status code during the request or a serialization error while processing the response.
|
|
47
|
-
*
|
|
48
|
-
*/
|
|
49
|
-
authorizationUrl(params: AuthorizationParams): Promise<string>;
|
|
50
|
-
/**
|
|
51
|
-
* Fetches the authorization server metadata from the .well-known endpoint.
|
|
52
|
-
* The metadata is cached for 1 minute.
|
|
53
|
-
*
|
|
54
|
-
* @param forceRefresh - If `true`, bypasses the cache and fetches fresh metadata from the server.
|
|
55
|
-
*
|
|
56
|
-
* @returns The issuer metadata for the tenant, retrieved from the OpenID Connect discovery endpoint.
|
|
57
|
-
*
|
|
58
|
-
* @throws {@link MonoCloudHttpError} - Thrown if there is a network error during the request or
|
|
59
|
-
* unexpected status code during the request or a serialization error while processing the response.
|
|
60
|
-
*
|
|
61
|
-
*/
|
|
62
|
-
getMetadata(forceRefresh?: boolean): Promise<IssuerMetadata>;
|
|
63
|
-
/**
|
|
64
|
-
* Fetches the JSON Web Keys used to sign the id token.
|
|
65
|
-
* The JWKS is cached for 1 minute.
|
|
66
|
-
*
|
|
67
|
-
* @param forceRefresh - If `true`, bypasses the cache and fetches fresh set of JWKS from the server.
|
|
68
|
-
*
|
|
69
|
-
* @returns The JSON Web Key Set containing the public keys for token verification.
|
|
70
|
-
*
|
|
71
|
-
* @throws {@link MonoCloudHttpError} - Thrown if there is a network error during the request or
|
|
72
|
-
* unexpected status code during the request or a serialization error while processing the response.
|
|
73
|
-
*
|
|
74
|
-
*/
|
|
75
|
-
getJwks(forceRefresh?: boolean): Promise<Jwks>;
|
|
76
|
-
/**
|
|
77
|
-
* Performs a pushed authorization request.
|
|
78
|
-
*
|
|
79
|
-
* @param params - Authorization Parameters
|
|
80
|
-
*
|
|
81
|
-
* @returns Response from Pushed Authorization Request (PAR) endpoint
|
|
82
|
-
*
|
|
83
|
-
* @throws {@link MonoCloudOPError} - When the request is invalid.
|
|
84
|
-
*
|
|
85
|
-
* @throws {@link MonoCloudHttpError} - Thrown if there is a network error during the request or
|
|
86
|
-
* unexpected status code during the request or a serialization error while processing the response.
|
|
87
|
-
*
|
|
88
|
-
*/
|
|
89
|
-
pushedAuthorizationRequest(params: PushedAuthorizationParams): Promise<ParResponse>;
|
|
90
|
-
/**
|
|
91
|
-
* Fetches userinfo associated with the provided access token.
|
|
92
|
-
*
|
|
93
|
-
* @param accessToken - A valid access token used to retrieve userinfo.
|
|
94
|
-
*
|
|
95
|
-
* @returns The authenticated user's claims.
|
|
96
|
-
*
|
|
97
|
-
* @throws {@link MonoCloudOPError} - When the OpenID Provider returns a standardized
|
|
98
|
-
* OAuth 2.0 error (e.g., 'invalid_token') in the 'WWW-Authenticate' header
|
|
99
|
-
* following a 401 Unauthorized response.
|
|
100
|
-
*
|
|
101
|
-
* @throws {@link MonoCloudHttpError} - Thrown if there is a network error during the request or
|
|
102
|
-
* unexpected status code during the request or a serialization error while processing the response.
|
|
103
|
-
*
|
|
104
|
-
* @throws {@link MonoCloudValidationError} - When the access token is invalid.
|
|
105
|
-
*
|
|
106
|
-
*/
|
|
107
|
-
userinfo(accessToken: string): Promise<UserinfoResponse>;
|
|
108
|
-
/**
|
|
109
|
-
* Generates OpenID end session url for signing out.
|
|
110
|
-
*
|
|
111
|
-
* Note - The `state` is added only when `postLogoutRedirectUri` is present.
|
|
112
|
-
*
|
|
113
|
-
* @param params - Parameters to build end session url
|
|
114
|
-
*
|
|
115
|
-
* @returns Tenant's end session url
|
|
116
|
-
*
|
|
117
|
-
* @throws {@link MonoCloudHttpError} - Thrown if there is a network error during the request or
|
|
118
|
-
* unexpected status code during the request or a serialization error while processing the response.
|
|
119
|
-
*
|
|
120
|
-
*/
|
|
121
|
-
endSessionUrl(params: EndSessionParameters): Promise<string>;
|
|
122
|
-
/**
|
|
123
|
-
* Exchanges an authorization code for tokens.
|
|
124
|
-
*
|
|
125
|
-
* @param code - The authorization code received from the authorization server.
|
|
126
|
-
* @param redirectUri - The redirect URI used in the initial authorization request.
|
|
127
|
-
* @param codeVerifier - Code verifier for PKCE.
|
|
128
|
-
* @param resource - Space-separated list of resources the access token should be scoped to
|
|
129
|
-
*
|
|
130
|
-
* @returns Tokens obtained by exchanging an authorization code at the token endpoint.
|
|
131
|
-
*
|
|
132
|
-
* @throws {@link MonoCloudOPError} - When the OpenID Provider returns a standardized
|
|
133
|
-
* OAuth 2.0 error response.
|
|
134
|
-
*
|
|
135
|
-
* @throws {@link MonoCloudHttpError} - Thrown if there is a network error during the request or
|
|
136
|
-
* unexpected status code during the request or a serialization error while processing the response.
|
|
137
|
-
*
|
|
138
|
-
*/
|
|
139
|
-
exchangeAuthorizationCode(code: string, redirectUri: string, codeVerifier?: string, resource?: string): Promise<Tokens>;
|
|
140
|
-
/**
|
|
141
|
-
* Exchanges a refresh token for new tokens.
|
|
142
|
-
*
|
|
143
|
-
* @param refreshToken - The refresh token used to request new tokens.
|
|
144
|
-
* @param options - Refresh grant options.
|
|
145
|
-
*
|
|
146
|
-
* @returns Tokens obtained by exchanging a refresh token at the token endpoint.
|
|
147
|
-
*
|
|
148
|
-
* @throws {@link MonoCloudOPError} - When the OpenID Provider returns a standardized
|
|
149
|
-
* OAuth 2.0 error response.
|
|
150
|
-
*
|
|
151
|
-
* @throws {@link MonoCloudHttpError} - Thrown if there is a network error during the request or
|
|
152
|
-
* unexpected status code during the request or a serialization error while processing the response.
|
|
153
|
-
*
|
|
154
|
-
*/
|
|
155
|
-
refreshGrant(refreshToken: string, options?: RefreshGrantOptions): Promise<Tokens>;
|
|
156
|
-
/**
|
|
157
|
-
* Generates a session with user and tokens by exchanging authorization code from callback params.
|
|
158
|
-
*
|
|
159
|
-
* @param code - The authorization code received from the callback
|
|
160
|
-
* @param redirectUri - The redirect URI that was used in the authorization request
|
|
161
|
-
* @param requestedScopes - A space-separated list of scopes originally requested via the `/authorize` endpoint.
|
|
162
|
-
* This is stored in the session to ensure the correct access token can be identified and refreshed during `refreshSession()`.
|
|
163
|
-
* @param resource - A space-separated list of resource indicators originally requested via the `/authorize` endpoint.
|
|
164
|
-
* Used alongside scopes to uniquely identify and refresh the specific access token associated with these resources.
|
|
165
|
-
* @param options - Options for authenticating a user with authorization code
|
|
166
|
-
*
|
|
167
|
-
* @returns The user's session containing authentication tokens and user information.
|
|
168
|
-
*
|
|
169
|
-
* @throws {@link MonoCloudValidationError} - When the token scope does not contain the openid scope,
|
|
170
|
-
* or if 'expires_in' or 'scope' is missing from the token response.
|
|
171
|
-
*
|
|
172
|
-
* @throws {@link MonoCloudOPError} - When the OpenID Provider returns a standardized
|
|
173
|
-
* OAuth 2.0 error response.
|
|
174
|
-
*
|
|
175
|
-
* @throws {@link MonoCloudTokenError} - If ID Token validation fails
|
|
176
|
-
*
|
|
177
|
-
* @throws {@link MonoCloudHttpError} - Thrown if there is a network error during the request or
|
|
178
|
-
* unexpected status code during the request or a serialization error while processing the response.
|
|
179
|
-
*
|
|
180
|
-
*/
|
|
181
|
-
authenticate(code: string, redirectUri: string, requestedScopes: string, resource?: string, options?: AuthenticateOptions): Promise<MonoCloudSession>;
|
|
182
|
-
/**
|
|
183
|
-
* Refetches user information for an existing session using the userinfo endpoint.
|
|
184
|
-
* Updates the session's user object with the latest user information while preserving existing properties.
|
|
185
|
-
*
|
|
186
|
-
* @param accessToken - Access token used to fetch the userinfo
|
|
187
|
-
* @param session - The current MonoCloudSession
|
|
188
|
-
* @param options - Userinfo refetch options
|
|
189
|
-
*
|
|
190
|
-
* @returns Updated session with the latest userinfo
|
|
191
|
-
*
|
|
192
|
-
* @throws {@link MonoCloudValidationError} - When the token scope does not contain openid scope
|
|
193
|
-
*
|
|
194
|
-
* @throws {@link MonoCloudOPError} - When the OpenID Provider returns a standardized
|
|
195
|
-
* OAuth 2.0 error response.
|
|
196
|
-
*
|
|
197
|
-
* @throws {@link MonoCloudTokenError} - If ID Token validation fails
|
|
198
|
-
*
|
|
199
|
-
* @throws {@link MonoCloudHttpError} - Thrown if there is a network error during the request or
|
|
200
|
-
* unexpected status code during the request or a serialization error while processing the response.
|
|
201
|
-
*
|
|
202
|
-
*/
|
|
203
|
-
refetchUserInfo(accessToken: AccessToken, session: MonoCloudSession, options?: RefetchUserInfoOptions): Promise<MonoCloudSession>;
|
|
204
|
-
/**
|
|
205
|
-
* Refreshes an existing session using the refresh token.
|
|
206
|
-
* This function requests new tokens using the refresh token and optionally updates user information.
|
|
207
|
-
*
|
|
208
|
-
* @param session - The current MonoCloudSession containing the refresh token
|
|
209
|
-
* @param options - Session refresh options
|
|
210
|
-
*
|
|
211
|
-
* @returns User's session containing refreshed authentication tokens and user information.
|
|
212
|
-
*
|
|
213
|
-
* @throws {@link MonoCloudValidationError} - If the refresh token is not present in the session,
|
|
214
|
-
* or if 'expires_in' or 'scope' (including the openid scope) is missing from the token response.
|
|
215
|
-
*
|
|
216
|
-
* @throws {@link MonoCloudOPError} - When the OpenID Provider returns a standardized
|
|
217
|
-
* OAuth 2.0 error response.
|
|
218
|
-
*
|
|
219
|
-
* @throws {@link MonoCloudTokenError} - If ID Token validation fails
|
|
220
|
-
*
|
|
221
|
-
* @throws {@link MonoCloudHttpError} - Thrown if there is a network error during the request or
|
|
222
|
-
* unexpected status code during the request or a serialization error while processing the response.
|
|
223
|
-
*
|
|
224
|
-
*/
|
|
225
|
-
refreshSession(session: MonoCloudSession, options?: RefreshSessionOptions): Promise<MonoCloudSession>;
|
|
226
|
-
/**
|
|
227
|
-
* Revokes an access token or refresh token, rendering it invalid for future use.
|
|
228
|
-
*
|
|
229
|
-
* @param token - The token string to be revoked
|
|
230
|
-
* @param tokenType - Hint about the token type ('access_token' or 'refresh_token')
|
|
231
|
-
*
|
|
232
|
-
* @returns If token revocation succeeded
|
|
233
|
-
*
|
|
234
|
-
* @throws {@link MonoCloudValidationError} - If token is invalid or unsupported token type
|
|
235
|
-
*
|
|
236
|
-
* @throws {@link MonoCloudOPError} - When the OpenID Provider returns a standardized
|
|
237
|
-
* OAuth 2.0 error response.
|
|
238
|
-
*
|
|
239
|
-
* @throws {@link MonoCloudHttpError} - Thrown if there is a network error during the request or
|
|
240
|
-
* unexpected status code during the request or a serialization error while processing the response.
|
|
241
|
-
*/
|
|
242
|
-
revokeToken(token: string, tokenType?: string): Promise<void>;
|
|
243
|
-
/**
|
|
244
|
-
* Validates an ID Token.
|
|
245
|
-
*
|
|
246
|
-
* @param idToken - The ID Token JWT string to validate
|
|
247
|
-
* @param jwks - Array of JSON Web Keys (JWK) used to verify the token's signature
|
|
248
|
-
* @param clockSkew - Number of seconds to adjust the current time to account for clock differences
|
|
249
|
-
* @param clockTolerance - Additional time tolerance in seconds for time-based claim validation
|
|
250
|
-
* @param maxAge - maximum authentication age in seconds
|
|
251
|
-
* @param nonce - nonce value to validate against the token's nonce claim
|
|
252
|
-
*
|
|
253
|
-
* @returns Validated ID Token claims
|
|
254
|
-
*
|
|
255
|
-
* @throws {@link MonoCloudTokenError} - If ID Token validation fails
|
|
256
|
-
*
|
|
257
|
-
*/
|
|
258
|
-
validateIdToken(idToken: string, jwks: Jwk[], clockSkew: number, clockTolerance: number, maxAge?: number, nonce?: string): Promise<IdTokenClaims>;
|
|
259
|
-
/**
|
|
260
|
-
* Decodes the payload of a JSON Web Token (JWT) and returns it as an object.
|
|
261
|
-
* **THIS METHOD DOES NOT VERIFY JWT TOKENS**.
|
|
262
|
-
*
|
|
263
|
-
* @param jwt - JWT to decode
|
|
264
|
-
*
|
|
265
|
-
* @returns Decoded payload
|
|
266
|
-
*
|
|
267
|
-
* @throws {@link MonoCloudTokenError} - If decoding fails
|
|
268
|
-
*
|
|
269
|
-
*/
|
|
270
|
-
static decodeJwt(jwt: string): IdTokenClaims;
|
|
271
|
-
}
|
|
272
|
-
//#endregion
|
|
273
|
-
export { type AccessToken, type Address, type AuthState, type AuthenticateOptions, type Authenticators, type AuthorizationParams, type CallbackParams, type ClientAuthMethod, type CodeChallengeMethod, type DisplayOptions, type EndSessionParameters, type Group, type IdTokenClaims, type IssuerMetadata, type JWSAlgorithm, type Jwk, type Jwks, type JwsHeaderParameters, MonoCloudAuthBaseError, type MonoCloudClientOptions, MonoCloudHttpError, MonoCloudOPError, MonoCloudOidcClient, type MonoCloudSession, MonoCloudTokenError, type MonoCloudUser, MonoCloudValidationError, type OnSessionCreating, type ParResponse, type Prompt, type PushedAuthorizationParams, type RefetchUserInfoOptions, type RefreshGrantOptions, type RefreshSessionOptions, type ResponseModes, type ResponseTypes, type Tokens, type UserinfoResponse };
|
|
274
|
-
//# sourceMappingURL=index.d.cts.map
|
|
@@ -1,343 +0,0 @@
|
|
|
1
|
-
//#region src/utils/internal.ts
|
|
2
|
-
/**
|
|
3
|
-
* @ignore
|
|
4
|
-
* Converts a string to a Base64URL encoded string.
|
|
5
|
-
*
|
|
6
|
-
* @param input - The string to encode.
|
|
7
|
-
*
|
|
8
|
-
* @returns The Base64URL encoded string.
|
|
9
|
-
*/
|
|
10
|
-
const toB64Url = (input) => input.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
11
|
-
/**
|
|
12
|
-
* @ignore
|
|
13
|
-
* Parses a string value into a boolean.
|
|
14
|
-
*
|
|
15
|
-
* @param value - The string value to parse.
|
|
16
|
-
*
|
|
17
|
-
* @returns `true` if "true", `false` if "false", otherwise `undefined`.
|
|
18
|
-
*/
|
|
19
|
-
const getBoolean = (value) => {
|
|
20
|
-
const v = value?.toLowerCase()?.trim();
|
|
21
|
-
if (v === "true") return true;
|
|
22
|
-
if (v === "false") return false;
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* @ignore
|
|
26
|
-
* Parses a string value into a number.
|
|
27
|
-
*
|
|
28
|
-
* @param value - The string value to parse.
|
|
29
|
-
*
|
|
30
|
-
* @returns The parsed number, or `undefined` if empty or invalid.
|
|
31
|
-
*/
|
|
32
|
-
const getNumber = (value) => {
|
|
33
|
-
const v = value?.trim();
|
|
34
|
-
if (v === void 0 || v.length === 0) return;
|
|
35
|
-
const p = parseInt(v, 10);
|
|
36
|
-
return Number.isNaN(p) ? void 0 : p;
|
|
37
|
-
};
|
|
38
|
-
/**
|
|
39
|
-
* @ignore
|
|
40
|
-
* Ensures that a string has a leading forward slash.
|
|
41
|
-
*
|
|
42
|
-
* @param val - The string to check.
|
|
43
|
-
*
|
|
44
|
-
* @returns The string with a leading slash.
|
|
45
|
-
*/
|
|
46
|
-
const ensureLeadingSlash = (val) => {
|
|
47
|
-
const v = val?.trim();
|
|
48
|
-
if (!v) return v;
|
|
49
|
-
return v.startsWith("/") ? v : `/${v}`;
|
|
50
|
-
};
|
|
51
|
-
/**
|
|
52
|
-
* @ignore
|
|
53
|
-
* Removes a trailing forward slash from a string.
|
|
54
|
-
*
|
|
55
|
-
* @param val - The string to check.
|
|
56
|
-
*
|
|
57
|
-
* @returns The string without a trailing slash.
|
|
58
|
-
*/
|
|
59
|
-
const removeTrailingSlash = (val) => {
|
|
60
|
-
const v = val?.trim();
|
|
61
|
-
if (!v) return v;
|
|
62
|
-
return v.endsWith("/") ? v.substring(0, v.length - 1) : v;
|
|
63
|
-
};
|
|
64
|
-
/**
|
|
65
|
-
* @ignore
|
|
66
|
-
* Checks if a value is present (not null, undefined, or an empty string).
|
|
67
|
-
*
|
|
68
|
-
* @param value - The value to check.
|
|
69
|
-
*
|
|
70
|
-
* @returns `true` if the value is present, `false` otherwise.
|
|
71
|
-
*/
|
|
72
|
-
const isPresent = (value) => {
|
|
73
|
-
if (typeof value === "boolean" || typeof value === "number") return true;
|
|
74
|
-
const v = value?.trim();
|
|
75
|
-
return v !== void 0 && v !== null && v.length > 0;
|
|
76
|
-
};
|
|
77
|
-
/**
|
|
78
|
-
* @ignore
|
|
79
|
-
* Checks if a URL is an absolute URL (starts with http:// or https://).
|
|
80
|
-
*
|
|
81
|
-
* @param url - The URL to check.
|
|
82
|
-
*
|
|
83
|
-
* @returns `true` if absolute, `false` otherwise.
|
|
84
|
-
*/
|
|
85
|
-
const isAbsoluteUrl = (url) => (url?.startsWith("http://") || url?.startsWith("https://")) ?? false;
|
|
86
|
-
/**
|
|
87
|
-
* @ignore
|
|
88
|
-
* Checks if two URLs have the same origin (host and port).
|
|
89
|
-
*
|
|
90
|
-
* @param url - The first URL.
|
|
91
|
-
* @param urlToCheck - The second URL to compare against.
|
|
92
|
-
*
|
|
93
|
-
* @returns `true` if they share the same origin, `false` otherwise.
|
|
94
|
-
*/
|
|
95
|
-
const isSameHost = (url, urlToCheck) => {
|
|
96
|
-
try {
|
|
97
|
-
const u = new URL(url);
|
|
98
|
-
const u2 = new URL(urlToCheck);
|
|
99
|
-
return u.origin === u2.origin;
|
|
100
|
-
} catch {
|
|
101
|
-
return false;
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
/**
|
|
105
|
-
* @ignore
|
|
106
|
-
* Converts a string to a Uint8Array using TextEncoder.
|
|
107
|
-
*
|
|
108
|
-
* @param str - The string to convert.
|
|
109
|
-
*
|
|
110
|
-
* @returns A Uint8Array representation of the string.
|
|
111
|
-
*/
|
|
112
|
-
const stringToArrayBuffer = (str) => {
|
|
113
|
-
return new TextEncoder().encode(str);
|
|
114
|
-
};
|
|
115
|
-
/**
|
|
116
|
-
* @ignore
|
|
117
|
-
* Converts an ArrayBuffer to a string using TextDecoder.
|
|
118
|
-
*
|
|
119
|
-
* @param buffer - The buffer to convert.
|
|
120
|
-
*
|
|
121
|
-
* @returns The decoded string.
|
|
122
|
-
*/
|
|
123
|
-
const arrayBufferToString = (buffer) => {
|
|
124
|
-
return new TextDecoder().decode(buffer);
|
|
125
|
-
};
|
|
126
|
-
/**
|
|
127
|
-
* @ignore
|
|
128
|
-
* Converts a Base64URL string back to a standard Base64 string with padding.
|
|
129
|
-
*
|
|
130
|
-
* @param input - The Base64URL string.
|
|
131
|
-
*
|
|
132
|
-
* @returns A standard Base64 string.
|
|
133
|
-
*/
|
|
134
|
-
const fromB64Url = (input) => {
|
|
135
|
-
let str = input;
|
|
136
|
-
if (str.length % 4 !== 0) str += "===".slice(0, 4 - str.length % 4);
|
|
137
|
-
str = str.replace(/-/g, "+").replace(/_/g, "/");
|
|
138
|
-
return str;
|
|
139
|
-
};
|
|
140
|
-
/**
|
|
141
|
-
* @ignore
|
|
142
|
-
* Decodes a Base64URL encoded string.
|
|
143
|
-
*
|
|
144
|
-
* @param input - The Base64URL string to decode.
|
|
145
|
-
*
|
|
146
|
-
* @returns The decoded plaintext string.
|
|
147
|
-
*/
|
|
148
|
-
const decodeBase64Url = (input) => atob(fromB64Url(input).replace(/\s/g, ""));
|
|
149
|
-
/**
|
|
150
|
-
* @ignore
|
|
151
|
-
* Converts a Uint8Array to a Base64URL encoded string.
|
|
152
|
-
*
|
|
153
|
-
* @param buffer - The buffer to encode.
|
|
154
|
-
*
|
|
155
|
-
* @returns The Base64URL encoded string.
|
|
156
|
-
*/
|
|
157
|
-
const arrayBufferToBase64 = (buffer) => {
|
|
158
|
-
const binary = new Uint8Array(buffer).reduce((acc, byte) => acc + String.fromCharCode(byte), "");
|
|
159
|
-
return btoa(binary).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
160
|
-
};
|
|
161
|
-
/**
|
|
162
|
-
* @ignore
|
|
163
|
-
* Gets the current Unix timestamp in seconds.
|
|
164
|
-
*
|
|
165
|
-
* @returns The current timestamp.
|
|
166
|
-
*/
|
|
167
|
-
const now = () => Math.ceil(Date.now() / 1e3);
|
|
168
|
-
const SUPPORTED_JWS_ALGS = [
|
|
169
|
-
"RS256",
|
|
170
|
-
"RS384",
|
|
171
|
-
"RS512",
|
|
172
|
-
"PS256",
|
|
173
|
-
"PS384",
|
|
174
|
-
"PS512",
|
|
175
|
-
"ES256",
|
|
176
|
-
"ES384",
|
|
177
|
-
"ES512"
|
|
178
|
-
];
|
|
179
|
-
/**
|
|
180
|
-
* Retrieves a public CryptoKey from a JWK set based on the JWS header.
|
|
181
|
-
*
|
|
182
|
-
* @param jwks - The set of JSON Web Keys.
|
|
183
|
-
* @param header - The JWS header containing the algorithm and key ID.
|
|
184
|
-
*
|
|
185
|
-
* @returns A promise that resolves to the CryptoKey.
|
|
186
|
-
*
|
|
187
|
-
* @throws If no applicable key or multiple keys are found or the algorithm is unsupported.
|
|
188
|
-
*/
|
|
189
|
-
const getPublicSigKeyFromIssuerJwks = async (jwks, header) => {
|
|
190
|
-
const { alg, kid } = header;
|
|
191
|
-
if (!SUPPORTED_JWS_ALGS.includes(alg)) throw new Error("unsupported JWS \"alg\" identifier");
|
|
192
|
-
let kty;
|
|
193
|
-
switch (alg.slice(0, 2)) {
|
|
194
|
-
case "RS":
|
|
195
|
-
case "PS":
|
|
196
|
-
kty = "RSA";
|
|
197
|
-
break;
|
|
198
|
-
case "ES":
|
|
199
|
-
kty = "EC";
|
|
200
|
-
break;
|
|
201
|
-
}
|
|
202
|
-
const { 0: jwk, length } = jwks.filter((jwk$1) => {
|
|
203
|
-
if (jwk$1.kty !== kty) return false;
|
|
204
|
-
if (kid !== void 0 && kid !== jwk$1.kid) return false;
|
|
205
|
-
if (jwk$1.alg !== void 0 && alg !== jwk$1.alg) return false;
|
|
206
|
-
if (jwk$1.use !== void 0 && jwk$1.use !== "sig") return false;
|
|
207
|
-
if (jwk$1.key_ops?.includes("verify") === false) return false;
|
|
208
|
-
switch (true) {
|
|
209
|
-
case alg === "ES256" && jwk$1.crv !== "P-256":
|
|
210
|
-
case alg === "ES384" && jwk$1.crv !== "P-384":
|
|
211
|
-
case alg === "ES512" && jwk$1.crv !== "P-521": return false;
|
|
212
|
-
}
|
|
213
|
-
return true;
|
|
214
|
-
});
|
|
215
|
-
if (length !== 1) throw new Error("error when selecting a JWT verification key, multiple applicable keys found, a \"kid\" JWT Header Parameter is required");
|
|
216
|
-
let algorithm;
|
|
217
|
-
switch (alg) {
|
|
218
|
-
case "PS256":
|
|
219
|
-
case "PS384":
|
|
220
|
-
case "PS512":
|
|
221
|
-
algorithm = {
|
|
222
|
-
name: "RSA-PSS",
|
|
223
|
-
hash: `SHA-${alg.slice(-3)}`
|
|
224
|
-
};
|
|
225
|
-
break;
|
|
226
|
-
case "RS256":
|
|
227
|
-
case "RS384":
|
|
228
|
-
case "RS512":
|
|
229
|
-
algorithm = {
|
|
230
|
-
name: "RSASSA-PKCS1-v1_5",
|
|
231
|
-
hash: `SHA-${alg.slice(-3)}`
|
|
232
|
-
};
|
|
233
|
-
break;
|
|
234
|
-
case "ES256":
|
|
235
|
-
case "ES384":
|
|
236
|
-
algorithm = {
|
|
237
|
-
name: "ECDSA",
|
|
238
|
-
namedCurve: `P-${alg.slice(-3)}`
|
|
239
|
-
};
|
|
240
|
-
break;
|
|
241
|
-
case "ES512":
|
|
242
|
-
algorithm = {
|
|
243
|
-
name: "ECDSA",
|
|
244
|
-
namedCurve: "P-521"
|
|
245
|
-
};
|
|
246
|
-
break;
|
|
247
|
-
}
|
|
248
|
-
const { ext, key_ops, use, ...k } = jwk;
|
|
249
|
-
const key = await crypto.subtle.importKey("jwk", k, algorithm, true, ["verify"]);
|
|
250
|
-
if (key.type !== "public") throw new Error("jwks_uri must only contain public keys");
|
|
251
|
-
return key;
|
|
252
|
-
};
|
|
253
|
-
const CHUNK_SIZE = 32768;
|
|
254
|
-
/**
|
|
255
|
-
* @ignore
|
|
256
|
-
* Encodes a Uint8Array or ArrayBuffer into a Base64URL string using chunked processing.
|
|
257
|
-
*
|
|
258
|
-
* @param input - The data to encode.
|
|
259
|
-
*
|
|
260
|
-
* @returns The Base64URL encoded string.
|
|
261
|
-
*/
|
|
262
|
-
const encodeBase64Url = (input) => {
|
|
263
|
-
if (input instanceof ArrayBuffer) input = new Uint8Array(input);
|
|
264
|
-
const arr = [];
|
|
265
|
-
for (let i = 0; i < input.byteLength; i += CHUNK_SIZE) arr.push(String.fromCharCode.apply(null, Array.from(new Uint8Array(input.slice(i, i + CHUNK_SIZE)))));
|
|
266
|
-
return btoa(arr.join("")).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
267
|
-
};
|
|
268
|
-
/**
|
|
269
|
-
* @ignore
|
|
270
|
-
* Generates a random Base64URL encoded string.
|
|
271
|
-
*
|
|
272
|
-
* @param length - The number of random bytes to generate.
|
|
273
|
-
*
|
|
274
|
-
* @returns A random Base64URL string.
|
|
275
|
-
*/
|
|
276
|
-
const randomBytes = (length = 32) => encodeBase64Url(crypto.getRandomValues(new Uint8Array(length)));
|
|
277
|
-
/**
|
|
278
|
-
* @ignore
|
|
279
|
-
* Checks if a value is a non-null, non-array JSON object.
|
|
280
|
-
*
|
|
281
|
-
* @param input - The value to check.
|
|
282
|
-
*
|
|
283
|
-
* @returns `true` if the value is a JSON object.
|
|
284
|
-
*/
|
|
285
|
-
const isJsonObject = (input) => {
|
|
286
|
-
if (input === null || typeof input !== "object" || Array.isArray(input)) return false;
|
|
287
|
-
return true;
|
|
288
|
-
};
|
|
289
|
-
/**
|
|
290
|
-
* @ignore
|
|
291
|
-
* Parses a space-separated string into an array of strings.
|
|
292
|
-
*
|
|
293
|
-
* @param s - The space-separated string.
|
|
294
|
-
*
|
|
295
|
-
* @returns An array of strings, or `undefined` if input is empty.
|
|
296
|
-
*/
|
|
297
|
-
const parseSpaceSeparated = (s) => s?.split(/\s+/).map((x) => x.trim()).filter(Boolean);
|
|
298
|
-
/**
|
|
299
|
-
* @ignore
|
|
300
|
-
* Parses a space-separated string into a Set of strings.
|
|
301
|
-
*
|
|
302
|
-
* @param s - The space-separated string.
|
|
303
|
-
*
|
|
304
|
-
* @returns A Set containing the unique strings.
|
|
305
|
-
*/
|
|
306
|
-
const parseSpaceSeparatedSet = (s) => {
|
|
307
|
-
if (!s) return /* @__PURE__ */ new Set();
|
|
308
|
-
return new Set(parseSpaceSeparated(s));
|
|
309
|
-
};
|
|
310
|
-
/**
|
|
311
|
-
* @ignore
|
|
312
|
-
* Compares two Sets for equality.
|
|
313
|
-
*
|
|
314
|
-
* @param a - The first Set
|
|
315
|
-
* @param b - The second Set
|
|
316
|
-
* @param strict - If `true`, requires both sets to be the same size. @defaultValue true
|
|
317
|
-
*
|
|
318
|
-
* @returns `true` if the sets are equal
|
|
319
|
-
*/
|
|
320
|
-
const setsEqual = (a, b, strict = true) => {
|
|
321
|
-
if (strict && a.size !== b.size) return false;
|
|
322
|
-
for (const v of a) if (!b.has(v)) return false;
|
|
323
|
-
return true;
|
|
324
|
-
};
|
|
325
|
-
/**
|
|
326
|
-
* Finds a specific access token in an array based on resource and scopes.
|
|
327
|
-
*
|
|
328
|
-
* @param tokens - The array of access tokens.
|
|
329
|
-
* @param resource - Space-separated resource indicators.
|
|
330
|
-
* @param scopes - Space-separated scopes.
|
|
331
|
-
*
|
|
332
|
-
* @returns The matching AccessToken, or `undefined` if not found.
|
|
333
|
-
*/
|
|
334
|
-
const findToken = (tokens, resource, scopes) => {
|
|
335
|
-
if (!Array.isArray(tokens) || tokens.length === 0) return;
|
|
336
|
-
const desiredResource = parseSpaceSeparatedSet(resource);
|
|
337
|
-
const desiredScopes = parseSpaceSeparatedSet(scopes);
|
|
338
|
-
return tokens.find((t) => setsEqual(desiredResource, parseSpaceSeparatedSet(t.resource)) && setsEqual(desiredScopes, parseSpaceSeparatedSet(t.requestedScopes)));
|
|
339
|
-
};
|
|
340
|
-
|
|
341
|
-
//#endregion
|
|
342
|
-
export { toB64Url as S, parseSpaceSeparatedSet as _, ensureLeadingSlash as a, setsEqual as b, getBoolean as c, isAbsoluteUrl as d, isJsonObject as f, parseSpaceSeparated as g, now as h, encodeBase64Url as i, getNumber as l, isSameHost as m, arrayBufferToString as n, findToken as o, isPresent as p, decodeBase64Url as r, fromB64Url as s, arrayBufferToBase64 as t, getPublicSigKeyFromIssuerJwks as u, randomBytes as v, stringToArrayBuffer as x, removeTrailingSlash as y };
|
|
343
|
-
//# sourceMappingURL=internal-DXHuqjJJ.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"internal-DXHuqjJJ.mjs","names":["SUPPORTED_JWS_ALGS: JWSAlgorithm[]","kty: string","jwk","algorithm:\n | RsaHashedImportParams\n | EcKeyImportParams\n | AlgorithmIdentifier"],"sources":["../src/utils/internal.ts"],"sourcesContent":["import type {\n AccessToken,\n Jwk,\n JWSAlgorithm,\n JwsHeaderParameters,\n} from '../types';\n\n/**\n * @ignore\n * Converts a string to a Base64URL encoded string.\n *\n * @param input - The string to encode.\n *\n * @returns The Base64URL encoded string.\n */\nexport const toB64Url = (input: string): string =>\n input.replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=+$/, '');\n\n/**\n * @ignore\n * Parses a string value into a boolean.\n *\n * @param value - The string value to parse.\n *\n * @returns `true` if \"true\", `false` if \"false\", otherwise `undefined`.\n */\nexport const getBoolean = (value?: string): boolean | undefined => {\n const v = value?.toLowerCase()?.trim();\n\n if (v === 'true') {\n return true;\n }\n\n if (v === 'false') {\n return false;\n }\n\n return undefined;\n};\n\n/**\n * @ignore\n * Parses a string value into a number.\n *\n * @param value - The string value to parse.\n *\n * @returns The parsed number, or `undefined` if empty or invalid.\n */\nexport const getNumber = (value?: string): number | undefined => {\n const v = value?.trim();\n\n if (v === undefined || v.length === 0) {\n return undefined;\n }\n\n const p = parseInt(v, 10);\n\n return Number.isNaN(p) ? undefined : p;\n};\n\n/**\n * @ignore\n * Ensures that a string has a leading forward slash.\n *\n * @param val - The string to check.\n *\n * @returns The string with a leading slash.\n */\nexport const ensureLeadingSlash = (val?: string): string => {\n const v = val?.trim();\n\n if (!v) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return v!;\n }\n\n return v.startsWith('/') ? v : `/${v}`;\n};\n\n/**\n * @ignore\n * Removes a trailing forward slash from a string.\n *\n * @param val - The string to check.\n *\n * @returns The string without a trailing slash.\n */\nexport const removeTrailingSlash = (val?: string): string => {\n const v = val?.trim();\n\n if (!v) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return v!;\n }\n\n return v.endsWith('/') ? v.substring(0, v.length - 1) : v;\n};\n\n/**\n * @ignore\n * Checks if a value is present (not null, undefined, or an empty string).\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is present, `false` otherwise.\n */\nexport const isPresent = (value?: string | number | boolean): boolean => {\n if (typeof value === 'boolean' || typeof value === 'number') {\n return true;\n }\n const v = value?.trim();\n return v !== undefined && v !== null && v.length > 0;\n};\n\n/**\n * @ignore\n * Checks if a URL is an absolute URL (starts with http:// or https://).\n *\n * @param url - The URL to check.\n *\n * @returns `true` if absolute, `false` otherwise.\n */\nexport const isAbsoluteUrl = (url: string): boolean =>\n (url?.startsWith('http://') || url?.startsWith('https://')) ?? false;\n\n/**\n * @ignore\n * Checks if two URLs have the same origin (host and port).\n *\n * @param url - The first URL.\n * @param urlToCheck - The second URL to compare against.\n *\n * @returns `true` if they share the same origin, `false` otherwise.\n */\nexport const isSameHost = (url: string, urlToCheck: string): boolean => {\n try {\n const u = new URL(url);\n const u2 = new URL(urlToCheck);\n\n return u.origin === u2.origin;\n } catch {\n return false;\n }\n};\n\n/**\n * @ignore\n * Converts a string to a Uint8Array using TextEncoder.\n *\n * @param str - The string to convert.\n *\n * @returns A Uint8Array representation of the string.\n */\nexport const stringToArrayBuffer = (str: string): Uint8Array => {\n const encoder = new TextEncoder();\n return encoder.encode(str);\n};\n\n/**\n * @ignore\n * Converts an ArrayBuffer to a string using TextDecoder.\n *\n * @param buffer - The buffer to convert.\n *\n * @returns The decoded string.\n */\nexport const arrayBufferToString = (buffer: ArrayBuffer): string => {\n const decoder = new TextDecoder();\n return decoder.decode(buffer);\n};\n\n/**\n * @ignore\n * Converts a Base64URL string back to a standard Base64 string with padding.\n *\n * @param input - The Base64URL string.\n *\n * @returns A standard Base64 string.\n */\nexport const fromB64Url = (input: string): string => {\n let str = input;\n if (str.length % 4 !== 0) {\n str += '==='.slice(0, 4 - (str.length % 4));\n }\n\n str = str.replace(/-/g, '+').replace(/_/g, '/');\n\n return str;\n};\n\n/**\n * @ignore\n * Decodes a Base64URL encoded string.\n *\n * @param input - The Base64URL string to decode.\n *\n * @returns The decoded plaintext string.\n */\nexport const decodeBase64Url = (input: string): string =>\n atob(fromB64Url(input).replace(/\\s/g, ''));\n\n/**\n * @ignore\n * Converts a Uint8Array to a Base64URL encoded string.\n *\n * @param buffer - The buffer to encode.\n *\n * @returns The Base64URL encoded string.\n */\nexport const arrayBufferToBase64 = (buffer: Uint8Array): string => {\n const bytes = new Uint8Array(buffer);\n const binary = bytes.reduce(\n (acc, byte) => acc + String.fromCharCode(byte),\n ''\n );\n return btoa(binary).replace(/=/g, '').replace(/\\+/g, '-').replace(/\\//g, '_');\n};\n\n/**\n * @ignore\n * Gets the current Unix timestamp in seconds.\n *\n * @returns The current timestamp.\n */\nexport const now = (): number => Math.ceil(Date.now() / 1000);\n\nconst SUPPORTED_JWS_ALGS: JWSAlgorithm[] = [\n 'RS256',\n 'RS384',\n 'RS512',\n 'PS256',\n 'PS384',\n 'PS512',\n 'ES256',\n 'ES384',\n 'ES512',\n];\n\n/**\n * Retrieves a public CryptoKey from a JWK set based on the JWS header.\n *\n * @param jwks - The set of JSON Web Keys.\n * @param header - The JWS header containing the algorithm and key ID.\n *\n * @returns A promise that resolves to the CryptoKey.\n *\n * @throws If no applicable key or multiple keys are found or the algorithm is unsupported.\n */\nexport const getPublicSigKeyFromIssuerJwks = async (\n jwks: Jwk[],\n header: JwsHeaderParameters\n): Promise<CryptoKey> => {\n const { alg, kid } = header;\n\n if (!SUPPORTED_JWS_ALGS.includes(alg)) {\n throw new Error('unsupported JWS \"alg\" identifier');\n }\n\n let kty: string;\n switch (alg.slice(0, 2)) {\n case 'RS': // Fall through\n case 'PS':\n kty = 'RSA';\n break;\n case 'ES':\n kty = 'EC';\n break;\n }\n\n const candidates = jwks.filter(jwk => {\n // filter keys based on the mapping of signature algorithms to Key Type\n if (jwk.kty !== kty) {\n return false;\n }\n\n // filter keys based on the JWK Key ID in the header\n if (kid !== undefined && kid !== jwk.kid) {\n return false;\n }\n\n // filter keys based on the key's declared Algorithm\n if (jwk.alg !== undefined && alg !== jwk.alg) {\n return false;\n }\n\n // filter keys based on the key's declared Public Key Use\n if (jwk.use !== undefined && jwk.use !== 'sig') {\n return false;\n }\n\n // filter keys based on the key's declared Key Operations\n if (jwk.key_ops?.includes('verify') === false) {\n return false;\n }\n\n // filter keys based on alg-specific key requirements\n switch (true) {\n case alg === 'ES256' && jwk.crv !== 'P-256': // Fall through\n case alg === 'ES384' && jwk.crv !== 'P-384': // Fall through\n case alg === 'ES512' && jwk.crv !== 'P-521': // Fall through\n return false;\n }\n\n return true;\n });\n\n const { 0: jwk, length } = candidates;\n\n if (length !== 1) {\n throw new Error(\n 'error when selecting a JWT verification key, multiple applicable keys found, a \"kid\" JWT Header Parameter is required'\n );\n }\n\n let algorithm:\n | RsaHashedImportParams\n | EcKeyImportParams\n | AlgorithmIdentifier;\n\n switch (alg) {\n case 'PS256': // Fall through\n case 'PS384': // Fall through\n case 'PS512':\n algorithm = { name: 'RSA-PSS', hash: `SHA-${alg.slice(-3)}` };\n break;\n case 'RS256': // Fall through\n case 'RS384': // Fall through\n case 'RS512':\n algorithm = { name: 'RSASSA-PKCS1-v1_5', hash: `SHA-${alg.slice(-3)}` };\n break;\n case 'ES256': // Fall through\n case 'ES384':\n algorithm = { name: 'ECDSA', namedCurve: `P-${alg.slice(-3)}` };\n break;\n case 'ES512':\n algorithm = { name: 'ECDSA', namedCurve: 'P-521' };\n break;\n }\n\n const { ext, key_ops, use, ...k } = jwk;\n\n const key = await crypto.subtle.importKey('jwk', k, algorithm, true, [\n 'verify',\n ]);\n\n if (key.type !== 'public') {\n throw new Error('jwks_uri must only contain public keys');\n }\n\n return key;\n};\n\nconst CHUNK_SIZE = 0x8000;\n\n/**\n * @ignore\n * Encodes a Uint8Array or ArrayBuffer into a Base64URL string using chunked processing.\n *\n * @param input - The data to encode.\n *\n * @returns The Base64URL encoded string.\n */\nexport const encodeBase64Url = (input: Uint8Array | ArrayBuffer): string => {\n if (input instanceof ArrayBuffer) {\n // eslint-disable-next-line no-param-reassign\n input = new Uint8Array(input);\n }\n\n const arr = [];\n for (let i = 0; i < input.byteLength; i += CHUNK_SIZE) {\n arr.push(\n String.fromCharCode.apply(\n null,\n Array.from(new Uint8Array(input.slice(i, i + CHUNK_SIZE)))\n )\n );\n }\n return btoa(arr.join(''))\n .replace(/=/g, '')\n .replace(/\\+/g, '-')\n .replace(/\\//g, '_');\n};\n\n/**\n * @ignore\n * Generates a random Base64URL encoded string.\n *\n * @param length - The number of random bytes to generate.\n *\n * @returns A random Base64URL string.\n */\nexport const randomBytes = (length = 32): string =>\n encodeBase64Url(crypto.getRandomValues(new Uint8Array(length)));\n\n/**\n * @ignore\n * Checks if a value is a non-null, non-array JSON object.\n *\n * @param input - The value to check.\n *\n * @returns `true` if the value is a JSON object.\n */\nexport const isJsonObject = <T>(input: unknown): input is T => {\n if (input === null || typeof input !== 'object' || Array.isArray(input)) {\n return false;\n }\n\n return true;\n};\n\n/**\n * @ignore\n * Parses a space-separated string into an array of strings.\n *\n * @param s - The space-separated string.\n *\n * @returns An array of strings, or `undefined` if input is empty.\n */\nexport const parseSpaceSeparated = (s?: string): string[] | undefined =>\n s\n ?.split(/\\s+/)\n .map(x => x.trim())\n .filter(Boolean);\n\n/**\n * @ignore\n * Parses a space-separated string into a Set of strings.\n *\n * @param s - The space-separated string.\n *\n * @returns A Set containing the unique strings.\n */\nexport const parseSpaceSeparatedSet = (s?: string): Set<string> => {\n if (!s) {\n return new Set();\n }\n\n return new Set(parseSpaceSeparated(s));\n};\n\n/**\n * @ignore\n * Compares two Sets for equality.\n *\n * @param a - The first Set\n * @param b - The second Set\n * @param strict - If `true`, requires both sets to be the same size. @defaultValue true\n *\n * @returns `true` if the sets are equal\n */\nexport const setsEqual = (\n a: Set<string>,\n b: Set<string>,\n strict = true\n): boolean => {\n if (strict && a.size !== b.size) {\n return false;\n }\n\n for (const v of a) {\n if (!b.has(v)) {\n return false;\n }\n }\n\n return true;\n};\n\n/**\n * Finds a specific access token in an array based on resource and scopes.\n *\n * @param tokens - The array of access tokens.\n * @param resource - Space-separated resource indicators.\n * @param scopes - Space-separated scopes.\n *\n * @returns The matching AccessToken, or `undefined` if not found.\n */\nexport const findToken = (\n tokens?: AccessToken[],\n resource?: string,\n scopes?: string\n): AccessToken | undefined => {\n if (!Array.isArray(tokens) || tokens.length === 0) {\n return undefined;\n }\n\n const desiredResource = parseSpaceSeparatedSet(resource);\n const desiredScopes = parseSpaceSeparatedSet(scopes);\n\n return tokens.find(\n t =>\n setsEqual(desiredResource, parseSpaceSeparatedSet(t.resource)) &&\n setsEqual(desiredScopes, parseSpaceSeparatedSet(t.requestedScopes))\n );\n};\n"],"mappings":";;;;;;;;;AAeA,MAAa,YAAY,UACvB,MAAM,QAAQ,OAAO,IAAI,CAAC,QAAQ,OAAO,IAAI,CAAC,QAAQ,OAAO,GAAG;;;;;;;;;AAUlE,MAAa,cAAc,UAAwC;CACjE,MAAM,IAAI,OAAO,aAAa,EAAE,MAAM;AAEtC,KAAI,MAAM,OACR,QAAO;AAGT,KAAI,MAAM,QACR,QAAO;;;;;;;;;;AAcX,MAAa,aAAa,UAAuC;CAC/D,MAAM,IAAI,OAAO,MAAM;AAEvB,KAAI,MAAM,UAAa,EAAE,WAAW,EAClC;CAGF,MAAM,IAAI,SAAS,GAAG,GAAG;AAEzB,QAAO,OAAO,MAAM,EAAE,GAAG,SAAY;;;;;;;;;;AAWvC,MAAa,sBAAsB,QAAyB;CAC1D,MAAM,IAAI,KAAK,MAAM;AAErB,KAAI,CAAC,EAEH,QAAO;AAGT,QAAO,EAAE,WAAW,IAAI,GAAG,IAAI,IAAI;;;;;;;;;;AAWrC,MAAa,uBAAuB,QAAyB;CAC3D,MAAM,IAAI,KAAK,MAAM;AAErB,KAAI,CAAC,EAEH,QAAO;AAGT,QAAO,EAAE,SAAS,IAAI,GAAG,EAAE,UAAU,GAAG,EAAE,SAAS,EAAE,GAAG;;;;;;;;;;AAW1D,MAAa,aAAa,UAA+C;AACvE,KAAI,OAAO,UAAU,aAAa,OAAO,UAAU,SAC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