@monocloud/auth-core 0.1.4 → 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.
@@ -1,481 +0,0 @@
1
- //#region src/types.d.ts
2
- /** Supported Response Types */
3
- type ResponseTypes = 'code' | 'token' | 'id_token' | 'id_token token' | 'code id_token' | 'code token' | 'code id_token token';
4
- /** Supported PKCE code challenge methods */
5
- type CodeChallengeMethod = 'plain' | 'S256';
6
- /** Display options */
7
- type DisplayOptions = 'page' | 'popup' | 'touch' | 'wap';
8
- /** Allowed Response Modes */
9
- type ResponseModes = 'form_post' | 'query' | 'fragment';
10
- /** Valid prompt parameter values */
11
- type Prompt = 'none' | 'login' | 'consent' | 'select_account' | 'create';
12
- /** Parameters for creating Authorization URL */
13
- interface AuthorizationParams {
14
- /** A random string used to prevent CSRF attacks */
15
- state?: string;
16
- /** Space-separated list of scopes requested from the authorization server */
17
- scopes?: string;
18
- /** The URI to redirect the user to after successful sign in */
19
- redirectUri?: string;
20
- /**
21
- * The desired response type from the authorization server.
22
- * - `code`: Authorization code flow.
23
- * - `token`: Implicit flow.
24
- * - `id_token`: Implicit flow with ID token.
25
- * - `id_token token`: Implicit flow with ID token and access token.
26
- * - `code id_token`: Authorization code flow with ID token.
27
- * - `code token`: Authorization code flow with access token.
28
- * - `code id_token token`: Authorization code flow with ID token and access token.
29
- */
30
- responseType?: ResponseTypes;
31
- /** A cryptographic hash used for proof key for code exchange (PKCE). */
32
- codeChallenge?: string;
33
- /**
34
- * The method used to generate the code challenge, either `plain` or `S256`.
35
- */
36
- codeChallengeMethod?: CodeChallengeMethod;
37
- /** A hint to the authorization server about the desired authenticator the client wishes to authenticate the user with */
38
- authenticatorHint?: Authenticators;
39
- /** Maximum allowed time in seconds since the last End-User authentication. */
40
- maxAge?: number;
41
- /** A hint to the authorization server about the user's identifier */
42
- loginHint?: string;
43
- /** A signed JWT containing the authorization request parameters */
44
- request?: string;
45
- /**
46
- * The response mode for the authorization response.
47
- * - `form_post`: Form-encoded POST request.
48
- * - `query`: URI query parameters.
49
- * - `fragment`: URI fragment.
50
- */
51
- responseMode?: ResponseModes;
52
- /** An array of authentication context class references (ACRs). */
53
- acrValues?: string[];
54
- /** A random string used to associate to the ID token to prevent replay attacks */
55
- nonce?: string;
56
- /** User's preferred languages and scripts for the user interface */
57
- uiLocales?: string;
58
- /** The desired user interface mode */
59
- display?: DisplayOptions;
60
- /**
61
- * The desired authentication behaviour.
62
- * - `none`: User is not prompted to sign in.
63
- * - `login`: Prompt the user to log in even if the user is already authenticated.
64
- * - `consent`: Prompt the user for consent.
65
- * - `select_account`: Prompt the user to sign in.
66
- * - `create`: Prompt the user to sign up.
67
- */
68
- prompt?: Prompt;
69
- /** The request uri obtained from pushed authorization request. When this parameter is set, all other properties are ignored */
70
- requestUri?: string;
71
- /** Space-separated list of resources the access token should be scoped to */
72
- resource?: string;
73
- }
74
- /** Defines the parameters received in the callback URL after authorization */
75
- interface CallbackParams {
76
- /** State received from the authorization server */
77
- state?: string;
78
- /** Error message specifying the cause of authentication failure */
79
- error?: string;
80
- /** Explanation of the reason for authentication failure */
81
- errorDescription?: string;
82
- /** Authorization code received from the callback */
83
- code?: string;
84
- /** Access token received from the callback */
85
- accessToken?: string;
86
- /** Expiry of the access token in seconds */
87
- expiresIn?: number;
88
- /** ID token received from the callback */
89
- idToken?: string;
90
- /** Refresh token received from the callback */
91
- refreshToken?: string;
92
- /** A string that represents the End-User's login state. The `sessionState` can be used to track the user's session in the frontend */
93
- sessionState?: string;
94
- }
95
- /** Represents a JSON Web Key (JWK) */
96
- interface Jwk {
97
- kty: string;
98
- alg?: string;
99
- key_ops?: string[];
100
- ext?: boolean;
101
- use?: string;
102
- x5c?: string[];
103
- x5t?: string;
104
- 'x5t#S256'?: string;
105
- x5u?: string;
106
- kid?: string;
107
- crv?: string;
108
- d?: string;
109
- dp?: string;
110
- dq?: string;
111
- e?: string;
112
- k?: string;
113
- n?: string;
114
- oth?: {
115
- d?: string;
116
- r?: string;
117
- t?: string;
118
- }[];
119
- p?: string;
120
- q?: string;
121
- qi?: string;
122
- x?: string;
123
- y?: string;
124
- }
125
- /** A set of public JSON Web Keys that are used to verify JSON Web Tokens */
126
- interface Jwks {
127
- /** List of JWKs in this JWKS */
128
- keys: Jwk[];
129
- }
130
- type KnownKeys<T> = { [K in keyof T]: string extends K ? never : number extends K ? never : K } extends { [_ in keyof T]: infer U } ? object extends U ? never : U : never;
131
- type Override<T1, T2> = Omit<T1, keyof Omit<T2, keyof KnownKeys<T2>>> & T2;
132
- /**
133
- * Address type
134
- */
135
- type Address<ExtendedAddress extends object = Record<string, unknown>> = Override<{
136
- formatted?: string;
137
- street_address?: string;
138
- locality?: string;
139
- region?: string;
140
- postal_code?: string;
141
- country?: string;
142
- }, ExtendedAddress>;
143
- /**
144
- * Userinfo response type
145
- */
146
- type UserinfoResponse<UserInfo extends object = Record<string, unknown>, ExtendedAddress extends object = Record<string, unknown>> = Override<{
147
- sub: string;
148
- groups?: Group[];
149
- name?: string;
150
- given_name?: string;
151
- family_name?: string;
152
- middle_name?: string;
153
- nickname?: string;
154
- preferred_username?: string;
155
- profile?: string;
156
- picture?: string;
157
- website?: string;
158
- email?: string;
159
- email_verified?: boolean;
160
- gender?: string;
161
- birthdate?: string;
162
- zoneinfo?: string;
163
- locale?: string;
164
- phone_number?: string;
165
- phone_number_verified?: boolean;
166
- updated_at?: number;
167
- address?: Address<ExtendedAddress>;
168
- }, UserInfo>;
169
- /** User's group type. The group can be a group object with `id` and `name` or group name or group id */
170
- type Group = {
171
- id: string;
172
- name: string;
173
- } | string;
174
- /** Represents a MonoCloudUser */
175
- interface MonoCloudUser extends UserinfoResponse {
176
- amr?: string[];
177
- idp?: string;
178
- }
179
- interface AccessToken {
180
- /**
181
- * The access token associated with the session.
182
- */
183
- accessToken: string;
184
- /**
185
- * The expiration timestamp of the access token (in epoch).
186
- */
187
- accessTokenExpiration: number;
188
- /**
189
- * The scopes granted by the access token.
190
- */
191
- scopes: string;
192
- /**
193
- * Optional. The resource associated with the access token.
194
- */
195
- resource?: string;
196
- /**
197
- * Optional. The requested scopes.
198
- */
199
- requestedScopes?: string;
200
- }
201
- /**
202
- * Represents a session containing user information, tokens, and additional custom properties.
203
- */
204
- interface MonoCloudSession {
205
- /**
206
- * Information about the authenticated user, typically claims obtained from an ID token or the 'userinfo' endpoint.
207
- */
208
- user: MonoCloudUser;
209
- /**
210
- * Optional. The ID token associated with the session.
211
- */
212
- idToken?: string;
213
- authorizedScopes?: string;
214
- /**
215
- * Optional. The access tokens associated with the session.
216
- */
217
- accessTokens?: AccessToken[];
218
- /**
219
- * Optional. The refresh token associated with the session.
220
- */
221
- refreshToken?: string;
222
- /**
223
- * Additional custom properties that can be added to the session.
224
- */
225
- [key: string]: unknown;
226
- }
227
- /** Claims obtained from ID token */
228
- interface IdTokenClaims extends UserinfoResponse {
229
- acr?: string;
230
- amr?: string[];
231
- at_hash?: string;
232
- aud: string | string[];
233
- auth_time?: number;
234
- azp?: string;
235
- c_hash?: string;
236
- exp: number;
237
- iat: number;
238
- iss: string;
239
- nonce?: string;
240
- s_hash?: string;
241
- sub: string;
242
- [key: string]: unknown;
243
- }
244
- /** Token endpoint response */
245
- interface Tokens {
246
- /** Access token */
247
- access_token: string;
248
- /** Refresh token */
249
- refresh_token?: string;
250
- /** ID token */
251
- id_token?: string;
252
- /** Scopes requested */
253
- scope?: string;
254
- /** Access token expiry in seconds */
255
- expires_in?: number;
256
- /** Type of access token */
257
- token_type?: string;
258
- }
259
- /**
260
- * Possible values for the authenticators.
261
- */
262
- type Authenticators = 'password' | 'passkey' | 'email' | 'phone' | 'google' | 'apple' | 'facebook' | 'microsoft' | 'github' | 'gitlab' | 'discord' | 'twitter' | 'linkedin' | 'xero';
263
- type JWSAlgorithm = 'RS256' | 'RS384' | 'RS512' | 'PS256' | 'PS384' | 'PS512' | 'ES256' | 'ES384' | 'ES512';
264
- interface JwsHeaderParameters {
265
- alg: JWSAlgorithm;
266
- kid?: string;
267
- typ?: string;
268
- crit?: string[];
269
- jwk?: Jwk;
270
- }
271
- /** Stores various parameters used in the authentication request */
272
- interface AuthState {
273
- /**
274
- * A unique value used to maintain state between the sign-in request and the callback.
275
- */
276
- state: string;
277
- /**
278
- * A unique value used to prevent replay attacks in OAuth flows.
279
- */
280
- nonce: string;
281
- /**
282
- * Optional. A code verifier used in PKCE (Proof Key for Code Exchange) flow.
283
- */
284
- codeVerifier?: string;
285
- /**
286
- * Optional. The maximum age (in seconds) of the session.
287
- */
288
- maxAge?: number;
289
- /**
290
- * Optional. Space-separated list of resources to scope the access token to
291
- */
292
- resource?: string;
293
- /**
294
- * Space-separated list of scopes to request
295
- */
296
- scopes: string;
297
- }
298
- /** Parameters for creating the sign out URL. */
299
- interface EndSessionParameters {
300
- /** The ID token of the user to be used to hint the user signing out */
301
- idToken?: string;
302
- /** The URL the authorization server should redirect the user to after a successful sign out. This URL has to be registered in the client's sign out URL section. */
303
- postLogoutRedirectUri?: string;
304
- /** A random string to be sent to the authorization server when the `postLogoutRedirectUri` is set. */
305
- state?: string;
306
- }
307
- /** Authorization server metadata */
308
- interface IssuerMetadata {
309
- issuer: string;
310
- jwks_uri: string;
311
- authorization_endpoint: string;
312
- token_endpoint: string;
313
- userinfo_endpoint: string;
314
- end_session_endpoint: string;
315
- check_session_iframe: string;
316
- revocation_endpoint: string;
317
- introspection_endpoint: string;
318
- device_authorization_endpoint: string;
319
- pushed_authorization_request_endpoint?: string;
320
- frontchannel_logout_supported: boolean;
321
- frontchannel_logout_session_supported: boolean;
322
- backchannel_logout_supported: boolean;
323
- backchannel_logout_session_supported: boolean;
324
- scopes_supported: string[];
325
- claims_supported: string[];
326
- grant_types_supported: string[];
327
- response_types_supported: string[];
328
- response_modes_supported: string[];
329
- token_endpoint_auth_methods_supported: string[];
330
- id_token_signing_alg_values_supported: string[];
331
- subject_types_supported: string[];
332
- code_challenge_methods_supported: string[];
333
- request_parameter_supported: boolean;
334
- request_uri_parameter_supported: boolean;
335
- require_pushed_authorization_requests: boolean;
336
- request_object_signing_alg_values_supported: string[];
337
- }
338
- interface RefreshGrantOptions {
339
- /**
340
- * Space-separated list of resources to scope the access token to
341
- */
342
- resource?: string;
343
- /**
344
- * Space-separated list of scopes to request
345
- */
346
- scopes?: string;
347
- }
348
- /** Options used for authenticating a user with authorization code */
349
- interface AuthenticateOptions {
350
- /** The PKCE Code verifier used for authentication */
351
- codeVerifier?: string;
352
- /** When enabled, the userinfo is fetched and populated into the user object. @defaultValue false */
353
- fetchUserInfo?: boolean;
354
- /** Whether to validate the ID token or not. @defaultValue true */
355
- validateIdToken?: boolean;
356
- /** Jwks to validate the ID token with. JWKS is fetched from the authorization server if `jwks` is not provided. */
357
- jwks?: Jwks;
358
- /** Nonce to be validated against the claims from the ID token */
359
- idTokenNonce?: string;
360
- /** Allowed max age in seconds */
361
- idTokenMaxAge?: number;
362
- /** Used to adjust the current time to align with the authorization server time */
363
- idTokenClockSkew?: number;
364
- /** Allowed clock tolerance when checking date-time claims */
365
- idTokenClockTolerance?: number;
366
- /**
367
- * List of ID token claims to remove.
368
- */
369
- filteredIdTokenClaims?: string[];
370
- /**
371
- * A callback function invoked before creating or updating the user session.
372
- */
373
- onSessionCreating?: OnSessionCreating;
374
- }
375
- /** Options for refreshing MonoCloudSession */
376
- interface RefreshSessionOptions {
377
- /** When enabled, the userinfo is fetched and populated into the user object. @defaultValue false */
378
- fetchUserInfo?: boolean;
379
- /** Whether to validate the ID token or not. @defaultValue true */
380
- validateIdToken?: boolean;
381
- /** Jwks to validate the ID token with. JWKS is fetched from the authorization server if `jwks` is not provided. */
382
- jwks?: Jwks;
383
- /** Used to adjust the current time to align with the authorization server time */
384
- idTokenClockSkew?: number;
385
- /** Allowed clock tolerance when checking date-time claims */
386
- idTokenClockTolerance?: number;
387
- /** Options for the refresh grant */
388
- refreshGrantOptions?: RefreshGrantOptions;
389
- /**
390
- * List of ID token claims to remove.
391
- */
392
- filteredIdTokenClaims?: string[];
393
- /**
394
- * A callback function invoked before creating or updating the user session.
395
- */
396
- onSessionCreating?: OnSessionCreating;
397
- }
398
- /** Options for refetching userinfo */
399
- interface RefetchUserInfoOptions {
400
- /**
401
- * A callback function invoked before creating or updating the user session.
402
- */
403
- onSessionCreating?: OnSessionCreating;
404
- }
405
- /** Client authentication methods supported */
406
- type ClientAuthMethod = 'client_secret_basic' | 'client_secret_post' | 'client_secret_jwt' | 'private_key_jwt';
407
- /** Parameters for Pushed Authorization Request (PAR) */
408
- type PushedAuthorizationParams = Omit<AuthorizationParams, 'requestUri'>;
409
- /** Options to initialize the MonoCloudClient */
410
- interface MonoCloudClientOptions {
411
- /**
412
- * Client secret used for authentication.
413
- *
414
- * When the client authentication method is `client_secret_jwt` and a plain-text secret is provided,
415
- * the default signing algorithm is `HS256`.
416
- *
417
- * To use a different algorithm, supply a symmetric JSON Web Key (JWK) object (`kty = "oct"`)
418
- * that specifies the desired algorithm in its `alg` property.
419
- */
420
- clientSecret?: string | Jwk;
421
- /** Client authentication method */
422
- clientAuthMethod?: ClientAuthMethod;
423
- /** ID token signing algorithm. @defaultValue - RS256 */
424
- idTokenSigningAlgorithm?: JWSAlgorithm;
425
- /**
426
- * Jwks Cache Duration
427
- *
428
- * Time in seconds to cache the JWKS document after it is fetched
429
- *
430
- * @defaultValue 60
431
- *
432
- * */
433
- jwksCacheDuration?: number;
434
- /**
435
- * Metadata Cache Duration
436
- *
437
- * Time in seconds to cache the metadata document after it is fetched.
438
- *
439
- * @defaultValue 60
440
- * */
441
- metadataCacheDuration?: number;
442
- }
443
- /**
444
- * Response from a Pushed Authorization Request (PAR) endpoint.
445
- */
446
- interface ParResponse {
447
- /**
448
- * URI reference for the pushed authorization request.
449
- */
450
- request_uri: string;
451
- /**
452
- * Request URI lifetime in seconds.
453
- */
454
- expires_in: number;
455
- }
456
- /**
457
- * Defines a callback function to be executed when a new session is being created or updated.
458
- * This function receives parameters related to the session being created,
459
- * including the session object itself, optional ID token and user information claims.
460
- *
461
- * @param session - The Session object being created.
462
- * @param idToken - Optional. Claims from the ID token received during authentication.
463
- * @param userInfo - Optional. Claims from the user information received during authentication.
464
- * @returns A Promise that resolves when the operation is completed, or void.
465
- */
466
- type OnSessionCreating = (
467
- /**
468
- * The Session object being created.
469
- */
470
- session: MonoCloudSession,
471
- /**
472
- * Optional. Claims from the ID token received during authentication.
473
- */
474
- idToken?: Partial<IdTokenClaims>,
475
- /**
476
- * Optional. Claims from the user information received during authentication.
477
- */
478
- userInfo?: UserinfoResponse) => Promise<void> | void;
479
- //#endregion
480
- export { ResponseTypes as A, ParResponse as C, RefreshGrantOptions as D, RefetchUserInfoOptions as E, UserinfoResponse as M, RefreshSessionOptions as O, OnSessionCreating as S, PushedAuthorizationParams as T, Jwks as _, Authenticators as a, MonoCloudSession as b, ClientAuthMethod as c, EndSessionParameters as d, Group as f, Jwk as g, JWSAlgorithm as h, AuthenticateOptions as i, Tokens as j, ResponseModes as k, CodeChallengeMethod as l, IssuerMetadata as m, Address as n, AuthorizationParams as o, IdTokenClaims as p, AuthState as r, CallbackParams as s, AccessToken as t, DisplayOptions as u, JwsHeaderParameters as v, Prompt as w, MonoCloudUser as x, MonoCloudClientOptions as y };
481
- //# sourceMappingURL=types-D3lVLgLQ.d.mts.map
@@ -1,105 +0,0 @@
1
- import { b as MonoCloudSession, p as IdTokenClaims, r as AuthState, s as CallbackParams, x as MonoCloudUser } from "../types-BAE9nCpJ.cjs";
2
-
3
- //#region src/utils/index.d.ts
4
- /**
5
- * Parses callback parameters from a URL, a URLSearchParams object, or a query string.
6
- */
7
- declare const parseCallbackParams: (queryOrUrl: string | URL | URLSearchParams) => CallbackParams;
8
- /**
9
- * Encrypts a given string using a secret with AES-GCM.
10
- *
11
- * @param data - The plaintext data to encrypt.
12
- * @param secret - The secret used to derive the encryption key.
13
- * @returns Base64-encoded ciphertext.
14
- */
15
- declare const encrypt: (data: string, secret: string) => Promise<string>;
16
- /**
17
- * Decrypts an encrypted string using a secret with AES-GCM.
18
- *
19
- * @param encrypted - The ciphertext to decrypt.
20
- * @param secret - The secret used to derive the decryption key.
21
- *
22
- * @returns Decrypted plaintext string or undefined if decryption fails.
23
- */
24
- declare const decrypt: (encrypted: string, secret: string) => Promise<string | undefined>;
25
- /**
26
- * Encrypts a MonoCloud session object with a secret and optional time-to-live (TTL).
27
- *
28
- * @param session - The session object to encrypt.
29
- * @param secret - The secret used for encryption.
30
- * @param ttl - Optional time-to-live in seconds, after which the session expires.
31
- * @returns Encrypted session string.
32
- */
33
- declare const encryptSession: (session: MonoCloudSession, secret: string, ttl?: number) => Promise<string>;
34
- /**
35
- * Decrypts an encrypted MonoCloud session.
36
- *
37
- * @param encryptedSession - The encrypted session string to decrypt.
38
- * @param secret - The secret used for decryption.
39
- *
40
- * @returns Session object on success.
41
- *
42
- * @throws If decryption fails or the session has expired
43
- */
44
- declare const decryptSession: (encryptedSession: string, secret: string) => Promise<MonoCloudSession>;
45
- /**
46
- * Encrypts an AuthState object with a secret and optional time-to-live (TTL).
47
- *
48
- * @param authState - A type that extends the AuthState interface.
49
- * @param secret - The secret used for encryption.
50
- * @param ttl - Optional time-to-live in seconds, after which the auth state expires.
51
- *
52
- * @returns Encrypted auth state string.
53
- */
54
- declare const encryptAuthState: <T extends AuthState>(authState: T, secret: string, ttl?: number) => Promise<string>;
55
- /**
56
- * Decrypts an encrypted AuthState.
57
- *
58
- * @param encryptedAuthState - The encrypted auth state string to decrypt.
59
- * @param secret - The secret used for decryption.
60
- *
61
- * @returns State object on success
62
- *
63
- * @throws If decryption fails or the auth state has expired
64
- *
65
- */
66
- declare const decryptAuthState: <T extends AuthState>(encryptedAuthState: string, secret: string) => Promise<T>;
67
- /**
68
- * Checks if a user is a member of a specified group or groups.
69
- *
70
- * @param user - The user.
71
- * @param groups - An array of group names or IDs to check membership against.
72
- * @param groupsClaim - The claim in the user object that contains groups.
73
- * @param matchAll - If `true`, requires the user to be in all specified groups; if `false`, checks if the user is in at least one of the groups.
74
- *
75
- * @returns `true` if the user is in the specified groups, `false` otherwise.
76
- */
77
- declare const isUserInGroup: (user: MonoCloudUser | IdTokenClaims, groups: string[], groupsClaim?: string, matchAll?: boolean) => boolean;
78
- /**
79
- * Generates a random state string.
80
- */
81
- declare const generateState: () => string;
82
- /**
83
- * Generates a PKCE (Proof Key for Code Exchange) code verifier and code challenge.
84
- *
85
- */
86
- declare const generatePKCE: () => Promise<{
87
- codeVerifier: string;
88
- codeChallenge: string;
89
- }>;
90
- /**
91
- * Generates a random nonce string.
92
- */
93
- declare const generateNonce: () => string;
94
- /**
95
- * @ignore
96
- * Merges multiple arrays of strings, removing duplicates.
97
- *
98
- * @param args - List of arrays to merge
99
- *
100
- * @returns A new array containing unique strings from both input arrays, or `undefined` if both inputs are `undefined`.
101
- */
102
- declare const mergeArrays: (...args: (string[] | undefined)[]) => string[] | undefined;
103
- //#endregion
104
- export { decrypt, decryptAuthState, decryptSession, encrypt, encryptAuthState, encryptSession, generateNonce, generatePKCE, generateState, isUserInGroup, mergeArrays, parseCallbackParams };
105
- //# sourceMappingURL=index.d.cts.map