@asgardeo/node 0.0.1

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.
@@ -0,0 +1,795 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
31
+
32
+ // src/index.ts
33
+ var index_exports = {};
34
+ __export(index_exports, {
35
+ AsgardeoNodeClient: () => AsgardeoNodeClient_default,
36
+ CookieConfig: () => CookieConfig_default,
37
+ LegacyAsgardeoNodeClient: () => AsgardeoNodeClient,
38
+ Logger: () => Logger,
39
+ generateSessionId: () => generateSessionId_default,
40
+ getSessionCookieOptions: () => getSessionCookieOptions_default
41
+ });
42
+ module.exports = __toCommonJS(index_exports);
43
+ var import_cross_fetch = __toESM(require("cross-fetch"), 1);
44
+
45
+ // src/__legacy__/core/authentication.ts
46
+ var import_javascript = require("@asgardeo/javascript");
47
+
48
+ // src/__legacy__/stores/memory-cache-store.ts
49
+ var import_memory_cache = __toESM(require("memory-cache"), 1);
50
+ var MemoryCacheStore = class {
51
+ async setData(key, value) {
52
+ import_memory_cache.default.put(key, value);
53
+ }
54
+ async getData(key) {
55
+ return import_memory_cache.default.get(key) ?? "{}";
56
+ }
57
+ async removeData(key) {
58
+ import_memory_cache.default.del(key);
59
+ }
60
+ };
61
+
62
+ // src/__legacy__/utils/session-utils.ts
63
+ var import_uuid = require("uuid");
64
+
65
+ // src/__legacy__/constants/uuid-config.ts
66
+ var UUID_VERSION = 4;
67
+
68
+ // src/__legacy__/constants/logger-config.ts
69
+ var LOGGER_CONFIG = {
70
+ bgGreen: "\x1B[42m",
71
+ bgRed: "\x1B[41m",
72
+ bgWhite: "\x1B[47m",
73
+ bgYellow: "\x1B[43m",
74
+ fgBlack: "\x1B[30m",
75
+ fgGreen: "\x1B[32m",
76
+ fgRed: "\x1B[31m",
77
+ fgWhite: "\x1B[37m",
78
+ fgYellow: "\x1B[33m",
79
+ reset: "\x1B[0m"
80
+ };
81
+
82
+ // src/__legacy__/utils/session-utils.ts
83
+ var SessionUtils = class {
84
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
85
+ constructor() {
86
+ }
87
+ static createUUID() {
88
+ const generated_uuid = (0, import_uuid.v4)();
89
+ return generated_uuid;
90
+ }
91
+ static validateUUID(uuid) {
92
+ if ((0, import_uuid.validate)(uuid) && (0, import_uuid.version)(uuid) === UUID_VERSION) {
93
+ return Promise.resolve(true);
94
+ } else {
95
+ return Promise.resolve(false);
96
+ }
97
+ }
98
+ static validateSession(sessionData) {
99
+ const currentTime = Date.now();
100
+ const expiryTimeStamp = sessionData.created_at + parseInt(sessionData.expires_in) * 60 * 1e3;
101
+ if (currentTime < expiryTimeStamp) {
102
+ return Promise.resolve(true);
103
+ } else {
104
+ Logger.warn("Expired Session");
105
+ return Promise.resolve(false);
106
+ }
107
+ }
108
+ };
109
+
110
+ // src/__legacy__/utils/logger-utils.ts
111
+ var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
112
+ LogLevel2[LogLevel2["DEBUG"] = 0] = "DEBUG";
113
+ LogLevel2[LogLevel2["INFO"] = 1] = "INFO";
114
+ LogLevel2[LogLevel2["WARN"] = 2] = "WARN";
115
+ LogLevel2[LogLevel2["ERROR"] = 3] = "ERROR";
116
+ LogLevel2[LogLevel2["OFF"] = 4] = "OFF";
117
+ return LogLevel2;
118
+ })(LogLevel || {});
119
+ var Logger = class {
120
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
121
+ constructor() {
122
+ }
123
+ static debug(message) {
124
+ if (LogLevel[this.LOG_LEVEL] <= 0 /* DEBUG */)
125
+ console.log(
126
+ LOGGER_CONFIG.bgGreen,
127
+ LOGGER_CONFIG.fgBlack,
128
+ "DEBUG",
129
+ LOGGER_CONFIG.reset,
130
+ LOGGER_CONFIG.fgGreen,
131
+ message,
132
+ LOGGER_CONFIG.reset
133
+ );
134
+ }
135
+ static info(message) {
136
+ if (LogLevel[this.LOG_LEVEL] <= 1 /* INFO */)
137
+ console.log(
138
+ LOGGER_CONFIG.bgWhite,
139
+ LOGGER_CONFIG.fgBlack,
140
+ "INFO",
141
+ LOGGER_CONFIG.reset,
142
+ LOGGER_CONFIG.fgWhite,
143
+ message,
144
+ LOGGER_CONFIG.reset
145
+ );
146
+ }
147
+ static warn(message) {
148
+ if (LogLevel[this.LOG_LEVEL] <= 2 /* WARN */)
149
+ console.log(
150
+ LOGGER_CONFIG.bgYellow,
151
+ LOGGER_CONFIG.fgBlack,
152
+ "WARNING",
153
+ LOGGER_CONFIG.reset,
154
+ LOGGER_CONFIG.fgYellow,
155
+ message,
156
+ LOGGER_CONFIG.reset
157
+ );
158
+ }
159
+ static error(message) {
160
+ if (LogLevel[this.LOG_LEVEL] <= 3 /* ERROR */)
161
+ console.log(
162
+ LOGGER_CONFIG.bgRed,
163
+ LOGGER_CONFIG.fgBlack,
164
+ "ERROR",
165
+ LOGGER_CONFIG.reset,
166
+ LOGGER_CONFIG.fgRed,
167
+ message,
168
+ LOGGER_CONFIG.reset
169
+ );
170
+ }
171
+ };
172
+ __publicField(Logger, "LOG_LEVEL", process.env["LOG_LEVEL"] ?? LogLevel[4 /* OFF */]);
173
+
174
+ // src/__legacy__/utils/crypto-utils.ts
175
+ var import_base64url = __toESM(require("base64url"), 1);
176
+ var import_fast_sha256 = __toESM(require("fast-sha256"), 1);
177
+ var jose = __toESM(require("jose"), 1);
178
+ var import_secure_random_bytes = __toESM(require("secure-random-bytes"), 1);
179
+ var NodeCryptoUtils = class {
180
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
181
+ constructor() {
182
+ }
183
+ /**
184
+ * Get URL encoded string.
185
+ *
186
+ * @returns {string} base 64 url encoded value.
187
+ */
188
+ base64URLEncode(value) {
189
+ return import_base64url.default.encode(value).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
190
+ }
191
+ base64URLDecode(value) {
192
+ return import_base64url.default.decode(value).toString();
193
+ }
194
+ hashSha256(data) {
195
+ return Buffer.from((0, import_fast_sha256.default)(new TextEncoder().encode(data)));
196
+ }
197
+ generateRandomBytes(length) {
198
+ return (0, import_secure_random_bytes.default)(length);
199
+ }
200
+ async verifyJwt(idToken, jwk, algorithms, clientID, issuer, subject, clockTolerance) {
201
+ const key = await jose.importJWK(jwk);
202
+ return jose.jwtVerify(idToken, key, {
203
+ algorithms,
204
+ audience: clientID,
205
+ clockTolerance,
206
+ issuer,
207
+ subject
208
+ }).then(() => {
209
+ return Promise.resolve(true);
210
+ });
211
+ }
212
+ };
213
+
214
+ // src/__legacy__/core/authentication.ts
215
+ var AsgardeoNodeCore = class _AsgardeoNodeCore {
216
+ constructor(config, store) {
217
+ __publicField(this, "_auth");
218
+ __publicField(this, "_cryptoUtils");
219
+ __publicField(this, "_store");
220
+ __publicField(this, "_dataLayer");
221
+ if (!store) {
222
+ this._store = new MemoryCacheStore();
223
+ } else {
224
+ this._store = store;
225
+ }
226
+ this._cryptoUtils = new NodeCryptoUtils();
227
+ this._auth = new import_javascript.AsgardeoAuthClient();
228
+ this._auth.initialize(config, this._store, this._cryptoUtils);
229
+ this._dataLayer = this._auth.getDataLayer();
230
+ Logger.debug("Initialized AsgardeoAuthClient successfully");
231
+ }
232
+ async signIn(authURLCallback, userID, authorizationCode, sessionState, state, signInConfig) {
233
+ if (!userID) {
234
+ return Promise.reject(
235
+ new import_javascript.AsgardeoAuthException(
236
+ "NODE-AUTH_CORE-SI-NF01",
237
+ "No user ID was provided.",
238
+ "Unable to sign in the user as no user ID was provided."
239
+ )
240
+ );
241
+ }
242
+ if (await this.isAuthenticated(userID)) {
243
+ const sessionData = await this._dataLayer.getSessionData(userID);
244
+ return Promise.resolve({
245
+ accessToken: sessionData.access_token,
246
+ createdAt: sessionData.created_at,
247
+ expiresIn: sessionData.expires_in,
248
+ idToken: sessionData.id_token,
249
+ refreshToken: sessionData.refresh_token ?? "",
250
+ scope: sessionData.scope,
251
+ tokenType: sessionData.token_type
252
+ });
253
+ }
254
+ if (!authorizationCode || !state) {
255
+ if (!authURLCallback || typeof authURLCallback !== "function") {
256
+ return Promise.reject(
257
+ new import_javascript.AsgardeoAuthException(
258
+ "NODE-AUTH_CORE-SI-NF02",
259
+ "Invalid AuthURLCallback function.",
260
+ "The AuthURLCallback is not defined or is not a function."
261
+ )
262
+ );
263
+ }
264
+ const authURL = await this.getAuthURL(userID, signInConfig);
265
+ authURLCallback(authURL);
266
+ return Promise.resolve({
267
+ accessToken: "",
268
+ createdAt: 0,
269
+ expiresIn: "",
270
+ idToken: "",
271
+ refreshToken: "",
272
+ scope: "",
273
+ session: "",
274
+ tokenType: ""
275
+ });
276
+ }
277
+ return this.requestAccessToken(authorizationCode, sessionState ?? "", userID, state);
278
+ }
279
+ async getAuthURL(userId, signInConfig) {
280
+ const authURL = await this._auth.getAuthorizationURL(signInConfig, userId);
281
+ if (authURL) {
282
+ return Promise.resolve(authURL.toString());
283
+ } else {
284
+ return Promise.reject(
285
+ new import_javascript.AsgardeoAuthException(
286
+ "NODE-AUTH_CORE-GAU-NF01",
287
+ "Getting Authorization URL failed.",
288
+ "No authorization URL was returned by the Asgardeo Auth JS SDK."
289
+ )
290
+ );
291
+ }
292
+ }
293
+ async requestAccessToken(authorizationCode, sessionState, userId, state) {
294
+ return this._auth.requestAccessToken(authorizationCode, sessionState, state, userId);
295
+ }
296
+ async getIDToken(userId) {
297
+ const is_logged_in = await this.isAuthenticated(userId);
298
+ if (!is_logged_in) {
299
+ return Promise.reject(
300
+ new import_javascript.AsgardeoAuthException(
301
+ "NODE-AUTH_CORE-GIT-NF01",
302
+ "The user is not logged in.",
303
+ "No session ID was found for the requested user. User is not logged in."
304
+ )
305
+ );
306
+ }
307
+ const idToken = await this._auth.getIDToken(userId);
308
+ if (idToken) {
309
+ return Promise.resolve(idToken);
310
+ } else {
311
+ return Promise.reject(
312
+ new import_javascript.AsgardeoAuthException(
313
+ "NODE-AUTH_CORE-GIT-NF02",
314
+ "Requesting ID Token Failed",
315
+ "No ID Token was returned by the Asgardeo Auth JS SDK."
316
+ )
317
+ );
318
+ }
319
+ }
320
+ async refreshAccessToken(userId) {
321
+ return this._auth.refreshAccessToken(userId);
322
+ }
323
+ async isAuthenticated(userId) {
324
+ try {
325
+ if (!await this._auth.isAuthenticated(userId)) {
326
+ return Promise.resolve(false);
327
+ }
328
+ if (await SessionUtils.validateSession(await this._dataLayer.getSessionData(userId))) {
329
+ return Promise.resolve(true);
330
+ }
331
+ const refreshed_token = await this.refreshAccessToken(userId);
332
+ if (refreshed_token) {
333
+ return Promise.resolve(true);
334
+ }
335
+ this._dataLayer.removeSessionData(userId);
336
+ this._dataLayer.getTemporaryData(userId);
337
+ return Promise.resolve(false);
338
+ } catch (error) {
339
+ return Promise.reject(error);
340
+ }
341
+ }
342
+ async signOut(userId) {
343
+ const signOutURL = await this._auth.getSignOutURL(userId);
344
+ if (!signOutURL) {
345
+ return Promise.reject(
346
+ new import_javascript.AsgardeoAuthException(
347
+ "NODE-AUTH_CORE-SO-NF01",
348
+ "Signing out the user failed.",
349
+ "Could not obtain the sign-out URL from the server."
350
+ )
351
+ );
352
+ }
353
+ return Promise.resolve(signOutURL);
354
+ }
355
+ async getBasicUserInfo(userId) {
356
+ return this._auth.getBasicUserInfo(userId);
357
+ }
358
+ async getOIDCServiceEndpoints() {
359
+ return this._auth.getOIDCServiceEndpoints();
360
+ }
361
+ async getDecodedIDToken(userId) {
362
+ return this._auth.getDecodedIDToken(userId);
363
+ }
364
+ async getAccessToken(userId) {
365
+ return this._auth.getAccessToken(userId);
366
+ }
367
+ async requestCustomGrant(config, userId) {
368
+ return this._auth.requestCustomGrant(config, userId);
369
+ }
370
+ async updateConfig(config) {
371
+ return this._auth.updateConfig(config);
372
+ }
373
+ async revokeAccessToken(userId) {
374
+ return this._auth.revokeAccessToken(userId);
375
+ }
376
+ static didSignOutFail(signOutRedirectURL) {
377
+ return _AsgardeoNodeCore.didSignOutFail(signOutRedirectURL);
378
+ }
379
+ static isSignOutSuccessful(signOutRedirectURL) {
380
+ return _AsgardeoNodeCore.isSignOutSuccessful(signOutRedirectURL);
381
+ }
382
+ getDataLayer() {
383
+ return this._dataLayer;
384
+ }
385
+ };
386
+
387
+ // src/__legacy__/client.ts
388
+ var AsgardeoNodeClient = class _AsgardeoNodeClient {
389
+ /**
390
+ * This is the constructor method that returns an instance of the `AsgardeoNodeClient` class.
391
+ *
392
+ * @param {AuthClientConfig<T>} config - The configuration object.
393
+ * @param {Store} store - The store object.
394
+ *
395
+ * @example
396
+ * ```
397
+ * const _store: Store = new DataStore();
398
+ * const _config = {
399
+ signInRedirectURL: "http://localhost:3000/sign-in",
400
+ signOutRedirectURL: "http://localhost:3000/dashboard",
401
+ clientID: "client ID",
402
+ serverOrigin: "https://api.asgardeo.io/t/<org_name>"
403
+ };
404
+ * const auth = new AsgardeoNodeClient(_config,_store);
405
+ * ```
406
+ *
407
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#constructor
408
+ * @preserve
409
+ */
410
+ constructor() {
411
+ __publicField(this, "_authCore");
412
+ }
413
+ async initialize(config, store) {
414
+ this._authCore = new AsgardeoNodeCore(config, store);
415
+ return Promise.resolve(true);
416
+ }
417
+ /**
418
+ * This method logs in a user. If the authorization code is not available it will resolve with the
419
+ * authorization URL to authorize the user.
420
+ * @param {string} authorizationCode - The authorization code obtained from Asgardeo after a user signs in.
421
+ * @param {String} sessionState - The session state obtained from Asgardeo after a user signs in.
422
+ * @param {string} userID - (Optional) A unique ID of the user to be authenticated. This is useful in multi-user
423
+ * scenarios where each user should be uniquely identified.
424
+ * @param {string} state - The state parameter in the redirect URL.
425
+ *
426
+ * @return {Promise<URLResponse | NodeTokenResponse>} - A Promise that resolves with the
427
+ * [`URLResponse`](#URLResponse) object or a Promise that resolves with
428
+ * the [`NodeTokenResponse`](#NodeTokenResponse) object.
429
+ *
430
+ * @example
431
+ * ```
432
+ * authClient.signIn(req.query.code, req.query.session_state).then(response => {
433
+ * //URL property will available if the user has not been authenticated already
434
+ * if (response.hasOwnProperty('url')) {
435
+ * res.redirect(response.url)
436
+ * } else {
437
+ * //Set the cookie
438
+ * res.cookie('ASGARDEO_SESSION_ID', response.session, { maxAge: 900000, httpOnly: true, SameSite: true });
439
+ * res.status(200).send(response)
440
+ * }
441
+ *});
442
+ * ```
443
+ *
444
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#signIn
445
+ *
446
+ * @memberof AsgardeoNodeClient
447
+ *
448
+ */
449
+ async signIn(authURLCallback, userId, authorizationCode, sessionState, state, signInConfig) {
450
+ return this._authCore.signIn(authURLCallback, userId, authorizationCode, sessionState, state, signInConfig);
451
+ }
452
+ /**
453
+ * This method clears all session data and returns the sign-out URL.
454
+ * @param {string} userId - The userId of the user. (If you are using ExpressJS,
455
+ * you may get this from the request cookies)
456
+ *
457
+ * @return {Promise<string>} - A Promise that resolves with the sign-out URL.
458
+ *
459
+ * @example
460
+ * ```
461
+ * const signOutUrl = await auth.signOut(userId);
462
+ * ```
463
+ *
464
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#signOut
465
+ *
466
+ * @memberof AsgardeoNodeClient
467
+ *
468
+ */
469
+ async signOut(userId) {
470
+ return this._authCore.signOut(userId);
471
+ }
472
+ /**
473
+ * This method returns a boolean value indicating if the user is authenticated or not.
474
+ * @param {string} userId - The userId of the user.
475
+ * (If you are using ExpressJS, you may get this from the request cookies)
476
+ *
477
+ * @return { Promise<boolean>} -A boolean value that indicates of the user is authenticated or not.
478
+ *
479
+ * @example
480
+ * ```
481
+ * const isAuth = await authClient.isAuthenticated("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
482
+ * ```
483
+ *
484
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#isAuthenticated
485
+ *
486
+ * @memberof AsgardeoNodeClient
487
+ *
488
+ */
489
+ async isAuthenticated(userId) {
490
+ return this._authCore.isAuthenticated(userId);
491
+ }
492
+ /**
493
+ * This method returns the id token.
494
+ * @param {string} userId - The userId of the user.
495
+ * (If you are using ExpressJS, you may get this from the request cookies)
496
+ *
497
+ * @return {Promise<string>} -A Promise that resolves with the ID Token.
498
+ *
499
+ * @example
500
+ * ```
501
+ * const isAuth = await authClient.getIDToken("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
502
+ * ```
503
+ *
504
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getIDToken
505
+ *
506
+ * @memberof AsgardeoNodeClient
507
+ *
508
+ */
509
+ async getIDToken(userId) {
510
+ return this._authCore.getIDToken(userId);
511
+ }
512
+ /**
513
+ * This method returns an object containing basic user information obtained from the id token.
514
+ * @param {string} userId - The userId of the user.
515
+ * (If you are using ExpressJS, you may get this from the request cookies)
516
+ *
517
+ * @return {Promise<string>} -A Promise that resolves with the
518
+ * An object containing basic user information obtained from the id token.
519
+ *
520
+ * @example
521
+ * ```
522
+ * const basicInfo = await authClient.getBasicUserInfo("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
523
+ * ```
524
+ *
525
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getBasicUserInfo
526
+ *
527
+ * @memberof AsgardeoNodeClient
528
+ *
529
+ */
530
+ async getBasicUserInfo(userId) {
531
+ return this._authCore.getBasicUserInfo(userId);
532
+ }
533
+ /**
534
+ * This method returns an object containing the OIDC service endpoints returned by the `.well-known` endpoint.
535
+ * @return {Promise<OIDCEndpoints>} -A Promise that resolves with
536
+ * an object containing the OIDC service endpoints returned by the `.well-known` endpoint.
537
+ *
538
+ * @example
539
+ * ```
540
+ * const oidcEndpoints = await auth.getOIDCServiceEndpoints();
541
+ * ```
542
+ *
543
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getOIDCServiceEndpoints
544
+ *
545
+ * @memberof AsgardeoNodeClient
546
+ *
547
+ */
548
+ async getOIDCServiceEndpoints() {
549
+ return this._authCore.getOIDCServiceEndpoints();
550
+ }
551
+ /**
552
+ * This method returns the decoded ID token payload.
553
+ * @param {string} userId - The userId of the user.
554
+ * (If you are using ExpressJS, you may get this from the request cookies)
555
+ *
556
+ * @return {Promise<IdTokenPayload>} -A Promise that resolves with
557
+ * an object containing the decoded ID token payload.
558
+ *
559
+ * @example
560
+ * ```
561
+ * const decodedIDTokenPayload = await auth.getDecodedIDToken("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
562
+ * ```
563
+ *
564
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getDecodedIDToken
565
+ *
566
+ * @memberof AsgardeoNodeClient
567
+ *
568
+ */
569
+ async getDecodedIDToken(userId) {
570
+ return this._authCore.getDecodedIDToken(userId);
571
+ }
572
+ /**
573
+ * This method returns the access token.
574
+ * @param {string} userId - The userId of the user.
575
+ * (If you are using ExpressJS, you may get this from the request cookies)
576
+ *
577
+ * @return {Promise<string>} -A Promise that resolves with
578
+ * the access token stored in the store
579
+ *
580
+ * @example
581
+ * ```
582
+ *const accessToken = await auth.getAccessToken("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
583
+ * ```
584
+ *
585
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getAccessToken
586
+ *
587
+ * @memberof AsgardeoNodeClient
588
+ *
589
+ */
590
+ async getAccessToken(userId) {
591
+ return this._authCore.getAccessToken(userId);
592
+ }
593
+ /**
594
+ * This method returns Promise that resolves with the token information
595
+ * or the response returned by the server depending on the configuration passed.
596
+ * @param {CustomGrantConfig} config - The config object contains attributes that would be used
597
+ * to configure the custom grant request.
598
+ *
599
+ * @param {string} userId - The userId of the user.
600
+ * (If you are using ExpressJS, you may get this from the request cookies)
601
+ *
602
+ * @return {Promise<TokenResponse | FetchResponse>} -A Promise that resolves with the token information
603
+ * or the response returned by the server depending on the configuration passed.
604
+ *
605
+ * @example
606
+ * ```
607
+ * const config = {
608
+ * attachToken: false,
609
+ * data: {
610
+ * client_id: "{{clientID}}",
611
+ * grant_type: "account_switch",
612
+ * scope: "{{scope}}",
613
+ * token: "{{token}}",
614
+ * },
615
+ * id: "account-switch",
616
+ * returnResponse: true,
617
+ * returnsSession: true,
618
+ * signInRequired: true
619
+ * }
620
+
621
+ * auth.requestCustomGrant(config).then((response)=>{
622
+ * console.log(response);
623
+ * }).catch((error)=>{
624
+ * console.error(error);
625
+ * });
626
+ * ```
627
+ *
628
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#requestCustomGrant
629
+ *
630
+ * @memberof AsgardeoNodeClient
631
+ *
632
+ */
633
+ async requestCustomGrant(config, userId) {
634
+ return this._authCore.requestCustomGrant(config, userId);
635
+ }
636
+ /**
637
+ * This method can be used to update the configurations passed into the constructor of the AsgardeoAuthClient.
638
+ * @param {AuthClientConfig<T>} config - The config object containing the attributes
639
+ * that can be used to configure the SDK
640
+ *
641
+ * @return {Promise<void>} -A Promise that resolves with a void.
642
+ *
643
+ * @example
644
+ * ```
645
+ * const updateConfig = await auth.updateConfig({
646
+ * signOutRedirectURL: "http://localhost:3000/sign-out"
647
+ * });
648
+ * ```
649
+ *
650
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#updateConfig
651
+ *
652
+ * @memberof AsgardeoNodeClient
653
+ *
654
+ */
655
+ async updateConfig(config) {
656
+ return this._authCore.updateConfig(config);
657
+ }
658
+ /**
659
+ * This method returns a Promise that resolves with the response returned by the server.
660
+ * @param {string} userId - The userId of the user.
661
+ * (If you are using ExpressJS, you may get this from the request cookies)
662
+ *
663
+ * @return {Promise<FetchResponse>} -A Promise that resolves with the response returned by the server.
664
+ *
665
+ * @example
666
+ * ```
667
+ * const revokeToken = await auth.revokeAccessToken("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
668
+ * ```
669
+ *
670
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#revokeAccessToken
671
+ *
672
+ * @memberof AsgardeoNodeClient
673
+ *
674
+ */
675
+ async revokeAccessToken(userId) {
676
+ return this._authCore.revokeAccessToken(userId);
677
+ }
678
+ /**
679
+ * This method refreshes the access token and returns a Promise that resolves with the new access
680
+ * token and other relevant data.
681
+ *
682
+ * @param {string} userId - A unique ID of the user to be authenticated. This is useful in multi-user
683
+ * scenarios where each user should be uniquely identified.
684
+ *
685
+ * @returns {Promise<TokenResponse>} - A Promise that resolves with the token response.
686
+ *
687
+ * @example
688
+ * ```
689
+ * const tokenResponse = await auth.refreshAccessToken("a2a2972c-51cd-5e9d-a9ae-058fae9f7927")
690
+ * ```
691
+ *
692
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#refreshAccessToken
693
+ *
694
+ * @memberof AsgardeoNodeClient
695
+ */
696
+ refreshAccessToken(userId) {
697
+ return this._authCore.refreshAccessToken(userId);
698
+ }
699
+ /**
700
+ * This method returns if the user has been successfully signed out or not.
701
+ * @param {string} signOutRedirectURL - The URL to which the user is redirected to
702
+ * after signing out from the server.
703
+ *
704
+ * @return {boolean} - A boolean value indicating if the user has been signed out or not.
705
+ *
706
+ * @example
707
+ * ```
708
+ * const isSignedOut = auth.isSignOutSuccessful(<signout_url>);;
709
+ * ```
710
+ *
711
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#isSignOutSuccessful
712
+ *
713
+ * @memberof AsgardeoNodeClient
714
+ *
715
+ */
716
+ static isSignOutSuccessful(signOutRedirectURL) {
717
+ return _AsgardeoNodeClient.isSignOutSuccessful(signOutRedirectURL);
718
+ }
719
+ /**
720
+ * This method returns if sign-out failed or not
721
+ * @param {string} signOutRedirectURL - The URL to which the user is redirected to
722
+ * after signing out from the server.
723
+ *
724
+ * @return {boolean} - A boolean value indicating if sign-out failed or not.
725
+ *
726
+ * @example
727
+ * ```
728
+ * const isSignedOut = auth.isSignOutSuccessful(<signout_url>);
729
+ * ```
730
+ *
731
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#didSignOutFail
732
+ *
733
+ * @memberof AsgardeoNodeClient
734
+ *
735
+ */
736
+ static didSignOutFail(signOutRedirectURL) {
737
+ return _AsgardeoNodeClient.didSignOutFail(signOutRedirectURL);
738
+ }
739
+ async getDataLayer() {
740
+ return this._authCore.getDataLayer();
741
+ }
742
+ };
743
+
744
+ // src/constants/CookieConfig.ts
745
+ var CookieConfig = class {
746
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
747
+ constructor() {
748
+ }
749
+ };
750
+ __publicField(CookieConfig, "SESSION_COOKIE_NAME", "ASGARDEO_SESSION_ID");
751
+ __publicField(CookieConfig, "DEFAULT_MAX_AGE", 3600);
752
+ __publicField(CookieConfig, "DEFAULT_HTTP_ONLY", true);
753
+ __publicField(CookieConfig, "DEFAULT_SAME_SITE", "lax");
754
+ __publicField(CookieConfig, "DEFAULT_SECURE", true);
755
+ var CookieConfig_default = CookieConfig;
756
+
757
+ // src/utils/generateSessionId.ts
758
+ var generateSessionId = () => (/* @__PURE__ */ new Date()).getTime().toString(36) + Math.random().toString(36).substring(2);
759
+ var generateSessionId_default = generateSessionId;
760
+
761
+ // src/utils/getSessionCookieOptions.ts
762
+ var getSessionCookieOptions = (options) => ({
763
+ ...options,
764
+ httpOnly: options.httpOnly ?? CookieConfig_default.DEFAULT_HTTP_ONLY,
765
+ maxAge: options.maxAge ?? CookieConfig_default.DEFAULT_MAX_AGE,
766
+ sameSite: options.sameSite ?? CookieConfig_default.DEFAULT_SAME_SITE,
767
+ secure: options.secure ?? CookieConfig_default.DEFAULT_SECURE
768
+ });
769
+ var getSessionCookieOptions_default = getSessionCookieOptions;
770
+
771
+ // src/AsgardeoNodeClient.ts
772
+ var import_javascript2 = require("@asgardeo/javascript");
773
+ var AsgardeoNodeClient2 = class extends import_javascript2.AsgardeoJavaScriptClient {
774
+ };
775
+ var AsgardeoNodeClient_default = AsgardeoNodeClient2;
776
+
777
+ // src/index.ts
778
+ __reExport(index_exports, require("@asgardeo/javascript"), module.exports);
779
+ if (!globalThis.fetch) {
780
+ globalThis.fetch = import_cross_fetch.default;
781
+ globalThis.Headers = import_cross_fetch.Headers;
782
+ globalThis.Request = import_cross_fetch.Request;
783
+ globalThis.Response = import_cross_fetch.Response;
784
+ }
785
+ // Annotate the CommonJS export names for ESM import in node:
786
+ 0 && (module.exports = {
787
+ AsgardeoNodeClient,
788
+ CookieConfig,
789
+ LegacyAsgardeoNodeClient,
790
+ Logger,
791
+ generateSessionId,
792
+ getSessionCookieOptions,
793
+ ...require("@asgardeo/javascript")
794
+ });
795
+ //# sourceMappingURL=index.js.map