@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/index.js CHANGED
@@ -163,11 +163,11 @@ var NodeCryptoUtils = class {
163
163
  generateRandomBytes(length) {
164
164
  return randombytes(length);
165
165
  }
166
- async verifyJwt(idToken, jwk, algorithms, clientID, issuer, subject, clockTolerance) {
166
+ async verifyJwt(idToken, jwk, algorithms, clientId, issuer, subject, clockTolerance) {
167
167
  const key = await jose.importJWK(jwk);
168
168
  return jose.jwtVerify(idToken, key, {
169
169
  algorithms,
170
- audience: clientID,
170
+ audience: clientId,
171
171
  clockTolerance,
172
172
  issuer,
173
173
  subject
@@ -183,7 +183,7 @@ var AsgardeoNodeCore = class _AsgardeoNodeCore {
183
183
  __publicField(this, "_auth");
184
184
  __publicField(this, "_cryptoUtils");
185
185
  __publicField(this, "_store");
186
- __publicField(this, "_dataLayer");
186
+ __publicField(this, "_storageManager");
187
187
  if (!store) {
188
188
  this._store = new MemoryCacheStore();
189
189
  } else {
@@ -192,11 +192,11 @@ var AsgardeoNodeCore = class _AsgardeoNodeCore {
192
192
  this._cryptoUtils = new NodeCryptoUtils();
193
193
  this._auth = new AsgardeoAuthClient();
194
194
  this._auth.initialize(config, this._store, this._cryptoUtils);
195
- this._dataLayer = this._auth.getDataLayer();
195
+ this._storageManager = this._auth.getStorageManager();
196
196
  Logger.debug("Initialized AsgardeoAuthClient successfully");
197
197
  }
198
- async signIn(authURLCallback, userID, authorizationCode, sessionState, state, signInConfig) {
199
- if (!userID) {
198
+ async signIn(authURLCallback, userId, authorizationCode, sessionState, state, signInConfig) {
199
+ if (!userId) {
200
200
  return Promise.reject(
201
201
  new AsgardeoAuthException(
202
202
  "NODE-AUTH_CORE-SI-NF01",
@@ -205,8 +205,8 @@ var AsgardeoNodeCore = class _AsgardeoNodeCore {
205
205
  )
206
206
  );
207
207
  }
208
- if (await this.isAuthenticated(userID)) {
209
- const sessionData = await this._dataLayer.getSessionData(userID);
208
+ if (await this.isSignedIn(userId)) {
209
+ const sessionData = await this._storageManager.getSessionData(userId);
210
210
  return Promise.resolve({
211
211
  accessToken: sessionData.access_token,
212
212
  createdAt: sessionData.created_at,
@@ -227,7 +227,7 @@ var AsgardeoNodeCore = class _AsgardeoNodeCore {
227
227
  )
228
228
  );
229
229
  }
230
- const authURL = await this.getAuthURL(userID, signInConfig);
230
+ const authURL = await this.getAuthURL(userId, signInConfig);
231
231
  authURLCallback(authURL);
232
232
  return Promise.resolve({
233
233
  accessToken: "",
@@ -240,10 +240,10 @@ var AsgardeoNodeCore = class _AsgardeoNodeCore {
240
240
  tokenType: ""
241
241
  });
242
242
  }
243
- return this.requestAccessToken(authorizationCode, sessionState ?? "", userID, state);
243
+ return this.requestAccessToken(authorizationCode, sessionState ?? "", userId, state);
244
244
  }
245
245
  async getAuthURL(userId, signInConfig) {
246
- const authURL = await this._auth.getAuthorizationURL(signInConfig, userId);
246
+ const authURL = await this._auth.getSignInUrl(signInConfig, userId);
247
247
  if (authURL) {
248
248
  return Promise.resolve(authURL.toString());
249
249
  } else {
@@ -259,8 +259,8 @@ var AsgardeoNodeCore = class _AsgardeoNodeCore {
259
259
  async requestAccessToken(authorizationCode, sessionState, userId, state) {
260
260
  return this._auth.requestAccessToken(authorizationCode, sessionState, state, userId);
261
261
  }
262
- async getIDToken(userId) {
263
- const is_logged_in = await this.isAuthenticated(userId);
262
+ async getIdToken(userId) {
263
+ const is_logged_in = await this.isSignedIn(userId);
264
264
  if (!is_logged_in) {
265
265
  return Promise.reject(
266
266
  new AsgardeoAuthException(
@@ -270,7 +270,7 @@ var AsgardeoNodeCore = class _AsgardeoNodeCore {
270
270
  )
271
271
  );
272
272
  }
273
- const idToken = await this._auth.getIDToken(userId);
273
+ const idToken = await this._auth.getIdToken(userId);
274
274
  if (idToken) {
275
275
  return Promise.resolve(idToken);
276
276
  } else {
@@ -286,27 +286,27 @@ var AsgardeoNodeCore = class _AsgardeoNodeCore {
286
286
  async refreshAccessToken(userId) {
287
287
  return this._auth.refreshAccessToken(userId);
288
288
  }
289
- async isAuthenticated(userId) {
289
+ async isSignedIn(userId) {
290
290
  try {
291
- if (!await this._auth.isAuthenticated(userId)) {
291
+ if (!await this._auth.isSignedIn(userId)) {
292
292
  return Promise.resolve(false);
293
293
  }
294
- if (await SessionUtils.validateSession(await this._dataLayer.getSessionData(userId))) {
294
+ if (await SessionUtils.validateSession(await this._storageManager.getSessionData(userId))) {
295
295
  return Promise.resolve(true);
296
296
  }
297
297
  const refreshed_token = await this.refreshAccessToken(userId);
298
298
  if (refreshed_token) {
299
299
  return Promise.resolve(true);
300
300
  }
301
- this._dataLayer.removeSessionData(userId);
302
- this._dataLayer.getTemporaryData(userId);
301
+ this._storageManager.removeSessionData(userId);
302
+ this._storageManager.getTemporaryData(userId);
303
303
  return Promise.resolve(false);
304
304
  } catch (error) {
305
305
  return Promise.reject(error);
306
306
  }
307
307
  }
308
308
  async signOut(userId) {
309
- const signOutURL = await this._auth.getSignOutURL(userId);
309
+ const signOutURL = await this._auth.getSignOutUrl(userId);
310
310
  if (!signOutURL) {
311
311
  return Promise.reject(
312
312
  new AsgardeoAuthException(
@@ -318,35 +318,38 @@ var AsgardeoNodeCore = class _AsgardeoNodeCore {
318
318
  }
319
319
  return Promise.resolve(signOutURL);
320
320
  }
321
- async getBasicUserInfo(userId) {
322
- return this._auth.getBasicUserInfo(userId);
321
+ async getUser(userId) {
322
+ return this._auth.getUser(userId);
323
+ }
324
+ async getConfigData() {
325
+ return this._storageManager.getConfigData();
323
326
  }
324
- async getOIDCServiceEndpoints() {
325
- return this._auth.getOIDCServiceEndpoints();
327
+ async getOpenIDProviderEndpoints() {
328
+ return this._auth.getOpenIDProviderEndpoints();
326
329
  }
327
- async getDecodedIDToken(userId) {
328
- return this._auth.getDecodedIDToken(userId);
330
+ async getDecodedIdToken(userId) {
331
+ return this._auth.getDecodedIdToken(userId);
329
332
  }
330
333
  async getAccessToken(userId) {
331
334
  return this._auth.getAccessToken(userId);
332
335
  }
333
- async requestCustomGrant(config, userId) {
334
- return this._auth.requestCustomGrant(config, userId);
336
+ async exchangeToken(config, userId) {
337
+ return this._auth.exchangeToken(config, userId);
335
338
  }
336
- async updateConfig(config) {
337
- return this._auth.updateConfig(config);
339
+ async reInitialize(config) {
340
+ return this._auth.reInitialize(config);
338
341
  }
339
342
  async revokeAccessToken(userId) {
340
343
  return this._auth.revokeAccessToken(userId);
341
344
  }
342
- static didSignOutFail(signOutRedirectURL) {
343
- return _AsgardeoNodeCore.didSignOutFail(signOutRedirectURL);
345
+ static didSignOutFail(afterSignOutUrl) {
346
+ return _AsgardeoNodeCore.didSignOutFail(afterSignOutUrl);
344
347
  }
345
- static isSignOutSuccessful(signOutRedirectURL) {
346
- return _AsgardeoNodeCore.isSignOutSuccessful(signOutRedirectURL);
348
+ static isSignOutSuccessful(afterSignOutUrl) {
349
+ return _AsgardeoNodeCore.isSignOutSuccessful(afterSignOutUrl);
347
350
  }
348
- getDataLayer() {
349
- return this._dataLayer;
351
+ getStorageManager() {
352
+ return this._storageManager;
350
353
  }
351
354
  };
352
355
 
@@ -356,15 +359,15 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
356
359
  * This is the constructor method that returns an instance of the `AsgardeoNodeClient` class.
357
360
  *
358
361
  * @param {AuthClientConfig<T>} config - The configuration object.
359
- * @param {Store} store - The store object.
362
+ * @param {Storage} store - The store object.
360
363
  *
361
364
  * @example
362
365
  * ```
363
- * const _store: Store = new DataStore();
366
+ * const _store: Storage = new DataStore();
364
367
  * const _config = {
365
- signInRedirectURL: "http://localhost:3000/sign-in",
366
- signOutRedirectURL: "http://localhost:3000/dashboard",
367
- clientID: "client ID",
368
+ afterSignInUrl: "http://localhost:3000/sign-in",
369
+ afterSignOutUrl: "http://localhost:3000/dashboard",
370
+ clientId: "client ID",
368
371
  serverOrigin: "https://api.asgardeo.io/t/<org_name>"
369
372
  };
370
373
  * const auth = new AsgardeoNodeClient(_config,_store);
@@ -385,7 +388,7 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
385
388
  * authorization URL to authorize the user.
386
389
  * @param {string} authorizationCode - The authorization code obtained from Asgardeo after a user signs in.
387
390
  * @param {String} sessionState - The session state obtained from Asgardeo after a user signs in.
388
- * @param {string} userID - (Optional) A unique ID of the user to be authenticated. This is useful in multi-user
391
+ * @param {string} userId - (Optional) A unique ID of the user to be authenticated. This is useful in multi-user
389
392
  * scenarios where each user should be uniquely identified.
390
393
  * @param {string} state - The state parameter in the redirect URL.
391
394
  *
@@ -415,6 +418,14 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
415
418
  async signIn(authURLCallback, userId, authorizationCode, sessionState, state, signInConfig) {
416
419
  return this._authCore.signIn(authURLCallback, userId, authorizationCode, sessionState, state, signInConfig);
417
420
  }
421
+ /**
422
+ * Method to get the configuration data.
423
+ *
424
+ * @returns {Promise<AuthClientConfig<Config>>} - A promise that resolves with the configuration data.
425
+ */
426
+ async getConfigData() {
427
+ return this._authCore.getConfigData();
428
+ }
418
429
  /**
419
430
  * This method clears all session data and returns the sign-out URL.
420
431
  * @param {string} userId - The userId of the user. (If you are using ExpressJS,
@@ -444,16 +455,16 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
444
455
  *
445
456
  * @example
446
457
  * ```
447
- * const isAuth = await authClient.isAuthenticated("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
458
+ * const isAuth = await authClient.isSignedIn("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
448
459
  * ```
449
460
  *
450
- * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#isAuthenticated
461
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#isSignedIn
451
462
  *
452
463
  * @memberof AsgardeoNodeClient
453
464
  *
454
465
  */
455
- async isAuthenticated(userId) {
456
- return this._authCore.isAuthenticated(userId);
466
+ async isSignedIn(userId) {
467
+ return this._authCore.isSignedIn(userId);
457
468
  }
458
469
  /**
459
470
  * This method returns the id token.
@@ -464,16 +475,16 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
464
475
  *
465
476
  * @example
466
477
  * ```
467
- * const isAuth = await authClient.getIDToken("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
478
+ * const isAuth = await authClient.getIdToken("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
468
479
  * ```
469
480
  *
470
- * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getIDToken
481
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getIdToken
471
482
  *
472
483
  * @memberof AsgardeoNodeClient
473
484
  *
474
485
  */
475
- async getIDToken(userId) {
476
- return this._authCore.getIDToken(userId);
486
+ async getIdToken(userId) {
487
+ return this._authCore.getIdToken(userId);
477
488
  }
478
489
  /**
479
490
  * This method returns an object containing basic user information obtained from the id token.
@@ -485,16 +496,16 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
485
496
  *
486
497
  * @example
487
498
  * ```
488
- * const basicInfo = await authClient.getBasicUserInfo("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
499
+ * const basicInfo = await authClient.getUser("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
489
500
  * ```
490
501
  *
491
- * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getBasicUserInfo
502
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getUser
492
503
  *
493
504
  * @memberof AsgardeoNodeClient
494
505
  *
495
506
  */
496
- async getBasicUserInfo(userId) {
497
- return this._authCore.getBasicUserInfo(userId);
507
+ async getUser(userId) {
508
+ return this._authCore.getUser(userId);
498
509
  }
499
510
  /**
500
511
  * This method returns an object containing the OIDC service endpoints returned by the `.well-known` endpoint.
@@ -503,37 +514,37 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
503
514
  *
504
515
  * @example
505
516
  * ```
506
- * const oidcEndpoints = await auth.getOIDCServiceEndpoints();
517
+ * const oidcEndpoints = await auth.getOpenIDProviderEndpoints();
507
518
  * ```
508
519
  *
509
- * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getOIDCServiceEndpoints
520
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getOpenIDProviderEndpoints
510
521
  *
511
522
  * @memberof AsgardeoNodeClient
512
523
  *
513
524
  */
514
- async getOIDCServiceEndpoints() {
515
- return this._authCore.getOIDCServiceEndpoints();
525
+ async getOpenIDProviderEndpoints() {
526
+ return this._authCore.getOpenIDProviderEndpoints();
516
527
  }
517
528
  /**
518
529
  * This method returns the decoded ID token payload.
519
530
  * @param {string} userId - The userId of the user.
520
531
  * (If you are using ExpressJS, you may get this from the request cookies)
521
532
  *
522
- * @return {Promise<IdTokenPayload>} -A Promise that resolves with
533
+ * @return {Promise<IdToken>} -A Promise that resolves with
523
534
  * an object containing the decoded ID token payload.
524
535
  *
525
536
  * @example
526
537
  * ```
527
- * const decodedIDTokenPayload = await auth.getDecodedIDToken("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
538
+ * const decodedIDTokenPayload = await auth.getDecodedIdToken("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
528
539
  * ```
529
540
  *
530
- * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getDecodedIDToken
541
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getDecodedIdToken
531
542
  *
532
543
  * @memberof AsgardeoNodeClient
533
544
  *
534
545
  */
535
- async getDecodedIDToken(userId) {
536
- return this._authCore.getDecodedIDToken(userId);
546
+ async getDecodedIdToken(userId) {
547
+ return this._authCore.getDecodedIdToken(userId);
537
548
  }
538
549
  /**
539
550
  * This method returns the access token.
@@ -557,15 +568,15 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
557
568
  return this._authCore.getAccessToken(userId);
558
569
  }
559
570
  /**
560
- * This method returns Promise that resolves with the token information
571
+ * This method returns Promise that resolves with the token information
561
572
  * or the response returned by the server depending on the configuration passed.
562
- * @param {CustomGrantConfig} config - The config object contains attributes that would be used
573
+ * @param {TokenExchangeRequestConfig} config - The config object contains attributes that would be used
563
574
  * to configure the custom grant request.
564
575
  *
565
576
  * @param {string} userId - The userId of the user.
566
577
  * (If you are using ExpressJS, you may get this from the request cookies)
567
- *
568
- * @return {Promise<TokenResponse | FetchResponse>} -A Promise that resolves with the token information
578
+ *
579
+ * @return {Promise<TokenResponse | Response>} -A Promise that resolves with the token information
569
580
  * or the response returned by the server depending on the configuration passed.
570
581
  *
571
582
  * @example
@@ -573,7 +584,7 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
573
584
  * const config = {
574
585
  * attachToken: false,
575
586
  * data: {
576
- * client_id: "{{clientID}}",
587
+ * client_id: "{{clientId}}",
577
588
  * grant_type: "account_switch",
578
589
  * scope: "{{scope}}",
579
590
  * token: "{{token}}",
@@ -584,20 +595,20 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
584
595
  * signInRequired: true
585
596
  * }
586
597
 
587
- * auth.requestCustomGrant(config).then((response)=>{
598
+ * auth.exchangeToken(config).then((response)=>{
588
599
  * console.log(response);
589
600
  * }).catch((error)=>{
590
601
  * console.error(error);
591
602
  * });
592
603
  * ```
593
604
  *
594
- * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#requestCustomGrant
605
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#exchangeToken
595
606
  *
596
607
  * @memberof AsgardeoNodeClient
597
608
  *
598
609
  */
599
- async requestCustomGrant(config, userId) {
600
- return this._authCore.requestCustomGrant(config, userId);
610
+ async exchangeToken(config, userId) {
611
+ return this._authCore.exchangeToken(config, userId);
601
612
  }
602
613
  /**
603
614
  * This method can be used to update the configurations passed into the constructor of the AsgardeoAuthClient.
@@ -608,25 +619,28 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
608
619
  *
609
620
  * @example
610
621
  * ```
611
- * const updateConfig = await auth.updateConfig({
612
- * signOutRedirectURL: "http://localhost:3000/sign-out"
622
+ * const reInitialize = await auth.reInitialize({
623
+ * afterSignOutUrl: "http://localhost:3000/sign-out"
613
624
  * });
614
625
  * ```
615
626
  *
616
- * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#updateConfig
627
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#reInitialize
617
628
  *
618
629
  * @memberof AsgardeoNodeClient
619
630
  *
620
631
  */
621
- async updateConfig(config) {
622
- return this._authCore.updateConfig(config);
632
+ async reInitialize(config) {
633
+ return this._authCore.reInitialize(config);
634
+ }
635
+ async getSignInUrl(requestConfig, userId) {
636
+ return this._authCore.getAuthURL(userId, requestConfig);
623
637
  }
624
638
  /**
625
639
  * This method returns a Promise that resolves with the response returned by the server.
626
640
  * @param {string} userId - The userId of the user.
627
641
  * (If you are using ExpressJS, you may get this from the request cookies)
628
642
  *
629
- * @return {Promise<FetchResponse>} -A Promise that resolves with the response returned by the server.
643
+ * @return {Promise<Response>} -A Promise that resolves with the response returned by the server.
630
644
  *
631
645
  * @example
632
646
  * ```
@@ -664,7 +678,7 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
664
678
  }
665
679
  /**
666
680
  * This method returns if the user has been successfully signed out or not.
667
- * @param {string} signOutRedirectURL - The URL to which the user is redirected to
681
+ * @param {string} afterSignOutUrl - The URL to which the user is redirected to
668
682
  * after signing out from the server.
669
683
  *
670
684
  * @return {boolean} - A boolean value indicating if the user has been signed out or not.
@@ -679,12 +693,12 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
679
693
  * @memberof AsgardeoNodeClient
680
694
  *
681
695
  */
682
- static isSignOutSuccessful(signOutRedirectURL) {
683
- return _AsgardeoNodeClient.isSignOutSuccessful(signOutRedirectURL);
696
+ static isSignOutSuccessful(afterSignOutUrl) {
697
+ return _AsgardeoNodeClient.isSignOutSuccessful(afterSignOutUrl);
684
698
  }
685
699
  /**
686
700
  * This method returns if sign-out failed or not
687
- * @param {string} signOutRedirectURL - The URL to which the user is redirected to
701
+ * @param {string} afterSignOutUrl - The URL to which the user is redirected to
688
702
  * after signing out from the server.
689
703
  *
690
704
  * @return {boolean} - A boolean value indicating if sign-out failed or not.
@@ -699,11 +713,11 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
699
713
  * @memberof AsgardeoNodeClient
700
714
  *
701
715
  */
702
- static didSignOutFail(signOutRedirectURL) {
703
- return _AsgardeoNodeClient.didSignOutFail(signOutRedirectURL);
716
+ static didSignOutFail(afterSignOutUrl) {
717
+ return _AsgardeoNodeClient.didSignOutFail(afterSignOutUrl);
704
718
  }
705
- async getDataLayer() {
706
- return this._authCore.getDataLayer();
719
+ async getStorageManager() {
720
+ return this._authCore.getStorageManager();
707
721
  }
708
722
  };
709
723