@asgardeo/node 0.0.1 → 0.0.2

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,35 @@ 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
323
  }
324
- async getOIDCServiceEndpoints() {
325
- return this._auth.getOIDCServiceEndpoints();
324
+ async getOpenIDProviderEndpoints() {
325
+ return this._auth.getOpenIDProviderEndpoints();
326
326
  }
327
- async getDecodedIDToken(userId) {
328
- return this._auth.getDecodedIDToken(userId);
327
+ async getDecodedIdToken(userId) {
328
+ return this._auth.getDecodedIdToken(userId);
329
329
  }
330
330
  async getAccessToken(userId) {
331
331
  return this._auth.getAccessToken(userId);
332
332
  }
333
- async requestCustomGrant(config, userId) {
334
- return this._auth.requestCustomGrant(config, userId);
333
+ async exchangeToken(config, userId) {
334
+ return this._auth.exchangeToken(config, userId);
335
335
  }
336
- async updateConfig(config) {
337
- return this._auth.updateConfig(config);
336
+ async reInitialize(config) {
337
+ return this._auth.reInitialize(config);
338
338
  }
339
339
  async revokeAccessToken(userId) {
340
340
  return this._auth.revokeAccessToken(userId);
341
341
  }
342
- static didSignOutFail(signOutRedirectURL) {
343
- return _AsgardeoNodeCore.didSignOutFail(signOutRedirectURL);
342
+ static didSignOutFail(afterSignOutUrl) {
343
+ return _AsgardeoNodeCore.didSignOutFail(afterSignOutUrl);
344
344
  }
345
- static isSignOutSuccessful(signOutRedirectURL) {
346
- return _AsgardeoNodeCore.isSignOutSuccessful(signOutRedirectURL);
345
+ static isSignOutSuccessful(afterSignOutUrl) {
346
+ return _AsgardeoNodeCore.isSignOutSuccessful(afterSignOutUrl);
347
347
  }
348
- getDataLayer() {
349
- return this._dataLayer;
348
+ getStorageManager() {
349
+ return this._storageManager;
350
350
  }
351
351
  };
352
352
 
@@ -356,15 +356,15 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
356
356
  * This is the constructor method that returns an instance of the `AsgardeoNodeClient` class.
357
357
  *
358
358
  * @param {AuthClientConfig<T>} config - The configuration object.
359
- * @param {Store} store - The store object.
359
+ * @param {Storage} store - The store object.
360
360
  *
361
361
  * @example
362
362
  * ```
363
- * const _store: Store = new DataStore();
363
+ * const _store: Storage = new DataStore();
364
364
  * const _config = {
365
- signInRedirectURL: "http://localhost:3000/sign-in",
366
- signOutRedirectURL: "http://localhost:3000/dashboard",
367
- clientID: "client ID",
365
+ afterSignInUrl: "http://localhost:3000/sign-in",
366
+ afterSignOutUrl: "http://localhost:3000/dashboard",
367
+ clientId: "client ID",
368
368
  serverOrigin: "https://api.asgardeo.io/t/<org_name>"
369
369
  };
370
370
  * const auth = new AsgardeoNodeClient(_config,_store);
@@ -385,7 +385,7 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
385
385
  * authorization URL to authorize the user.
386
386
  * @param {string} authorizationCode - The authorization code obtained from Asgardeo after a user signs in.
387
387
  * @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
388
+ * @param {string} userId - (Optional) A unique ID of the user to be authenticated. This is useful in multi-user
389
389
  * scenarios where each user should be uniquely identified.
390
390
  * @param {string} state - The state parameter in the redirect URL.
391
391
  *
@@ -444,16 +444,16 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
444
444
  *
445
445
  * @example
446
446
  * ```
447
- * const isAuth = await authClient.isAuthenticated("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
447
+ * const isAuth = await authClient.isSignedIn("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
448
448
  * ```
449
449
  *
450
- * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#isAuthenticated
450
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#isSignedIn
451
451
  *
452
452
  * @memberof AsgardeoNodeClient
453
453
  *
454
454
  */
455
- async isAuthenticated(userId) {
456
- return this._authCore.isAuthenticated(userId);
455
+ async isSignedIn(userId) {
456
+ return this._authCore.isSignedIn(userId);
457
457
  }
458
458
  /**
459
459
  * This method returns the id token.
@@ -464,16 +464,16 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
464
464
  *
465
465
  * @example
466
466
  * ```
467
- * const isAuth = await authClient.getIDToken("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
467
+ * const isAuth = await authClient.getIdToken("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
468
468
  * ```
469
469
  *
470
- * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getIDToken
470
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getIdToken
471
471
  *
472
472
  * @memberof AsgardeoNodeClient
473
473
  *
474
474
  */
475
- async getIDToken(userId) {
476
- return this._authCore.getIDToken(userId);
475
+ async getIdToken(userId) {
476
+ return this._authCore.getIdToken(userId);
477
477
  }
478
478
  /**
479
479
  * This method returns an object containing basic user information obtained from the id token.
@@ -485,16 +485,16 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
485
485
  *
486
486
  * @example
487
487
  * ```
488
- * const basicInfo = await authClient.getBasicUserInfo("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
488
+ * const basicInfo = await authClient.getUser("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
489
489
  * ```
490
490
  *
491
- * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getBasicUserInfo
491
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getUser
492
492
  *
493
493
  * @memberof AsgardeoNodeClient
494
494
  *
495
495
  */
496
- async getBasicUserInfo(userId) {
497
- return this._authCore.getBasicUserInfo(userId);
496
+ async getUser(userId) {
497
+ return this._authCore.getUser(userId);
498
498
  }
499
499
  /**
500
500
  * This method returns an object containing the OIDC service endpoints returned by the `.well-known` endpoint.
@@ -503,16 +503,16 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
503
503
  *
504
504
  * @example
505
505
  * ```
506
- * const oidcEndpoints = await auth.getOIDCServiceEndpoints();
506
+ * const oidcEndpoints = await auth.getOpenIDProviderEndpoints();
507
507
  * ```
508
508
  *
509
- * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getOIDCServiceEndpoints
509
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getOpenIDProviderEndpoints
510
510
  *
511
511
  * @memberof AsgardeoNodeClient
512
512
  *
513
513
  */
514
- async getOIDCServiceEndpoints() {
515
- return this._authCore.getOIDCServiceEndpoints();
514
+ async getOpenIDProviderEndpoints() {
515
+ return this._authCore.getOpenIDProviderEndpoints();
516
516
  }
517
517
  /**
518
518
  * This method returns the decoded ID token payload.
@@ -524,16 +524,16 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
524
524
  *
525
525
  * @example
526
526
  * ```
527
- * const decodedIDTokenPayload = await auth.getDecodedIDToken("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
527
+ * const decodedIDTokenPayload = await auth.getDecodedIdToken("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
528
528
  * ```
529
529
  *
530
- * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getDecodedIDToken
530
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getDecodedIdToken
531
531
  *
532
532
  * @memberof AsgardeoNodeClient
533
533
  *
534
534
  */
535
- async getDecodedIDToken(userId) {
536
- return this._authCore.getDecodedIDToken(userId);
535
+ async getDecodedIdToken(userId) {
536
+ return this._authCore.getDecodedIdToken(userId);
537
537
  }
538
538
  /**
539
539
  * This method returns the access token.
@@ -557,15 +557,15 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
557
557
  return this._authCore.getAccessToken(userId);
558
558
  }
559
559
  /**
560
- * This method returns Promise that resolves with the token information
560
+ * This method returns Promise that resolves with the token information
561
561
  * 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
562
+ * @param {TokenExchangeRequestConfig} config - The config object contains attributes that would be used
563
563
  * to configure the custom grant request.
564
564
  *
565
565
  * @param {string} userId - The userId of the user.
566
566
  * (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
567
+ *
568
+ * @return {Promise<TokenResponse | Response>} -A Promise that resolves with the token information
569
569
  * or the response returned by the server depending on the configuration passed.
570
570
  *
571
571
  * @example
@@ -573,7 +573,7 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
573
573
  * const config = {
574
574
  * attachToken: false,
575
575
  * data: {
576
- * client_id: "{{clientID}}",
576
+ * client_id: "{{clientId}}",
577
577
  * grant_type: "account_switch",
578
578
  * scope: "{{scope}}",
579
579
  * token: "{{token}}",
@@ -584,20 +584,20 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
584
584
  * signInRequired: true
585
585
  * }
586
586
 
587
- * auth.requestCustomGrant(config).then((response)=>{
587
+ * auth.exchangeToken(config).then((response)=>{
588
588
  * console.log(response);
589
589
  * }).catch((error)=>{
590
590
  * console.error(error);
591
591
  * });
592
592
  * ```
593
593
  *
594
- * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#requestCustomGrant
594
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#exchangeToken
595
595
  *
596
596
  * @memberof AsgardeoNodeClient
597
597
  *
598
598
  */
599
- async requestCustomGrant(config, userId) {
600
- return this._authCore.requestCustomGrant(config, userId);
599
+ async exchangeToken(config, userId) {
600
+ return this._authCore.exchangeToken(config, userId);
601
601
  }
602
602
  /**
603
603
  * This method can be used to update the configurations passed into the constructor of the AsgardeoAuthClient.
@@ -608,25 +608,25 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
608
608
  *
609
609
  * @example
610
610
  * ```
611
- * const updateConfig = await auth.updateConfig({
612
- * signOutRedirectURL: "http://localhost:3000/sign-out"
611
+ * const reInitialize = await auth.reInitialize({
612
+ * afterSignOutUrl: "http://localhost:3000/sign-out"
613
613
  * });
614
614
  * ```
615
615
  *
616
- * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#updateConfig
616
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#reInitialize
617
617
  *
618
618
  * @memberof AsgardeoNodeClient
619
619
  *
620
620
  */
621
- async updateConfig(config) {
622
- return this._authCore.updateConfig(config);
621
+ async reInitialize(config) {
622
+ return this._authCore.reInitialize(config);
623
623
  }
624
624
  /**
625
625
  * This method returns a Promise that resolves with the response returned by the server.
626
626
  * @param {string} userId - The userId of the user.
627
627
  * (If you are using ExpressJS, you may get this from the request cookies)
628
628
  *
629
- * @return {Promise<FetchResponse>} -A Promise that resolves with the response returned by the server.
629
+ * @return {Promise<Response>} -A Promise that resolves with the response returned by the server.
630
630
  *
631
631
  * @example
632
632
  * ```
@@ -664,7 +664,7 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
664
664
  }
665
665
  /**
666
666
  * 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
667
+ * @param {string} afterSignOutUrl - The URL to which the user is redirected to
668
668
  * after signing out from the server.
669
669
  *
670
670
  * @return {boolean} - A boolean value indicating if the user has been signed out or not.
@@ -679,12 +679,12 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
679
679
  * @memberof AsgardeoNodeClient
680
680
  *
681
681
  */
682
- static isSignOutSuccessful(signOutRedirectURL) {
683
- return _AsgardeoNodeClient.isSignOutSuccessful(signOutRedirectURL);
682
+ static isSignOutSuccessful(afterSignOutUrl) {
683
+ return _AsgardeoNodeClient.isSignOutSuccessful(afterSignOutUrl);
684
684
  }
685
685
  /**
686
686
  * This method returns if sign-out failed or not
687
- * @param {string} signOutRedirectURL - The URL to which the user is redirected to
687
+ * @param {string} afterSignOutUrl - The URL to which the user is redirected to
688
688
  * after signing out from the server.
689
689
  *
690
690
  * @return {boolean} - A boolean value indicating if sign-out failed or not.
@@ -699,11 +699,11 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
699
699
  * @memberof AsgardeoNodeClient
700
700
  *
701
701
  */
702
- static didSignOutFail(signOutRedirectURL) {
703
- return _AsgardeoNodeClient.didSignOutFail(signOutRedirectURL);
702
+ static didSignOutFail(afterSignOutUrl) {
703
+ return _AsgardeoNodeClient.didSignOutFail(afterSignOutUrl);
704
704
  }
705
- async getDataLayer() {
706
- return this._authCore.getDataLayer();
705
+ async getStorageManager() {
706
+ return this._authCore.getStorageManager();
707
707
  }
708
708
  };
709
709