@asgardeo/node 0.0.1 → 0.0.3

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/cjs/index.js CHANGED
@@ -197,11 +197,11 @@ var NodeCryptoUtils = class {
197
197
  generateRandomBytes(length) {
198
198
  return (0, import_secure_random_bytes.default)(length);
199
199
  }
200
- async verifyJwt(idToken, jwk, algorithms, clientID, issuer, subject, clockTolerance) {
200
+ async verifyJwt(idToken, jwk, algorithms, clientId, issuer, subject, clockTolerance) {
201
201
  const key = await jose.importJWK(jwk);
202
202
  return jose.jwtVerify(idToken, key, {
203
203
  algorithms,
204
- audience: clientID,
204
+ audience: clientId,
205
205
  clockTolerance,
206
206
  issuer,
207
207
  subject
@@ -217,7 +217,7 @@ var AsgardeoNodeCore = class _AsgardeoNodeCore {
217
217
  __publicField(this, "_auth");
218
218
  __publicField(this, "_cryptoUtils");
219
219
  __publicField(this, "_store");
220
- __publicField(this, "_dataLayer");
220
+ __publicField(this, "_storageManager");
221
221
  if (!store) {
222
222
  this._store = new MemoryCacheStore();
223
223
  } else {
@@ -226,11 +226,11 @@ var AsgardeoNodeCore = class _AsgardeoNodeCore {
226
226
  this._cryptoUtils = new NodeCryptoUtils();
227
227
  this._auth = new import_javascript.AsgardeoAuthClient();
228
228
  this._auth.initialize(config, this._store, this._cryptoUtils);
229
- this._dataLayer = this._auth.getDataLayer();
229
+ this._storageManager = this._auth.getStorageManager();
230
230
  Logger.debug("Initialized AsgardeoAuthClient successfully");
231
231
  }
232
- async signIn(authURLCallback, userID, authorizationCode, sessionState, state, signInConfig) {
233
- if (!userID) {
232
+ async signIn(authURLCallback, userId, authorizationCode, sessionState, state, signInConfig) {
233
+ if (!userId) {
234
234
  return Promise.reject(
235
235
  new import_javascript.AsgardeoAuthException(
236
236
  "NODE-AUTH_CORE-SI-NF01",
@@ -239,8 +239,8 @@ var AsgardeoNodeCore = class _AsgardeoNodeCore {
239
239
  )
240
240
  );
241
241
  }
242
- if (await this.isAuthenticated(userID)) {
243
- const sessionData = await this._dataLayer.getSessionData(userID);
242
+ if (await this.isSignedIn(userId)) {
243
+ const sessionData = await this._storageManager.getSessionData(userId);
244
244
  return Promise.resolve({
245
245
  accessToken: sessionData.access_token,
246
246
  createdAt: sessionData.created_at,
@@ -261,7 +261,7 @@ var AsgardeoNodeCore = class _AsgardeoNodeCore {
261
261
  )
262
262
  );
263
263
  }
264
- const authURL = await this.getAuthURL(userID, signInConfig);
264
+ const authURL = await this.getAuthURL(userId, signInConfig);
265
265
  authURLCallback(authURL);
266
266
  return Promise.resolve({
267
267
  accessToken: "",
@@ -274,10 +274,10 @@ var AsgardeoNodeCore = class _AsgardeoNodeCore {
274
274
  tokenType: ""
275
275
  });
276
276
  }
277
- return this.requestAccessToken(authorizationCode, sessionState ?? "", userID, state);
277
+ return this.requestAccessToken(authorizationCode, sessionState ?? "", userId, state);
278
278
  }
279
279
  async getAuthURL(userId, signInConfig) {
280
- const authURL = await this._auth.getAuthorizationURL(signInConfig, userId);
280
+ const authURL = await this._auth.getSignInUrl(signInConfig, userId);
281
281
  if (authURL) {
282
282
  return Promise.resolve(authURL.toString());
283
283
  } else {
@@ -293,8 +293,8 @@ var AsgardeoNodeCore = class _AsgardeoNodeCore {
293
293
  async requestAccessToken(authorizationCode, sessionState, userId, state) {
294
294
  return this._auth.requestAccessToken(authorizationCode, sessionState, state, userId);
295
295
  }
296
- async getIDToken(userId) {
297
- const is_logged_in = await this.isAuthenticated(userId);
296
+ async getIdToken(userId) {
297
+ const is_logged_in = await this.isSignedIn(userId);
298
298
  if (!is_logged_in) {
299
299
  return Promise.reject(
300
300
  new import_javascript.AsgardeoAuthException(
@@ -304,7 +304,7 @@ var AsgardeoNodeCore = class _AsgardeoNodeCore {
304
304
  )
305
305
  );
306
306
  }
307
- const idToken = await this._auth.getIDToken(userId);
307
+ const idToken = await this._auth.getIdToken(userId);
308
308
  if (idToken) {
309
309
  return Promise.resolve(idToken);
310
310
  } else {
@@ -320,27 +320,27 @@ var AsgardeoNodeCore = class _AsgardeoNodeCore {
320
320
  async refreshAccessToken(userId) {
321
321
  return this._auth.refreshAccessToken(userId);
322
322
  }
323
- async isAuthenticated(userId) {
323
+ async isSignedIn(userId) {
324
324
  try {
325
- if (!await this._auth.isAuthenticated(userId)) {
325
+ if (!await this._auth.isSignedIn(userId)) {
326
326
  return Promise.resolve(false);
327
327
  }
328
- if (await SessionUtils.validateSession(await this._dataLayer.getSessionData(userId))) {
328
+ if (await SessionUtils.validateSession(await this._storageManager.getSessionData(userId))) {
329
329
  return Promise.resolve(true);
330
330
  }
331
331
  const refreshed_token = await this.refreshAccessToken(userId);
332
332
  if (refreshed_token) {
333
333
  return Promise.resolve(true);
334
334
  }
335
- this._dataLayer.removeSessionData(userId);
336
- this._dataLayer.getTemporaryData(userId);
335
+ this._storageManager.removeSessionData(userId);
336
+ this._storageManager.getTemporaryData(userId);
337
337
  return Promise.resolve(false);
338
338
  } catch (error) {
339
339
  return Promise.reject(error);
340
340
  }
341
341
  }
342
342
  async signOut(userId) {
343
- const signOutURL = await this._auth.getSignOutURL(userId);
343
+ const signOutURL = await this._auth.getSignOutUrl(userId);
344
344
  if (!signOutURL) {
345
345
  return Promise.reject(
346
346
  new import_javascript.AsgardeoAuthException(
@@ -352,35 +352,38 @@ var AsgardeoNodeCore = class _AsgardeoNodeCore {
352
352
  }
353
353
  return Promise.resolve(signOutURL);
354
354
  }
355
- async getBasicUserInfo(userId) {
356
- return this._auth.getBasicUserInfo(userId);
355
+ async getUser(userId) {
356
+ return this._auth.getUser(userId);
357
+ }
358
+ async getConfigData() {
359
+ return this._storageManager.getConfigData();
357
360
  }
358
- async getOIDCServiceEndpoints() {
359
- return this._auth.getOIDCServiceEndpoints();
361
+ async getOpenIDProviderEndpoints() {
362
+ return this._auth.getOpenIDProviderEndpoints();
360
363
  }
361
- async getDecodedIDToken(userId) {
362
- return this._auth.getDecodedIDToken(userId);
364
+ async getDecodedIdToken(userId) {
365
+ return this._auth.getDecodedIdToken(userId);
363
366
  }
364
367
  async getAccessToken(userId) {
365
368
  return this._auth.getAccessToken(userId);
366
369
  }
367
- async requestCustomGrant(config, userId) {
368
- return this._auth.requestCustomGrant(config, userId);
370
+ async exchangeToken(config, userId) {
371
+ return this._auth.exchangeToken(config, userId);
369
372
  }
370
- async updateConfig(config) {
371
- return this._auth.updateConfig(config);
373
+ async reInitialize(config) {
374
+ return this._auth.reInitialize(config);
372
375
  }
373
376
  async revokeAccessToken(userId) {
374
377
  return this._auth.revokeAccessToken(userId);
375
378
  }
376
- static didSignOutFail(signOutRedirectURL) {
377
- return _AsgardeoNodeCore.didSignOutFail(signOutRedirectURL);
379
+ static didSignOutFail(afterSignOutUrl) {
380
+ return _AsgardeoNodeCore.didSignOutFail(afterSignOutUrl);
378
381
  }
379
- static isSignOutSuccessful(signOutRedirectURL) {
380
- return _AsgardeoNodeCore.isSignOutSuccessful(signOutRedirectURL);
382
+ static isSignOutSuccessful(afterSignOutUrl) {
383
+ return _AsgardeoNodeCore.isSignOutSuccessful(afterSignOutUrl);
381
384
  }
382
- getDataLayer() {
383
- return this._dataLayer;
385
+ getStorageManager() {
386
+ return this._storageManager;
384
387
  }
385
388
  };
386
389
 
@@ -390,15 +393,15 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
390
393
  * This is the constructor method that returns an instance of the `AsgardeoNodeClient` class.
391
394
  *
392
395
  * @param {AuthClientConfig<T>} config - The configuration object.
393
- * @param {Store} store - The store object.
396
+ * @param {Storage} store - The store object.
394
397
  *
395
398
  * @example
396
399
  * ```
397
- * const _store: Store = new DataStore();
400
+ * const _store: Storage = new DataStore();
398
401
  * const _config = {
399
- signInRedirectURL: "http://localhost:3000/sign-in",
400
- signOutRedirectURL: "http://localhost:3000/dashboard",
401
- clientID: "client ID",
402
+ afterSignInUrl: "http://localhost:3000/sign-in",
403
+ afterSignOutUrl: "http://localhost:3000/dashboard",
404
+ clientId: "client ID",
402
405
  serverOrigin: "https://api.asgardeo.io/t/<org_name>"
403
406
  };
404
407
  * const auth = new AsgardeoNodeClient(_config,_store);
@@ -419,7 +422,7 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
419
422
  * authorization URL to authorize the user.
420
423
  * @param {string} authorizationCode - The authorization code obtained from Asgardeo after a user signs in.
421
424
  * @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
425
+ * @param {string} userId - (Optional) A unique ID of the user to be authenticated. This is useful in multi-user
423
426
  * scenarios where each user should be uniquely identified.
424
427
  * @param {string} state - The state parameter in the redirect URL.
425
428
  *
@@ -449,6 +452,14 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
449
452
  async signIn(authURLCallback, userId, authorizationCode, sessionState, state, signInConfig) {
450
453
  return this._authCore.signIn(authURLCallback, userId, authorizationCode, sessionState, state, signInConfig);
451
454
  }
455
+ /**
456
+ * Method to get the configuration data.
457
+ *
458
+ * @returns {Promise<AuthClientConfig<Config>>} - A promise that resolves with the configuration data.
459
+ */
460
+ async getConfigData() {
461
+ return this._authCore.getConfigData();
462
+ }
452
463
  /**
453
464
  * This method clears all session data and returns the sign-out URL.
454
465
  * @param {string} userId - The userId of the user. (If you are using ExpressJS,
@@ -478,16 +489,16 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
478
489
  *
479
490
  * @example
480
491
  * ```
481
- * const isAuth = await authClient.isAuthenticated("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
492
+ * const isAuth = await authClient.isSignedIn("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
482
493
  * ```
483
494
  *
484
- * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#isAuthenticated
495
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#isSignedIn
485
496
  *
486
497
  * @memberof AsgardeoNodeClient
487
498
  *
488
499
  */
489
- async isAuthenticated(userId) {
490
- return this._authCore.isAuthenticated(userId);
500
+ async isSignedIn(userId) {
501
+ return this._authCore.isSignedIn(userId);
491
502
  }
492
503
  /**
493
504
  * This method returns the id token.
@@ -498,16 +509,16 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
498
509
  *
499
510
  * @example
500
511
  * ```
501
- * const isAuth = await authClient.getIDToken("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
512
+ * const isAuth = await authClient.getIdToken("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
502
513
  * ```
503
514
  *
504
- * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getIDToken
515
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getIdToken
505
516
  *
506
517
  * @memberof AsgardeoNodeClient
507
518
  *
508
519
  */
509
- async getIDToken(userId) {
510
- return this._authCore.getIDToken(userId);
520
+ async getIdToken(userId) {
521
+ return this._authCore.getIdToken(userId);
511
522
  }
512
523
  /**
513
524
  * This method returns an object containing basic user information obtained from the id token.
@@ -519,16 +530,16 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
519
530
  *
520
531
  * @example
521
532
  * ```
522
- * const basicInfo = await authClient.getBasicUserInfo("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
533
+ * const basicInfo = await authClient.getUser("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
523
534
  * ```
524
535
  *
525
- * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getBasicUserInfo
536
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getUser
526
537
  *
527
538
  * @memberof AsgardeoNodeClient
528
539
  *
529
540
  */
530
- async getBasicUserInfo(userId) {
531
- return this._authCore.getBasicUserInfo(userId);
541
+ async getUser(userId) {
542
+ return this._authCore.getUser(userId);
532
543
  }
533
544
  /**
534
545
  * This method returns an object containing the OIDC service endpoints returned by the `.well-known` endpoint.
@@ -537,37 +548,37 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
537
548
  *
538
549
  * @example
539
550
  * ```
540
- * const oidcEndpoints = await auth.getOIDCServiceEndpoints();
551
+ * const oidcEndpoints = await auth.getOpenIDProviderEndpoints();
541
552
  * ```
542
553
  *
543
- * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getOIDCServiceEndpoints
554
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getOpenIDProviderEndpoints
544
555
  *
545
556
  * @memberof AsgardeoNodeClient
546
557
  *
547
558
  */
548
- async getOIDCServiceEndpoints() {
549
- return this._authCore.getOIDCServiceEndpoints();
559
+ async getOpenIDProviderEndpoints() {
560
+ return this._authCore.getOpenIDProviderEndpoints();
550
561
  }
551
562
  /**
552
563
  * This method returns the decoded ID token payload.
553
564
  * @param {string} userId - The userId of the user.
554
565
  * (If you are using ExpressJS, you may get this from the request cookies)
555
566
  *
556
- * @return {Promise<IdTokenPayload>} -A Promise that resolves with
567
+ * @return {Promise<IdToken>} -A Promise that resolves with
557
568
  * an object containing the decoded ID token payload.
558
569
  *
559
570
  * @example
560
571
  * ```
561
- * const decodedIDTokenPayload = await auth.getDecodedIDToken("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
572
+ * const decodedIDTokenPayload = await auth.getDecodedIdToken("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
562
573
  * ```
563
574
  *
564
- * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getDecodedIDToken
575
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getDecodedIdToken
565
576
  *
566
577
  * @memberof AsgardeoNodeClient
567
578
  *
568
579
  */
569
- async getDecodedIDToken(userId) {
570
- return this._authCore.getDecodedIDToken(userId);
580
+ async getDecodedIdToken(userId) {
581
+ return this._authCore.getDecodedIdToken(userId);
571
582
  }
572
583
  /**
573
584
  * This method returns the access token.
@@ -591,15 +602,15 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
591
602
  return this._authCore.getAccessToken(userId);
592
603
  }
593
604
  /**
594
- * This method returns Promise that resolves with the token information
605
+ * This method returns Promise that resolves with the token information
595
606
  * 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
607
+ * @param {TokenExchangeRequestConfig} config - The config object contains attributes that would be used
597
608
  * to configure the custom grant request.
598
609
  *
599
610
  * @param {string} userId - The userId of the user.
600
611
  * (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
612
+ *
613
+ * @return {Promise<TokenResponse | Response>} -A Promise that resolves with the token information
603
614
  * or the response returned by the server depending on the configuration passed.
604
615
  *
605
616
  * @example
@@ -607,7 +618,7 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
607
618
  * const config = {
608
619
  * attachToken: false,
609
620
  * data: {
610
- * client_id: "{{clientID}}",
621
+ * client_id: "{{clientId}}",
611
622
  * grant_type: "account_switch",
612
623
  * scope: "{{scope}}",
613
624
  * token: "{{token}}",
@@ -618,20 +629,20 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
618
629
  * signInRequired: true
619
630
  * }
620
631
 
621
- * auth.requestCustomGrant(config).then((response)=>{
632
+ * auth.exchangeToken(config).then((response)=>{
622
633
  * console.log(response);
623
634
  * }).catch((error)=>{
624
635
  * console.error(error);
625
636
  * });
626
637
  * ```
627
638
  *
628
- * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#requestCustomGrant
639
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#exchangeToken
629
640
  *
630
641
  * @memberof AsgardeoNodeClient
631
642
  *
632
643
  */
633
- async requestCustomGrant(config, userId) {
634
- return this._authCore.requestCustomGrant(config, userId);
644
+ async exchangeToken(config, userId) {
645
+ return this._authCore.exchangeToken(config, userId);
635
646
  }
636
647
  /**
637
648
  * This method can be used to update the configurations passed into the constructor of the AsgardeoAuthClient.
@@ -642,25 +653,28 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
642
653
  *
643
654
  * @example
644
655
  * ```
645
- * const updateConfig = await auth.updateConfig({
646
- * signOutRedirectURL: "http://localhost:3000/sign-out"
656
+ * const reInitialize = await auth.reInitialize({
657
+ * afterSignOutUrl: "http://localhost:3000/sign-out"
647
658
  * });
648
659
  * ```
649
660
  *
650
- * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#updateConfig
661
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#reInitialize
651
662
  *
652
663
  * @memberof AsgardeoNodeClient
653
664
  *
654
665
  */
655
- async updateConfig(config) {
656
- return this._authCore.updateConfig(config);
666
+ async reInitialize(config) {
667
+ return this._authCore.reInitialize(config);
668
+ }
669
+ async getSignInUrl(requestConfig, userId) {
670
+ return this._authCore.getAuthURL(userId, requestConfig);
657
671
  }
658
672
  /**
659
673
  * This method returns a Promise that resolves with the response returned by the server.
660
674
  * @param {string} userId - The userId of the user.
661
675
  * (If you are using ExpressJS, you may get this from the request cookies)
662
676
  *
663
- * @return {Promise<FetchResponse>} -A Promise that resolves with the response returned by the server.
677
+ * @return {Promise<Response>} -A Promise that resolves with the response returned by the server.
664
678
  *
665
679
  * @example
666
680
  * ```
@@ -698,7 +712,7 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
698
712
  }
699
713
  /**
700
714
  * 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
715
+ * @param {string} afterSignOutUrl - The URL to which the user is redirected to
702
716
  * after signing out from the server.
703
717
  *
704
718
  * @return {boolean} - A boolean value indicating if the user has been signed out or not.
@@ -713,12 +727,12 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
713
727
  * @memberof AsgardeoNodeClient
714
728
  *
715
729
  */
716
- static isSignOutSuccessful(signOutRedirectURL) {
717
- return _AsgardeoNodeClient.isSignOutSuccessful(signOutRedirectURL);
730
+ static isSignOutSuccessful(afterSignOutUrl) {
731
+ return _AsgardeoNodeClient.isSignOutSuccessful(afterSignOutUrl);
718
732
  }
719
733
  /**
720
734
  * This method returns if sign-out failed or not
721
- * @param {string} signOutRedirectURL - The URL to which the user is redirected to
735
+ * @param {string} afterSignOutUrl - The URL to which the user is redirected to
722
736
  * after signing out from the server.
723
737
  *
724
738
  * @return {boolean} - A boolean value indicating if sign-out failed or not.
@@ -733,11 +747,11 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
733
747
  * @memberof AsgardeoNodeClient
734
748
  *
735
749
  */
736
- static didSignOutFail(signOutRedirectURL) {
737
- return _AsgardeoNodeClient.didSignOutFail(signOutRedirectURL);
750
+ static didSignOutFail(afterSignOutUrl) {
751
+ return _AsgardeoNodeClient.didSignOutFail(afterSignOutUrl);
738
752
  }
739
- async getDataLayer() {
740
- return this._authCore.getDataLayer();
753
+ async getStorageManager() {
754
+ return this._authCore.getStorageManager();
741
755
  }
742
756
  };
743
757