@monocloud/auth-node-core 0.0.0-canary-20251223204113
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/LICENSE +21 -0
- package/README.md +143 -0
- package/dist/index.cjs +1105 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +676 -0
- package/dist/index.d.mts +676 -0
- package/dist/index.mjs +1040 -0
- package/dist/index.mjs.map +1 -0
- package/dist/utils/index.cjs +9 -0
- package/dist/utils/index.d.cts +1 -0
- package/dist/utils/index.d.mts +1 -0
- package/dist/utils/index.mjs +3 -0
- package/dist/utils/internal.cjs +9 -0
- package/dist/utils/internal.d.cts +1 -0
- package/dist/utils/internal.d.mts +1 -0
- package/dist/utils/internal.mjs +3 -0
- package/package.json +80 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,676 @@
|
|
|
1
|
+
import { AccessToken, AccessToken as AccessToken$1, AuthState, AuthenticateOptions, Authenticators, AuthorizationParams, AuthorizationParams as AuthorizationParams$1, CallbackParams, ClientAuthMethod, CodeChallengeMethod, DisplayOptions, EndSessionParameters, EndSessionParameters as EndSessionParameters$1, Group, IdTokenClaims, IdTokenClaims as IdTokenClaims$1, IssuerMetadata, JWSAlgorithm, Jwk, Jwks, JwsHeaderParameters, MonoCloudAuthBaseError, MonoCloudClientOptions, MonoCloudHttpError, MonoCloudOPError, MonoCloudOidcClient, MonoCloudOidcClient as MonoCloudOidcClient$1, MonoCloudSession, MonoCloudSession as MonoCloudSession$1, MonoCloudTokenError, MonoCloudUser, MonoCloudValidationError, ParResponse, Prompt, PushedAuthorizationParams, RefetchUserInfoOptions, RefreshGrantOptions, RefreshGrantOptions as RefreshGrantOptions$1, RefreshSessionOptions, ResponseModes, ResponseTypes, Tokens, UserinfoResponse, UserinfoResponse as UserinfoResponse$1 } from "@monocloud/auth-core";
|
|
2
|
+
import { SerializeOptions } from "cookie";
|
|
3
|
+
import { Except, PartialDeep } from "type-fest";
|
|
4
|
+
|
|
5
|
+
//#region src/types/internal.d.ts
|
|
6
|
+
type CookieOptions = SerializeOptions;
|
|
7
|
+
interface IMonoCloudCookieRequest {
|
|
8
|
+
getCookie(name: string): Promise<string | undefined>;
|
|
9
|
+
getAllCookies(): Promise<Map<string, string>>;
|
|
10
|
+
}
|
|
11
|
+
interface MonoCloudRequest extends IMonoCloudCookieRequest {
|
|
12
|
+
getRoute(parameter: string): string | string[] | undefined;
|
|
13
|
+
getQuery(parameter: string): string | string[] | undefined;
|
|
14
|
+
getRawRequest(): Promise<{
|
|
15
|
+
method: string;
|
|
16
|
+
url: string;
|
|
17
|
+
body: Record<string, string> | string;
|
|
18
|
+
}>;
|
|
19
|
+
}
|
|
20
|
+
interface IMonoCloudCookieResponse {
|
|
21
|
+
setCookie(cookieName: string, value: string, options: CookieOptions): Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
interface MonoCloudResponse extends IMonoCloudCookieResponse {
|
|
24
|
+
redirect(url: string, statusCode?: number): void;
|
|
25
|
+
sendJson(data: any, statusCode?: number): void;
|
|
26
|
+
notFound(): void;
|
|
27
|
+
noContent(): void;
|
|
28
|
+
internalServerError(): void;
|
|
29
|
+
methodNotAllowed(): void;
|
|
30
|
+
setNoCache(): void;
|
|
31
|
+
done(): any;
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region src/types/index.d.ts
|
|
35
|
+
/**
|
|
36
|
+
* Possible values for the SameSite attribute in cookies.
|
|
37
|
+
*/
|
|
38
|
+
type SameSiteValues = 'strict' | 'lax' | 'none';
|
|
39
|
+
/**
|
|
40
|
+
* Possible values for the Security Algorithms.
|
|
41
|
+
*/
|
|
42
|
+
type SecurityAlgorithms = 'RS256' | 'RS384' | 'RS512' | 'PS256' | 'PS384' | 'PS512' | 'ES256' | 'ES384' | 'ES512';
|
|
43
|
+
/**
|
|
44
|
+
* Represents the lifetime information of a session, including the creation time (c),
|
|
45
|
+
* the last updated time (u), and optionally the expiration time (e).
|
|
46
|
+
*/
|
|
47
|
+
interface SessionLifetime {
|
|
48
|
+
/**
|
|
49
|
+
* The time at which the session was created (in epoch).
|
|
50
|
+
*/
|
|
51
|
+
c: number;
|
|
52
|
+
/**
|
|
53
|
+
* The time at which the session was last updated (in epoch).
|
|
54
|
+
*/
|
|
55
|
+
u: number;
|
|
56
|
+
/**
|
|
57
|
+
* Optional. The expiration time of the session (in epoch).
|
|
58
|
+
*/
|
|
59
|
+
e?: number;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Represents a session store interface for managing session data.
|
|
63
|
+
*/
|
|
64
|
+
interface MonoCloudSessionStore {
|
|
65
|
+
/**
|
|
66
|
+
* Retrieves a session from the store based on the provided key.
|
|
67
|
+
* @param key - The key used to identify the session.
|
|
68
|
+
* @returns A Promise that resolves with the session data, or undefined / null if not found.
|
|
69
|
+
*/
|
|
70
|
+
get(key: string): Promise<MonoCloudSession$1 | undefined | null>;
|
|
71
|
+
/**
|
|
72
|
+
* Stores a session in the store with the specified key.
|
|
73
|
+
* @param key - The key used to identify the session.
|
|
74
|
+
* @param data - The session data to be stored.
|
|
75
|
+
* @param lifetime - The lifetime information of the session.
|
|
76
|
+
* @returns A Promise that resolves when the session is successfully stored.
|
|
77
|
+
*/
|
|
78
|
+
set(key: string, data: MonoCloudSession$1, lifetime: SessionLifetime): Promise<void>;
|
|
79
|
+
/**
|
|
80
|
+
* Deletes a session from the store based on the provided key.
|
|
81
|
+
* @param key - The key used to identify the session to be deleted.
|
|
82
|
+
* @returns A Promise that resolves when the session is successfully deleted.
|
|
83
|
+
*/
|
|
84
|
+
delete(key: string): Promise<void>;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Options for cookies.
|
|
88
|
+
*/
|
|
89
|
+
interface MonoCloudCookieOptions {
|
|
90
|
+
/**
|
|
91
|
+
* The name of the cookie.
|
|
92
|
+
* For session cookies, the default value is 'session'.
|
|
93
|
+
* For state cookies, the default value is 'state'.
|
|
94
|
+
*/
|
|
95
|
+
name: string;
|
|
96
|
+
/**
|
|
97
|
+
* The path for which the cookie is valid.
|
|
98
|
+
* @defaultValue '/'
|
|
99
|
+
*/
|
|
100
|
+
path: string;
|
|
101
|
+
/**
|
|
102
|
+
* Optional: The domain for which the cookie is valid.
|
|
103
|
+
*/
|
|
104
|
+
domain?: string;
|
|
105
|
+
/**
|
|
106
|
+
* Determines whether the cookie is accessible only through HTTP requests.
|
|
107
|
+
* This setting will be ignored for the state cookie and will always be true.
|
|
108
|
+
* @defaultValue true
|
|
109
|
+
*/
|
|
110
|
+
httpOnly: boolean;
|
|
111
|
+
/**
|
|
112
|
+
* Determines whether the cookie should only be sent over HTTPS connections.
|
|
113
|
+
* If not provided, this settings will be auto-detected basis the scheme of the application url.
|
|
114
|
+
*/
|
|
115
|
+
secure: boolean;
|
|
116
|
+
/**
|
|
117
|
+
* The SameSite attribute value for the cookie, ensuring cross-site request forgery protection.
|
|
118
|
+
* @defaultValue 'lax'
|
|
119
|
+
*/
|
|
120
|
+
sameSite: SameSiteValues;
|
|
121
|
+
/**
|
|
122
|
+
* Determines whether the cookie should persist beyond the current session.
|
|
123
|
+
* For session cookies, the default value is true.
|
|
124
|
+
* For state cookies, the default value is false.
|
|
125
|
+
*/
|
|
126
|
+
persistent: boolean;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Options for the authentication sessions.
|
|
130
|
+
*/
|
|
131
|
+
interface MonoCloudSessionOptionsBase {
|
|
132
|
+
/**
|
|
133
|
+
* Configuration options for the authentication session cookie.
|
|
134
|
+
*/
|
|
135
|
+
cookie: MonoCloudCookieOptions;
|
|
136
|
+
/**
|
|
137
|
+
* Determines whether the session should use sliding expiration.
|
|
138
|
+
* @defaultValue false
|
|
139
|
+
*/
|
|
140
|
+
sliding: boolean;
|
|
141
|
+
/**
|
|
142
|
+
* The duration of the session in seconds.
|
|
143
|
+
* @defaultValue 86400 (1 Day)
|
|
144
|
+
*/
|
|
145
|
+
duration: number;
|
|
146
|
+
/**
|
|
147
|
+
* The maximum duration for the session in seconds.
|
|
148
|
+
* Will only be used when the session is set to 'sliding'.
|
|
149
|
+
* @defaultValue 604800 (1 Week)
|
|
150
|
+
*/
|
|
151
|
+
maximumDuration: number;
|
|
152
|
+
/**
|
|
153
|
+
* Optional: The session store to use for storing session data.
|
|
154
|
+
*/
|
|
155
|
+
store?: MonoCloudSessionStore;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Options for the authentication state.
|
|
159
|
+
*/
|
|
160
|
+
interface MonoCloudStateOptions {
|
|
161
|
+
/**
|
|
162
|
+
* Configuration options for the authentication state cookie.
|
|
163
|
+
*/
|
|
164
|
+
cookie: MonoCloudCookieOptions;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Options for the MonoCloud Authentication route handlers.
|
|
168
|
+
*/
|
|
169
|
+
interface MonoCloudRoutes {
|
|
170
|
+
/**
|
|
171
|
+
* The URL of the callback handler
|
|
172
|
+
* @defaultValue '/api/auth/callback'
|
|
173
|
+
*/
|
|
174
|
+
callback: string;
|
|
175
|
+
/**
|
|
176
|
+
* The URL of the back-channel logout handler
|
|
177
|
+
* @defaultValue '/api/auth/backchannel-logout'
|
|
178
|
+
*/
|
|
179
|
+
backChannelLogout: string;
|
|
180
|
+
/**
|
|
181
|
+
* The URL of the sign-in handler
|
|
182
|
+
* @defaultValue '/api/auth/signin'
|
|
183
|
+
*/
|
|
184
|
+
signIn: string;
|
|
185
|
+
/**
|
|
186
|
+
* The URL of the sign-out handler
|
|
187
|
+
* @defaultValue '/api/auth/signout'
|
|
188
|
+
*/
|
|
189
|
+
signOut: string;
|
|
190
|
+
/**
|
|
191
|
+
* The URL of the userinfo handler
|
|
192
|
+
* @defaultValue '/api/auth/userinfo'
|
|
193
|
+
*/
|
|
194
|
+
userInfo: string;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Represents an indicator for additional resources that can be requested.
|
|
198
|
+
*/
|
|
199
|
+
interface Indicator {
|
|
200
|
+
/**
|
|
201
|
+
* Space separated list of resources to scope the access token to
|
|
202
|
+
*/
|
|
203
|
+
resource: string;
|
|
204
|
+
/**
|
|
205
|
+
* Optional: Space separated list of scopes to request
|
|
206
|
+
*/
|
|
207
|
+
scopes?: string;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Options for configuration MonoCloud Authentication.
|
|
211
|
+
*/
|
|
212
|
+
interface MonoCloudOptionsBase {
|
|
213
|
+
/**
|
|
214
|
+
* The client ID of the authenticating application.
|
|
215
|
+
*/
|
|
216
|
+
clientId: string;
|
|
217
|
+
/**
|
|
218
|
+
* Optional: The client secret of the authenticating application.
|
|
219
|
+
*/
|
|
220
|
+
clientSecret?: string;
|
|
221
|
+
/**
|
|
222
|
+
* MonoCloud tenant domain.
|
|
223
|
+
*/
|
|
224
|
+
tenantDomain: string;
|
|
225
|
+
/**
|
|
226
|
+
* A secret key that will be used for encrypting cookies.
|
|
227
|
+
*/
|
|
228
|
+
cookieSecret: string;
|
|
229
|
+
/**
|
|
230
|
+
* The URL of the application.
|
|
231
|
+
*/
|
|
232
|
+
appUrl: string;
|
|
233
|
+
/**
|
|
234
|
+
* Configuration options for the route handler URLs.
|
|
235
|
+
*/
|
|
236
|
+
routes: MonoCloudRoutes;
|
|
237
|
+
/**
|
|
238
|
+
* The maximum allowed clock skew (in seconds) for token validation.
|
|
239
|
+
* @defaultValue 60 (seconds)
|
|
240
|
+
*/
|
|
241
|
+
clockSkew: number;
|
|
242
|
+
/**
|
|
243
|
+
* The timeout (in milliseconds) for receiving responses from the authentication service.
|
|
244
|
+
* @defaultValue 10000 (10 seconds)
|
|
245
|
+
*/
|
|
246
|
+
responseTimeout: number;
|
|
247
|
+
/**
|
|
248
|
+
* Determines whether to use PAR (Pushed Authorization Requests) for authorization requests.
|
|
249
|
+
* @defaultValue false
|
|
250
|
+
*/
|
|
251
|
+
usePar: boolean;
|
|
252
|
+
/**
|
|
253
|
+
* Optional: The URI to redirect to after the user logs out.
|
|
254
|
+
*/
|
|
255
|
+
postLogoutRedirectUri?: string;
|
|
256
|
+
/**
|
|
257
|
+
* Determines whether the user will be logged out of the authentication service.
|
|
258
|
+
* @defaultValue true
|
|
259
|
+
*/
|
|
260
|
+
federatedSignOut: boolean;
|
|
261
|
+
/**
|
|
262
|
+
* Determines whether to fetch the user information from the 'userinfo' endpoint during authentication.
|
|
263
|
+
* @defaultValue true
|
|
264
|
+
*/
|
|
265
|
+
userInfo: boolean;
|
|
266
|
+
/**
|
|
267
|
+
* Determines whether to refetch the user information from the authentication service on each request to the
|
|
268
|
+
* application's userinfo endpoint.
|
|
269
|
+
* @defaultValue false
|
|
270
|
+
*/
|
|
271
|
+
refetchUserInfo: boolean;
|
|
272
|
+
/**
|
|
273
|
+
* Default authorization parameters to include in authentication requests.
|
|
274
|
+
* @defaultValue {
|
|
275
|
+
* scope: 'openid email profile',
|
|
276
|
+
* response_type: 'code'
|
|
277
|
+
* }
|
|
278
|
+
*/
|
|
279
|
+
defaultAuthParams: AuthorizationParams$1;
|
|
280
|
+
/**
|
|
281
|
+
* Optional: Additional resources that can be requested in `getTokens()`.
|
|
282
|
+
*
|
|
283
|
+
*/
|
|
284
|
+
resources?: Indicator[];
|
|
285
|
+
/**
|
|
286
|
+
* Configuration options for the user session.
|
|
287
|
+
*/
|
|
288
|
+
session: MonoCloudSessionOptionsBase;
|
|
289
|
+
/**
|
|
290
|
+
* Configuration options for state management during authentication.
|
|
291
|
+
*/
|
|
292
|
+
state: MonoCloudStateOptions;
|
|
293
|
+
/**
|
|
294
|
+
* The signing algorithm that is expected to be used for signing ID tokens.
|
|
295
|
+
* @defaultValue 'RS256'
|
|
296
|
+
*/
|
|
297
|
+
idTokenSigningAlg: SecurityAlgorithms;
|
|
298
|
+
/**
|
|
299
|
+
* Array of strings representing the filtered ID token claims.
|
|
300
|
+
*/
|
|
301
|
+
filteredIdTokenClaims: string[];
|
|
302
|
+
/**
|
|
303
|
+
* The name of the debugger instance.
|
|
304
|
+
*/
|
|
305
|
+
debugger: string;
|
|
306
|
+
/**
|
|
307
|
+
* The name of the user agent.
|
|
308
|
+
*/
|
|
309
|
+
userAgent: string;
|
|
310
|
+
/**
|
|
311
|
+
* Jwks Cache Duration
|
|
312
|
+
*
|
|
313
|
+
* Time in seconds to cache the JWKS document after it is fetched
|
|
314
|
+
*
|
|
315
|
+
* @default 300
|
|
316
|
+
*
|
|
317
|
+
* */
|
|
318
|
+
jwksCacheDuration?: number;
|
|
319
|
+
/**
|
|
320
|
+
* Metadata Cache Duration
|
|
321
|
+
*
|
|
322
|
+
* Time in seconds to cache the metadata document after it is fetched.
|
|
323
|
+
*
|
|
324
|
+
* @default 300
|
|
325
|
+
* */
|
|
326
|
+
metadataCacheDuration?: number;
|
|
327
|
+
/**
|
|
328
|
+
* Optional: A callback function invoked when a back-channel logout event is received.
|
|
329
|
+
*/
|
|
330
|
+
onBackChannelLogout?: OnBackChannelLogout;
|
|
331
|
+
/**
|
|
332
|
+
* Optional: A callback function invoked when an authentication state is being set (before sign-in).
|
|
333
|
+
*/
|
|
334
|
+
onSetApplicationState?: OnSetApplicationState;
|
|
335
|
+
/**
|
|
336
|
+
* Optional: A callback function invoked before creating or updating the user session.
|
|
337
|
+
*/
|
|
338
|
+
onSessionCreating?: OnSessionCreating;
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Options for the authentication sessions.
|
|
342
|
+
*/
|
|
343
|
+
type MonoCloudSessionOptions = Except<PartialDeep<MonoCloudSessionOptionsBase>, 'store'> & {
|
|
344
|
+
/**
|
|
345
|
+
* Optional: The session store to use for storing session data.
|
|
346
|
+
*/
|
|
347
|
+
store?: MonoCloudSessionStore;
|
|
348
|
+
};
|
|
349
|
+
/**
|
|
350
|
+
* Options for configuration MonoCloud Authentication.
|
|
351
|
+
*/
|
|
352
|
+
type MonoCloudOptions = Except<PartialDeep<MonoCloudOptionsBase>, 'defaultAuthParams' | 'session'> & {
|
|
353
|
+
/**
|
|
354
|
+
* Default authorization parameters to include in authentication requests.
|
|
355
|
+
* @defaultValue {
|
|
356
|
+
* scope: 'openid email profile',
|
|
357
|
+
* response_type: 'code'
|
|
358
|
+
* }
|
|
359
|
+
*/
|
|
360
|
+
defaultAuthParams?: Partial<AuthorizationParams$1>;
|
|
361
|
+
/**
|
|
362
|
+
* Configuration options for the user session.
|
|
363
|
+
*/
|
|
364
|
+
session?: MonoCloudSessionOptions;
|
|
365
|
+
};
|
|
366
|
+
/**
|
|
367
|
+
* Defines a callback function to be invoked when a back-channel logout event is received.
|
|
368
|
+
* This function receives an optional subject identifier (sub) of the user and an optional session identifier (sid).
|
|
369
|
+
*
|
|
370
|
+
* @param sub - Optional. The subject identifier (sub) of the user.
|
|
371
|
+
* @param sid - Optional. The session identifier (sid) associated with the user's session.
|
|
372
|
+
* @returns A Promise that resolves when the operation is completed, or void.
|
|
373
|
+
*/
|
|
374
|
+
type OnBackChannelLogout = (
|
|
375
|
+
/**
|
|
376
|
+
* Optional. The subject identifier (sub) of the user.
|
|
377
|
+
*/
|
|
378
|
+
sub?: string,
|
|
379
|
+
/**
|
|
380
|
+
* Optional. The session identifier (sid) associated with the user's session.
|
|
381
|
+
*/
|
|
382
|
+
sid?: string) => Promise<void> | void;
|
|
383
|
+
/**
|
|
384
|
+
* The custom application state.
|
|
385
|
+
*/
|
|
386
|
+
type ApplicationState = Record<string, any>;
|
|
387
|
+
/**
|
|
388
|
+
* Defines a callback function to be executed when a new session is being created or updated.
|
|
389
|
+
* This function receives parameters related to the session being created,
|
|
390
|
+
* including the session object itself, optional ID token and user information claims,
|
|
391
|
+
* and the application state.
|
|
392
|
+
*
|
|
393
|
+
* @param session - The Session object being created.
|
|
394
|
+
* @param idToken - Optional. Claims from the ID token received during authentication.
|
|
395
|
+
* @param userInfo - Optional. Claims from the user information received during authentication.
|
|
396
|
+
* @param state - Optional. The application state associated with the session.
|
|
397
|
+
* @returns A Promise that resolves when the operation is completed, or void.
|
|
398
|
+
*/
|
|
399
|
+
type OnSessionCreating = (
|
|
400
|
+
/**
|
|
401
|
+
* The Session object being created.
|
|
402
|
+
*/
|
|
403
|
+
session: MonoCloudSession$1,
|
|
404
|
+
/**
|
|
405
|
+
* Optional. Claims from the ID token received during authentication.
|
|
406
|
+
*/
|
|
407
|
+
idToken?: Partial<IdTokenClaims$1>,
|
|
408
|
+
/**
|
|
409
|
+
* Optional. Claims from the user information received during authentication.
|
|
410
|
+
*/
|
|
411
|
+
userInfo?: UserinfoResponse$1,
|
|
412
|
+
/**
|
|
413
|
+
* Optional. The application state associated with the session.
|
|
414
|
+
*/
|
|
415
|
+
state?: ApplicationState) => Promise<void> | void;
|
|
416
|
+
/**
|
|
417
|
+
* Defines a callback function to be executed when an authentication state is being set.
|
|
418
|
+
* This function receives the incoming request and should return or resolve with an ApplicationState object.
|
|
419
|
+
*
|
|
420
|
+
* @param req - The incoming request.
|
|
421
|
+
* @returns A Promise that resolves with the ApplicationState object when the operation is completed, or the ApplicationState object directly.
|
|
422
|
+
*/
|
|
423
|
+
type OnSetApplicationState = (
|
|
424
|
+
/**
|
|
425
|
+
* The incoming request.
|
|
426
|
+
*/
|
|
427
|
+
req: MonoCloudRequest) => Promise<ApplicationState> | ApplicationState;
|
|
428
|
+
/**
|
|
429
|
+
* Represents the tokens obtained during authentication that are available in the session.
|
|
430
|
+
*/
|
|
431
|
+
interface MonoCloudTokens extends AccessToken$1 {
|
|
432
|
+
/**
|
|
433
|
+
* The ID token obtained during authentication.
|
|
434
|
+
*/
|
|
435
|
+
idToken?: string;
|
|
436
|
+
/**
|
|
437
|
+
* The refresh token obtained during authentication.
|
|
438
|
+
*/
|
|
439
|
+
refreshToken?: string;
|
|
440
|
+
/**
|
|
441
|
+
* Specifies if the access token has expired.
|
|
442
|
+
*/
|
|
443
|
+
isExpired: boolean;
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* A function used to handle errors that occur during the signin, callback, signout and userinfo endpoint execution.
|
|
447
|
+
*
|
|
448
|
+
* @param error - Error occured during execution of the endpoint.
|
|
449
|
+
*/
|
|
450
|
+
type OnError = (error: Error) => Promise<any> | any;
|
|
451
|
+
/**
|
|
452
|
+
* Represents options for the sign-in handler.
|
|
453
|
+
*/
|
|
454
|
+
interface SignInOptions {
|
|
455
|
+
/**
|
|
456
|
+
* The application URL to which the user should be redirected after successful authentication.
|
|
457
|
+
* Must be a relative Url.
|
|
458
|
+
* Defaults to the appUrl.
|
|
459
|
+
*/
|
|
460
|
+
returnUrl?: string;
|
|
461
|
+
/**
|
|
462
|
+
* Specifies whether to initiate a user registration process.
|
|
463
|
+
*/
|
|
464
|
+
register?: boolean;
|
|
465
|
+
/**
|
|
466
|
+
* Additional authorization parameters to include in the authentication request.
|
|
467
|
+
*/
|
|
468
|
+
authParams?: AuthorizationParams$1;
|
|
469
|
+
/**
|
|
470
|
+
* A custom function to handle unexpected errors while signing in.
|
|
471
|
+
*/
|
|
472
|
+
onError?: OnError;
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
475
|
+
* Represents options for the callback handler.
|
|
476
|
+
*/
|
|
477
|
+
interface CallbackOptions {
|
|
478
|
+
/**
|
|
479
|
+
* Determines whether to fetch the user information from the 'userinfo' endpoint after processing the callback.
|
|
480
|
+
*/
|
|
481
|
+
userInfo?: boolean;
|
|
482
|
+
/**
|
|
483
|
+
* Url to be sent to the token endpoint.
|
|
484
|
+
*/
|
|
485
|
+
redirectUri?: string;
|
|
486
|
+
/**
|
|
487
|
+
* A custom function to handle unexpected errors while processing callback from MonoCloud.
|
|
488
|
+
*/
|
|
489
|
+
onError?: OnError;
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
492
|
+
* Represents options for the userinfo handler.
|
|
493
|
+
*/
|
|
494
|
+
interface UserInfoOptions {
|
|
495
|
+
/**
|
|
496
|
+
* Determines whether to refetch the user information from the authentication service.
|
|
497
|
+
*/
|
|
498
|
+
refresh?: boolean;
|
|
499
|
+
/**
|
|
500
|
+
* A custom function to handle unexpected errors while fetching userinfo.
|
|
501
|
+
*/
|
|
502
|
+
onError?: OnError;
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* Represents options for the sign-out handler.
|
|
506
|
+
*/
|
|
507
|
+
type SignOutOptions = {
|
|
508
|
+
/**
|
|
509
|
+
* Determines whether the user will be logged out of the authentication service.
|
|
510
|
+
*/
|
|
511
|
+
federatedSignOut?: boolean;
|
|
512
|
+
/**
|
|
513
|
+
* A custom function to handle unexpected errors while signing out.
|
|
514
|
+
*/
|
|
515
|
+
onError?: OnError;
|
|
516
|
+
} & EndSessionParameters$1;
|
|
517
|
+
/**
|
|
518
|
+
* Represents options for the GetTokens handler.
|
|
519
|
+
*/
|
|
520
|
+
interface GetTokensOptions extends RefreshGrantOptions$1 {
|
|
521
|
+
/**
|
|
522
|
+
* Specifies whether to force the refresh of the access token.
|
|
523
|
+
*/
|
|
524
|
+
forceRefresh?: boolean;
|
|
525
|
+
/**
|
|
526
|
+
* Determines whether to refetch the user information.
|
|
527
|
+
*/
|
|
528
|
+
refetchUserInfo?: boolean;
|
|
529
|
+
}
|
|
530
|
+
//#endregion
|
|
531
|
+
//#region src/monocloud-node-core-client.d.ts
|
|
532
|
+
declare class MonoCloudCoreClient {
|
|
533
|
+
readonly oidcClient: MonoCloudOidcClient$1;
|
|
534
|
+
private readonly options;
|
|
535
|
+
private readonly stateService;
|
|
536
|
+
private readonly sessionService;
|
|
537
|
+
private readonly debug;
|
|
538
|
+
private optionsValidated;
|
|
539
|
+
constructor(partialOptions?: MonoCloudOptions);
|
|
540
|
+
/**
|
|
541
|
+
* Initiates the sign-in flow by redirecting the user to the MonoCloud authorization endpoint.
|
|
542
|
+
*
|
|
543
|
+
* This method handles scope and resource merging, state generation (nonce, state, PKCE),
|
|
544
|
+
* and Constructing the final authorization URL.
|
|
545
|
+
*
|
|
546
|
+
* @param request - MonoCloud request object.
|
|
547
|
+
* @param response - MonoCloud response object.
|
|
548
|
+
* @param signInOptions - Optional configuration to customize the sign-in behavior.
|
|
549
|
+
* @returns A promise that resolves when the callback processing and redirection are complete.
|
|
550
|
+
*
|
|
551
|
+
* @throws {@link MonoCloudValidationError} When validation of parameters or state fails.
|
|
552
|
+
*/
|
|
553
|
+
signIn(request: MonoCloudRequest, response: MonoCloudResponse, signInOptions?: SignInOptions): Promise<any>;
|
|
554
|
+
/**
|
|
555
|
+
* Handles the OpenID callback after the user authenticates with MonoCloud.
|
|
556
|
+
*
|
|
557
|
+
* Processes the authorization code, validates the state and nonce, exchanges the code for tokens,
|
|
558
|
+
* initializes the user session, and performs the final redirect to the application's return URL.
|
|
559
|
+
*
|
|
560
|
+
* @param request - MonoCloud request object.
|
|
561
|
+
* @param response - MonoCloud response object.
|
|
562
|
+
* @param callbackOptions - Optional configuration for the callback handler.
|
|
563
|
+
* @returns A promise that resolves when the callback processing and redirection are complete.
|
|
564
|
+
*
|
|
565
|
+
* @throws {@link MonoCloudValidationError} If the state is mismatched or tokens are invalid.
|
|
566
|
+
*/
|
|
567
|
+
callback(request: MonoCloudRequest, response: MonoCloudResponse, callbackOptions?: CallbackOptions): Promise<any>;
|
|
568
|
+
/**
|
|
569
|
+
* Retrieves user information, optionally refetching fresh data from the UserInfo endpoint.
|
|
570
|
+
*
|
|
571
|
+
* @param request - MonoCloud request object.
|
|
572
|
+
* @param response - MonoCloud response object.
|
|
573
|
+
* @param userinfoOptions - Configuration to control refetching and error handling.
|
|
574
|
+
* @returns A promise that resolves with the user information sent as a JSON response.
|
|
575
|
+
*
|
|
576
|
+
* @remarks
|
|
577
|
+
* If `refresh` is true, the session is updated with fresh claims from the identity provider.
|
|
578
|
+
*/
|
|
579
|
+
userInfo(request: MonoCloudRequest, response: MonoCloudResponse, userinfoOptions?: UserInfoOptions): Promise<any>;
|
|
580
|
+
/**
|
|
581
|
+
* Initiates the sign-out flow, destroying the local session and optionally performing federated sign-out.
|
|
582
|
+
*
|
|
583
|
+
* @param request - MonoCloud request object.
|
|
584
|
+
* @param response - MonoCloud response object.
|
|
585
|
+
* @param signOutOptions - Configuration for post-logout behavior and federated sign-out.
|
|
586
|
+
*
|
|
587
|
+
* @returns A promise that resolves when the sign-out redirection is initiated.
|
|
588
|
+
*/
|
|
589
|
+
signOut(request: MonoCloudRequest, response: MonoCloudResponse, signOutOptions?: SignOutOptions): Promise<any>;
|
|
590
|
+
/**
|
|
591
|
+
* Handles Back-Channel Logout notifications from the identity provider.
|
|
592
|
+
*
|
|
593
|
+
* Validates the Logout Token and triggers the `onBackChannelLogout` callback defined in options.
|
|
594
|
+
*
|
|
595
|
+
* @param request - MonoCloud request object.
|
|
596
|
+
* @param response - MonoCloud response object.
|
|
597
|
+
*
|
|
598
|
+
* @returns A promise that resolves when the logout notification has been processed.
|
|
599
|
+
*
|
|
600
|
+
* @throws {@link MonoCloudValidationError} If the logout token is missing or invalid.
|
|
601
|
+
*/
|
|
602
|
+
backChannelLogout(request: MonoCloudRequest, response: MonoCloudResponse): Promise<any>;
|
|
603
|
+
/**
|
|
604
|
+
* Checks if the current request has an active and authenticated session.
|
|
605
|
+
*
|
|
606
|
+
* @param request - MonoCloud cookie request object.
|
|
607
|
+
* @param response - MonoCloud cookie response object.
|
|
608
|
+
*
|
|
609
|
+
* @returns `true` if a valid session with user data exists, `false` otherwise.
|
|
610
|
+
*
|
|
611
|
+
*/
|
|
612
|
+
isAuthenticated(request: IMonoCloudCookieRequest, response: IMonoCloudCookieResponse): Promise<boolean>;
|
|
613
|
+
/**
|
|
614
|
+
* Checks if the current session user belongs to the specified groups.
|
|
615
|
+
*
|
|
616
|
+
* @param request - MonoCloud cookie request object.
|
|
617
|
+
* @param response - MonoCloud cookie response object.
|
|
618
|
+
* @param groups - List of group names or IDs to check.
|
|
619
|
+
* @param groupsClaim - Optional claim name that holds groups. Defaults to "groups".
|
|
620
|
+
* @param matchAll - If `true`, requires membership in all groups; otherwise any one group is sufficient.
|
|
621
|
+
*
|
|
622
|
+
* @returns `true` if the user satisfies the group condition, `false` otherwise.
|
|
623
|
+
*/
|
|
624
|
+
isUserInGroup(request: IMonoCloudCookieRequest, response: IMonoCloudCookieResponse, groups: string[], groupsClaim?: string, matchAll?: boolean): Promise<boolean>;
|
|
625
|
+
/**
|
|
626
|
+
* Retrieves the current user's session data.
|
|
627
|
+
*
|
|
628
|
+
* @param request - MonoCloud cookie request object.
|
|
629
|
+
* @param response - MonoCloud cookie response object.
|
|
630
|
+
*
|
|
631
|
+
* @returns Session or `undefined`.
|
|
632
|
+
*/
|
|
633
|
+
getSession(request: IMonoCloudCookieRequest, response: IMonoCloudCookieResponse): Promise<MonoCloudSession$1 | undefined>;
|
|
634
|
+
/**
|
|
635
|
+
* Updates the current user's session with new data.
|
|
636
|
+
*
|
|
637
|
+
* @param request - MonoCloud cookie request object.
|
|
638
|
+
* @param response - MonoCloud cookie response object.
|
|
639
|
+
* @param session - The updated session object to persist.
|
|
640
|
+
*/
|
|
641
|
+
updateSession(request: IMonoCloudCookieRequest, response: IMonoCloudCookieResponse, session: MonoCloudSession$1): Promise<void>;
|
|
642
|
+
/**
|
|
643
|
+
* Returns a copy of the current client configuration options.
|
|
644
|
+
*
|
|
645
|
+
* @returns A copy of the initialized configuration.
|
|
646
|
+
*/
|
|
647
|
+
getOptions(): MonoCloudOptionsBase;
|
|
648
|
+
/**
|
|
649
|
+
* Destroys the local user session.
|
|
650
|
+
*
|
|
651
|
+
* @param request - MonoCloud cookie request object.
|
|
652
|
+
* @param response - MonoCloud cookie response object.
|
|
653
|
+
*
|
|
654
|
+
* @remarks
|
|
655
|
+
* This does not perform federated sign-out. For identity provider sign-out, use `signOut` handler.
|
|
656
|
+
*/
|
|
657
|
+
destroySession(request: IMonoCloudCookieRequest, response: IMonoCloudCookieResponse): Promise<void>;
|
|
658
|
+
/**
|
|
659
|
+
* Retrieves active tokens (Access, ID, Refresh), performing a refresh if they are expired or missing.
|
|
660
|
+
*
|
|
661
|
+
* @param request - MonoCloud cookie request object.
|
|
662
|
+
* @param response - MonoCloud cookie response object.
|
|
663
|
+
* @param options - Configuration for token retrieval (force refresh, specific scopes/resources).
|
|
664
|
+
*
|
|
665
|
+
* @returns Fetched tokens
|
|
666
|
+
*
|
|
667
|
+
* @throws {@link MonoCloudValidationError} If the session does not exist or tokens cannot be found/refreshed.
|
|
668
|
+
*/
|
|
669
|
+
getTokens(request: IMonoCloudCookieRequest, response: IMonoCloudCookieResponse, options?: GetTokensOptions): Promise<MonoCloudTokens>;
|
|
670
|
+
private verifyLogoutToken;
|
|
671
|
+
private handleCatchAll;
|
|
672
|
+
private validateOptions;
|
|
673
|
+
}
|
|
674
|
+
//#endregion
|
|
675
|
+
export { type AccessToken, type ApplicationState, type AuthState, type AuthenticateOptions, type Authenticators, type AuthorizationParams, type CallbackOptions, type CallbackParams, type ClientAuthMethod, type CodeChallengeMethod, type CookieOptions, type DisplayOptions, type EndSessionParameters, type GetTokensOptions, type Group, type IMonoCloudCookieRequest, type IMonoCloudCookieResponse, type IdTokenClaims, type Indicator, type IssuerMetadata, type JWSAlgorithm, type Jwk, type Jwks, type JwsHeaderParameters, MonoCloudAuthBaseError, type MonoCloudClientOptions, type MonoCloudCookieOptions, MonoCloudCoreClient, MonoCloudHttpError, MonoCloudOPError, MonoCloudOidcClient, type MonoCloudOptions, type MonoCloudOptionsBase, type MonoCloudRequest, type MonoCloudResponse, type MonoCloudRoutes, type MonoCloudSession, type MonoCloudSessionOptions, type MonoCloudSessionOptionsBase, type MonoCloudSessionStore, type MonoCloudStateOptions, MonoCloudTokenError, type MonoCloudTokens, type MonoCloudUser, MonoCloudValidationError, type OnBackChannelLogout, type OnError, type OnSessionCreating, type OnSetApplicationState, type ParResponse, type Prompt, type PushedAuthorizationParams, type RefetchUserInfoOptions, type RefreshGrantOptions, type RefreshSessionOptions, type ResponseModes, type ResponseTypes, type SameSiteValues, type SecurityAlgorithms, type SessionLifetime, type SignInOptions, type SignOutOptions, type Tokens, type UserInfoOptions, type UserinfoResponse };
|
|
676
|
+
//# sourceMappingURL=index.d.mts.map
|