@asgardeo/node 0.0.50 → 0.0.51

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -14,12 +14,15 @@ import {
14
14
  // src/__legacy__/stores/memory-cache-store.ts
15
15
  import cache from "memory-cache";
16
16
  var MemoryCacheStore = class {
17
+ // eslint-disable-next-line class-methods-use-this
17
18
  async setData(key, value) {
18
19
  cache.put(key, value);
19
20
  }
21
+ // eslint-disable-next-line class-methods-use-this
20
22
  async getData(key) {
21
23
  return cache.get(key) ?? "{}";
22
24
  }
25
+ // eslint-disable-next-line class-methods-use-this
23
26
  async removeData(key) {
24
27
  cache.del(key);
25
28
  }
@@ -51,25 +54,23 @@ var SessionUtils = class {
51
54
  constructor() {
52
55
  }
53
56
  static createUUID() {
54
- const generated_uuid = uuidv4();
55
- return generated_uuid;
57
+ const generatedUuid = uuidv4();
58
+ return generatedUuid;
56
59
  }
57
60
  static validateUUID(uuid) {
58
61
  if (uuidValidate(uuid) && uuidVersion(uuid) === UUID_VERSION) {
59
62
  return Promise.resolve(true);
60
- } else {
61
- return Promise.resolve(false);
62
63
  }
64
+ return Promise.resolve(false);
63
65
  }
64
66
  static validateSession(sessionData) {
65
67
  const currentTime = Date.now();
66
- const expiryTimeStamp = sessionData.created_at + parseInt(sessionData.expires_in) * 60 * 1e3;
68
+ const expiryTimeStamp = sessionData.created_at + parseInt(sessionData.expires_in, 10) * 60 * 1e3;
67
69
  if (currentTime < expiryTimeStamp) {
68
70
  return Promise.resolve(true);
69
- } else {
70
- Logger.warn("Expired Session");
71
- return Promise.resolve(false);
72
71
  }
72
+ Logger.warn("Expired Session");
73
+ return Promise.resolve(false);
73
74
  }
74
75
  };
75
76
 
@@ -151,18 +152,23 @@ var NodeCryptoUtils = class {
151
152
  *
152
153
  * @returns {string} base 64 url encoded value.
153
154
  */
155
+ // eslint-disable-next-line class-methods-use-this
154
156
  base64URLEncode(value) {
155
157
  return base64url.encode(value).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
156
158
  }
159
+ // eslint-disable-next-line class-methods-use-this
157
160
  base64URLDecode(value) {
158
161
  return base64url.decode(value).toString();
159
162
  }
163
+ // eslint-disable-next-line class-methods-use-this
160
164
  hashSha256(data) {
161
165
  return Buffer.from(sha256(new TextEncoder().encode(data)));
162
166
  }
167
+ // eslint-disable-next-line class-methods-use-this
163
168
  generateRandomBytes(length) {
164
169
  return randombytes(length);
165
170
  }
171
+ // eslint-disable-next-line class-methods-use-this
166
172
  async verifyJwt(idToken, jwk, algorithms, clientId, issuer, subject, clockTolerance) {
167
173
  const key = await jose.importJWK(jwk);
168
174
  return jose.jwtVerify(idToken, key, {
@@ -171,28 +177,26 @@ var NodeCryptoUtils = class {
171
177
  clockTolerance,
172
178
  issuer,
173
179
  subject
174
- }).then(() => {
175
- return Promise.resolve(true);
176
- });
180
+ }).then(() => Promise.resolve(true));
177
181
  }
178
182
  };
179
183
 
180
184
  // src/__legacy__/core/authentication.ts
181
185
  var AsgardeoNodeCore = class _AsgardeoNodeCore {
182
186
  constructor(config, store) {
183
- __publicField(this, "_auth");
184
- __publicField(this, "_cryptoUtils");
185
- __publicField(this, "_store");
186
- __publicField(this, "_storageManager");
187
+ __publicField(this, "auth");
188
+ __publicField(this, "cryptoUtils");
189
+ __publicField(this, "store");
190
+ __publicField(this, "storageManager");
187
191
  if (!store) {
188
- this._store = new MemoryCacheStore();
192
+ this.store = new MemoryCacheStore();
189
193
  } else {
190
- this._store = store;
194
+ this.store = store;
191
195
  }
192
- this._cryptoUtils = new NodeCryptoUtils();
193
- this._auth = new AsgardeoAuthClient();
194
- this._auth.initialize(config, this._store, this._cryptoUtils);
195
- this._storageManager = this._auth.getStorageManager();
196
+ this.cryptoUtils = new NodeCryptoUtils();
197
+ this.auth = new AsgardeoAuthClient();
198
+ this.auth.initialize(config, this.store, this.cryptoUtils);
199
+ this.storageManager = this.auth.getStorageManager();
196
200
  Logger.debug("Initialized AsgardeoAuthClient successfully");
197
201
  }
198
202
  async signIn(authURLCallback, userId, authorizationCode, sessionState, state, signInConfig) {
@@ -206,7 +210,7 @@ var AsgardeoNodeCore = class _AsgardeoNodeCore {
206
210
  );
207
211
  }
208
212
  if (await this.isSignedIn(userId)) {
209
- const sessionData = await this._storageManager.getSessionData(userId);
213
+ const sessionData = await this.storageManager.getSessionData(userId);
210
214
  return Promise.resolve({
211
215
  accessToken: sessionData.access_token,
212
216
  createdAt: sessionData.created_at,
@@ -243,25 +247,24 @@ var AsgardeoNodeCore = class _AsgardeoNodeCore {
243
247
  return this.requestAccessToken(authorizationCode, sessionState ?? "", userId, state);
244
248
  }
245
249
  async getAuthURL(userId, signInConfig) {
246
- const authURL = await this._auth.getSignInUrl(signInConfig, userId);
250
+ const authURL = await this.auth.getSignInUrl(signInConfig, userId);
247
251
  if (authURL) {
248
252
  return Promise.resolve(authURL.toString());
249
- } else {
250
- return Promise.reject(
251
- new AsgardeoAuthException(
252
- "NODE-AUTH_CORE-GAU-NF01",
253
- "Getting Authorization URL failed.",
254
- "No authorization URL was returned by the Asgardeo Auth JS SDK."
255
- )
256
- );
257
253
  }
254
+ return Promise.reject(
255
+ new AsgardeoAuthException(
256
+ "NODE-AUTH_CORE-GAU-NF01",
257
+ "Getting Authorization URL failed.",
258
+ "No authorization URL was returned by the Asgardeo Auth JS SDK."
259
+ )
260
+ );
258
261
  }
259
262
  async requestAccessToken(authorizationCode, sessionState, userId, state) {
260
- return this._auth.requestAccessToken(authorizationCode, sessionState, state, userId);
263
+ return this.auth.requestAccessToken(authorizationCode, sessionState, state, userId);
261
264
  }
262
265
  async getIdToken(userId) {
263
- const is_logged_in = await this.isSignedIn(userId);
264
- if (!is_logged_in) {
266
+ const isLoggedIn = await this.isSignedIn(userId);
267
+ if (!isLoggedIn) {
265
268
  return Promise.reject(
266
269
  new AsgardeoAuthException(
267
270
  "NODE-AUTH_CORE-GIT-NF01",
@@ -270,43 +273,42 @@ var AsgardeoNodeCore = class _AsgardeoNodeCore {
270
273
  )
271
274
  );
272
275
  }
273
- const idToken = await this._auth.getIdToken(userId);
276
+ const idToken = await this.auth.getIdToken(userId);
274
277
  if (idToken) {
275
278
  return Promise.resolve(idToken);
276
- } else {
277
- return Promise.reject(
278
- new AsgardeoAuthException(
279
- "NODE-AUTH_CORE-GIT-NF02",
280
- "Requesting ID Token Failed",
281
- "No ID Token was returned by the Asgardeo Auth JS SDK."
282
- )
283
- );
284
279
  }
280
+ return Promise.reject(
281
+ new AsgardeoAuthException(
282
+ "NODE-AUTH_CORE-GIT-NF02",
283
+ "Requesting ID Token Failed",
284
+ "No ID Token was returned by the Asgardeo Auth JS SDK."
285
+ )
286
+ );
285
287
  }
286
288
  async refreshAccessToken(userId) {
287
- return this._auth.refreshAccessToken(userId);
289
+ return this.auth.refreshAccessToken(userId);
288
290
  }
289
291
  async isSignedIn(userId) {
290
292
  try {
291
- if (!await this._auth.isSignedIn(userId)) {
293
+ if (!await this.auth.isSignedIn(userId)) {
292
294
  return Promise.resolve(false);
293
295
  }
294
- if (await SessionUtils.validateSession(await this._storageManager.getSessionData(userId))) {
296
+ if (await SessionUtils.validateSession(await this.storageManager.getSessionData(userId))) {
295
297
  return Promise.resolve(true);
296
298
  }
297
- const refreshed_token = await this.refreshAccessToken(userId);
298
- if (refreshed_token) {
299
+ const refreshedToken = await this.refreshAccessToken(userId);
300
+ if (refreshedToken) {
299
301
  return Promise.resolve(true);
300
302
  }
301
- this._storageManager.removeSessionData(userId);
302
- this._storageManager.getTemporaryData(userId);
303
+ this.storageManager.removeSessionData(userId);
304
+ this.storageManager.getTemporaryData(userId);
303
305
  return Promise.resolve(false);
304
306
  } catch (error) {
305
307
  return Promise.reject(error);
306
308
  }
307
309
  }
308
310
  async signOut(userId) {
309
- const signOutURL = await this._auth.getSignOutUrl(userId);
311
+ const signOutURL = await this.auth.getSignOutUrl(userId);
310
312
  if (!signOutURL) {
311
313
  return Promise.reject(
312
314
  new AsgardeoAuthException(
@@ -319,28 +321,28 @@ var AsgardeoNodeCore = class _AsgardeoNodeCore {
319
321
  return Promise.resolve(signOutURL);
320
322
  }
321
323
  async getUser(userId) {
322
- return this._auth.getUser(userId);
324
+ return this.auth.getUser(userId);
323
325
  }
324
326
  async getConfigData() {
325
- return this._storageManager.getConfigData();
327
+ return this.storageManager.getConfigData();
326
328
  }
327
329
  async getOpenIDProviderEndpoints() {
328
- return this._auth.getOpenIDProviderEndpoints();
330
+ return this.auth.getOpenIDProviderEndpoints();
329
331
  }
330
332
  async getDecodedIdToken(userId, idToken) {
331
- return this._auth.getDecodedIdToken(userId, idToken);
333
+ return this.auth.getDecodedIdToken(userId, idToken);
332
334
  }
333
335
  async getAccessToken(userId) {
334
- return this._auth.getAccessToken(userId);
336
+ return this.auth.getAccessToken(userId);
335
337
  }
336
338
  async exchangeToken(config, userId) {
337
- return this._auth.exchangeToken(config, userId);
339
+ return this.auth.exchangeToken(config, userId);
338
340
  }
339
341
  async reInitialize(config) {
340
- return this._auth.reInitialize(config);
342
+ return this.auth.reInitialize(config);
341
343
  }
342
344
  async revokeAccessToken(userId) {
343
- return this._auth.revokeAccessToken(userId);
345
+ return this.auth.revokeAccessToken(userId);
344
346
  }
345
347
  static didSignOutFail(afterSignOutUrl) {
346
348
  return _AsgardeoNodeCore.didSignOutFail(afterSignOutUrl);
@@ -349,10 +351,10 @@ var AsgardeoNodeCore = class _AsgardeoNodeCore {
349
351
  return _AsgardeoNodeCore.isSignOutSuccessful(afterSignOutUrl);
350
352
  }
351
353
  getStorageManager() {
352
- return this._storageManager;
354
+ return this.storageManager;
353
355
  }
354
356
  async decodeJwtToken(token) {
355
- return this._auth.decodeJwtToken(token);
357
+ return this.auth.decodeJwtToken(token);
356
358
  }
357
359
  };
358
360
 
@@ -379,11 +381,12 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
379
381
  * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#constructor
380
382
  * @preserve
381
383
  */
384
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
382
385
  constructor() {
383
- __publicField(this, "_authCore");
386
+ __publicField(this, "authCore");
384
387
  }
385
388
  async initialize(config, store) {
386
- this._authCore = new AsgardeoNodeCore(config, store);
389
+ this.authCore = new AsgardeoNodeCore(config, store);
387
390
  return Promise.resolve(true);
388
391
  }
389
392
  /**
@@ -419,7 +422,7 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
419
422
  *
420
423
  */
421
424
  async signIn(authURLCallback, userId, authorizationCode, sessionState, state, signInConfig) {
422
- return this._authCore.signIn(authURLCallback, userId, authorizationCode, sessionState, state, signInConfig);
425
+ return this.authCore.signIn(authURLCallback, userId, authorizationCode, sessionState, state, signInConfig);
423
426
  }
424
427
  /**
425
428
  * Method to get the configuration data.
@@ -427,7 +430,7 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
427
430
  * @returns {Promise<AuthClientConfig<Config>>} - A promise that resolves with the configuration data.
428
431
  */
429
432
  async getConfigData() {
430
- return this._authCore.getConfigData();
433
+ return this.authCore.getConfigData();
431
434
  }
432
435
  /**
433
436
  * This method clears all session data and returns the sign-out URL.
@@ -447,7 +450,7 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
447
450
  *
448
451
  */
449
452
  async signOut(userId) {
450
- return this._authCore.signOut(userId);
453
+ return this.authCore.signOut(userId);
451
454
  }
452
455
  /**
453
456
  * This method returns a boolean value indicating if the user is authenticated or not.
@@ -467,7 +470,7 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
467
470
  *
468
471
  */
469
472
  async isSignedIn(userId) {
470
- return this._authCore.isSignedIn(userId);
473
+ return this.authCore.isSignedIn(userId);
471
474
  }
472
475
  /**
473
476
  * This method returns the id token.
@@ -487,7 +490,7 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
487
490
  *
488
491
  */
489
492
  async getIdToken(userId) {
490
- return this._authCore.getIdToken(userId);
493
+ return this.authCore.getIdToken(userId);
491
494
  }
492
495
  /**
493
496
  * This method returns an object containing basic user information obtained from the id token.
@@ -508,7 +511,7 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
508
511
  *
509
512
  */
510
513
  async getUser(userId) {
511
- return this._authCore.getUser(userId);
514
+ return this.authCore.getUser(userId);
512
515
  }
513
516
  /**
514
517
  * This method returns an object containing the OIDC service endpoints returned by the `.well-known` endpoint.
@@ -526,7 +529,7 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
526
529
  *
527
530
  */
528
531
  async getOpenIDProviderEndpoints() {
529
- return this._authCore.getOpenIDProviderEndpoints();
532
+ return this.authCore.getOpenIDProviderEndpoints();
530
533
  }
531
534
  /**
532
535
  * This method returns the decoded ID token payload.
@@ -547,7 +550,7 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
547
550
  *
548
551
  */
549
552
  async getDecodedIdToken(userId, idToken) {
550
- return this._authCore.getDecodedIdToken(userId, idToken);
553
+ return this.authCore.getDecodedIdToken(userId, idToken);
551
554
  }
552
555
  /**
553
556
  * This method returns the access token.
@@ -568,7 +571,7 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
568
571
  *
569
572
  */
570
573
  async getAccessToken(userId) {
571
- return this._authCore.getAccessToken(userId);
574
+ return this.authCore.getAccessToken(userId);
572
575
  }
573
576
  /**
574
577
  * This method returns Promise that resolves with the token information
@@ -611,7 +614,7 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
611
614
  *
612
615
  */
613
616
  async exchangeToken(config, userId) {
614
- return this._authCore.exchangeToken(config, userId);
617
+ return this.authCore.exchangeToken(config, userId);
615
618
  }
616
619
  /**
617
620
  * This method can be used to update the configurations passed into the constructor of the AsgardeoAuthClient.
@@ -633,10 +636,10 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
633
636
  *
634
637
  */
635
638
  async reInitialize(config) {
636
- return this._authCore.reInitialize(config);
639
+ return this.authCore.reInitialize(config);
637
640
  }
638
641
  async getSignInUrl(requestConfig, userId) {
639
- return this._authCore.getAuthURL(userId, requestConfig);
642
+ return this.authCore.getAuthURL(userId, requestConfig);
640
643
  }
641
644
  /**
642
645
  * This method returns a Promise that resolves with the response returned by the server.
@@ -656,7 +659,7 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
656
659
  *
657
660
  */
658
661
  async revokeAccessToken(userId) {
659
- return this._authCore.revokeAccessToken(userId);
662
+ return this.authCore.revokeAccessToken(userId);
660
663
  }
661
664
  /**
662
665
  * This method refreshes the access token and returns a Promise that resolves with the new access
@@ -677,7 +680,7 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
677
680
  * @memberof AsgardeoNodeClient
678
681
  */
679
682
  refreshAccessToken(userId) {
680
- return this._authCore.refreshAccessToken(userId);
683
+ return this.authCore.refreshAccessToken(userId);
681
684
  }
682
685
  /**
683
686
  * This method returns if the user has been successfully signed out or not.
@@ -720,10 +723,10 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
720
723
  return _AsgardeoNodeClient.didSignOutFail(afterSignOutUrl);
721
724
  }
722
725
  async getStorageManager() {
723
- return this._authCore.getStorageManager();
726
+ return this.authCore.getStorageManager();
724
727
  }
725
728
  async decodeJwtToken(token) {
726
- return this._authCore.decodeJwtToken(token);
729
+ return this.authCore.decodeJwtToken(token);
727
730
  }
728
731
  };
729
732