@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/__legacy__/client.d.ts +2 -2
- package/dist/__legacy__/constants/index.d.ts +18 -18
- package/dist/__legacy__/constants/logger-config.d.ts +6 -4
- package/dist/__legacy__/constants/uuid-config.d.ts +3 -3
- package/dist/__legacy__/core/authentication.d.ts +6 -6
- package/dist/__legacy__/core/index.d.ts +3 -3
- package/dist/__legacy__/models/index.d.ts +4 -4
- package/dist/__legacy__/models/session-data.d.ts +2 -2
- package/dist/__legacy__/models/url-callback.d.ts +16 -16
- package/dist/__legacy__/stores/index.d.ts +17 -17
- package/dist/__legacy__/stores/memory-cache-store.d.ts +2 -2
- package/dist/__legacy__/utils/crypto-utils.d.ts +2 -2
- package/dist/__legacy__/utils/index.d.ts +18 -18
- package/dist/__legacy__/utils/logger-utils.d.ts +16 -16
- package/dist/__legacy__/utils/session-utils.d.ts +17 -17
- package/dist/cjs/index.js +82 -79
- package/dist/cjs/index.js.map +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +82 -79
- package/dist/index.js.map +2 -2
- package/package.json +3 -3
package/dist/cjs/index.js
CHANGED
|
@@ -48,12 +48,15 @@ var import_javascript = require("@asgardeo/javascript");
|
|
|
48
48
|
// src/__legacy__/stores/memory-cache-store.ts
|
|
49
49
|
var import_memory_cache = __toESM(require("memory-cache"), 1);
|
|
50
50
|
var MemoryCacheStore = class {
|
|
51
|
+
// eslint-disable-next-line class-methods-use-this
|
|
51
52
|
async setData(key, value) {
|
|
52
53
|
import_memory_cache.default.put(key, value);
|
|
53
54
|
}
|
|
55
|
+
// eslint-disable-next-line class-methods-use-this
|
|
54
56
|
async getData(key) {
|
|
55
57
|
return import_memory_cache.default.get(key) ?? "{}";
|
|
56
58
|
}
|
|
59
|
+
// eslint-disable-next-line class-methods-use-this
|
|
57
60
|
async removeData(key) {
|
|
58
61
|
import_memory_cache.default.del(key);
|
|
59
62
|
}
|
|
@@ -85,25 +88,23 @@ var SessionUtils = class {
|
|
|
85
88
|
constructor() {
|
|
86
89
|
}
|
|
87
90
|
static createUUID() {
|
|
88
|
-
const
|
|
89
|
-
return
|
|
91
|
+
const generatedUuid = (0, import_uuid.v4)();
|
|
92
|
+
return generatedUuid;
|
|
90
93
|
}
|
|
91
94
|
static validateUUID(uuid) {
|
|
92
95
|
if ((0, import_uuid.validate)(uuid) && (0, import_uuid.version)(uuid) === UUID_VERSION) {
|
|
93
96
|
return Promise.resolve(true);
|
|
94
|
-
} else {
|
|
95
|
-
return Promise.resolve(false);
|
|
96
97
|
}
|
|
98
|
+
return Promise.resolve(false);
|
|
97
99
|
}
|
|
98
100
|
static validateSession(sessionData) {
|
|
99
101
|
const currentTime = Date.now();
|
|
100
|
-
const expiryTimeStamp = sessionData.created_at + parseInt(sessionData.expires_in) * 60 * 1e3;
|
|
102
|
+
const expiryTimeStamp = sessionData.created_at + parseInt(sessionData.expires_in, 10) * 60 * 1e3;
|
|
101
103
|
if (currentTime < expiryTimeStamp) {
|
|
102
104
|
return Promise.resolve(true);
|
|
103
|
-
} else {
|
|
104
|
-
Logger.warn("Expired Session");
|
|
105
|
-
return Promise.resolve(false);
|
|
106
105
|
}
|
|
106
|
+
Logger.warn("Expired Session");
|
|
107
|
+
return Promise.resolve(false);
|
|
107
108
|
}
|
|
108
109
|
};
|
|
109
110
|
|
|
@@ -185,18 +186,23 @@ var NodeCryptoUtils = class {
|
|
|
185
186
|
*
|
|
186
187
|
* @returns {string} base 64 url encoded value.
|
|
187
188
|
*/
|
|
189
|
+
// eslint-disable-next-line class-methods-use-this
|
|
188
190
|
base64URLEncode(value) {
|
|
189
191
|
return import_base64url.default.encode(value).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
190
192
|
}
|
|
193
|
+
// eslint-disable-next-line class-methods-use-this
|
|
191
194
|
base64URLDecode(value) {
|
|
192
195
|
return import_base64url.default.decode(value).toString();
|
|
193
196
|
}
|
|
197
|
+
// eslint-disable-next-line class-methods-use-this
|
|
194
198
|
hashSha256(data) {
|
|
195
199
|
return Buffer.from((0, import_fast_sha256.default)(new TextEncoder().encode(data)));
|
|
196
200
|
}
|
|
201
|
+
// eslint-disable-next-line class-methods-use-this
|
|
197
202
|
generateRandomBytes(length) {
|
|
198
203
|
return (0, import_secure_random_bytes.default)(length);
|
|
199
204
|
}
|
|
205
|
+
// eslint-disable-next-line class-methods-use-this
|
|
200
206
|
async verifyJwt(idToken, jwk, algorithms, clientId, issuer, subject, clockTolerance) {
|
|
201
207
|
const key = await jose.importJWK(jwk);
|
|
202
208
|
return jose.jwtVerify(idToken, key, {
|
|
@@ -205,28 +211,26 @@ var NodeCryptoUtils = class {
|
|
|
205
211
|
clockTolerance,
|
|
206
212
|
issuer,
|
|
207
213
|
subject
|
|
208
|
-
}).then(() =>
|
|
209
|
-
return Promise.resolve(true);
|
|
210
|
-
});
|
|
214
|
+
}).then(() => Promise.resolve(true));
|
|
211
215
|
}
|
|
212
216
|
};
|
|
213
217
|
|
|
214
218
|
// src/__legacy__/core/authentication.ts
|
|
215
219
|
var AsgardeoNodeCore = class _AsgardeoNodeCore {
|
|
216
220
|
constructor(config, store) {
|
|
217
|
-
__publicField(this, "
|
|
218
|
-
__publicField(this, "
|
|
219
|
-
__publicField(this, "
|
|
220
|
-
__publicField(this, "
|
|
221
|
+
__publicField(this, "auth");
|
|
222
|
+
__publicField(this, "cryptoUtils");
|
|
223
|
+
__publicField(this, "store");
|
|
224
|
+
__publicField(this, "storageManager");
|
|
221
225
|
if (!store) {
|
|
222
|
-
this.
|
|
226
|
+
this.store = new MemoryCacheStore();
|
|
223
227
|
} else {
|
|
224
|
-
this.
|
|
228
|
+
this.store = store;
|
|
225
229
|
}
|
|
226
|
-
this.
|
|
227
|
-
this.
|
|
228
|
-
this.
|
|
229
|
-
this.
|
|
230
|
+
this.cryptoUtils = new NodeCryptoUtils();
|
|
231
|
+
this.auth = new import_javascript.AsgardeoAuthClient();
|
|
232
|
+
this.auth.initialize(config, this.store, this.cryptoUtils);
|
|
233
|
+
this.storageManager = this.auth.getStorageManager();
|
|
230
234
|
Logger.debug("Initialized AsgardeoAuthClient successfully");
|
|
231
235
|
}
|
|
232
236
|
async signIn(authURLCallback, userId, authorizationCode, sessionState, state, signInConfig) {
|
|
@@ -240,7 +244,7 @@ var AsgardeoNodeCore = class _AsgardeoNodeCore {
|
|
|
240
244
|
);
|
|
241
245
|
}
|
|
242
246
|
if (await this.isSignedIn(userId)) {
|
|
243
|
-
const sessionData = await this.
|
|
247
|
+
const sessionData = await this.storageManager.getSessionData(userId);
|
|
244
248
|
return Promise.resolve({
|
|
245
249
|
accessToken: sessionData.access_token,
|
|
246
250
|
createdAt: sessionData.created_at,
|
|
@@ -277,25 +281,24 @@ var AsgardeoNodeCore = class _AsgardeoNodeCore {
|
|
|
277
281
|
return this.requestAccessToken(authorizationCode, sessionState ?? "", userId, state);
|
|
278
282
|
}
|
|
279
283
|
async getAuthURL(userId, signInConfig) {
|
|
280
|
-
const authURL = await this.
|
|
284
|
+
const authURL = await this.auth.getSignInUrl(signInConfig, userId);
|
|
281
285
|
if (authURL) {
|
|
282
286
|
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
287
|
}
|
|
288
|
+
return Promise.reject(
|
|
289
|
+
new import_javascript.AsgardeoAuthException(
|
|
290
|
+
"NODE-AUTH_CORE-GAU-NF01",
|
|
291
|
+
"Getting Authorization URL failed.",
|
|
292
|
+
"No authorization URL was returned by the Asgardeo Auth JS SDK."
|
|
293
|
+
)
|
|
294
|
+
);
|
|
292
295
|
}
|
|
293
296
|
async requestAccessToken(authorizationCode, sessionState, userId, state) {
|
|
294
|
-
return this.
|
|
297
|
+
return this.auth.requestAccessToken(authorizationCode, sessionState, state, userId);
|
|
295
298
|
}
|
|
296
299
|
async getIdToken(userId) {
|
|
297
|
-
const
|
|
298
|
-
if (!
|
|
300
|
+
const isLoggedIn = await this.isSignedIn(userId);
|
|
301
|
+
if (!isLoggedIn) {
|
|
299
302
|
return Promise.reject(
|
|
300
303
|
new import_javascript.AsgardeoAuthException(
|
|
301
304
|
"NODE-AUTH_CORE-GIT-NF01",
|
|
@@ -304,43 +307,42 @@ var AsgardeoNodeCore = class _AsgardeoNodeCore {
|
|
|
304
307
|
)
|
|
305
308
|
);
|
|
306
309
|
}
|
|
307
|
-
const idToken = await this.
|
|
310
|
+
const idToken = await this.auth.getIdToken(userId);
|
|
308
311
|
if (idToken) {
|
|
309
312
|
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
313
|
}
|
|
314
|
+
return Promise.reject(
|
|
315
|
+
new import_javascript.AsgardeoAuthException(
|
|
316
|
+
"NODE-AUTH_CORE-GIT-NF02",
|
|
317
|
+
"Requesting ID Token Failed",
|
|
318
|
+
"No ID Token was returned by the Asgardeo Auth JS SDK."
|
|
319
|
+
)
|
|
320
|
+
);
|
|
319
321
|
}
|
|
320
322
|
async refreshAccessToken(userId) {
|
|
321
|
-
return this.
|
|
323
|
+
return this.auth.refreshAccessToken(userId);
|
|
322
324
|
}
|
|
323
325
|
async isSignedIn(userId) {
|
|
324
326
|
try {
|
|
325
|
-
if (!await this.
|
|
327
|
+
if (!await this.auth.isSignedIn(userId)) {
|
|
326
328
|
return Promise.resolve(false);
|
|
327
329
|
}
|
|
328
|
-
if (await SessionUtils.validateSession(await this.
|
|
330
|
+
if (await SessionUtils.validateSession(await this.storageManager.getSessionData(userId))) {
|
|
329
331
|
return Promise.resolve(true);
|
|
330
332
|
}
|
|
331
|
-
const
|
|
332
|
-
if (
|
|
333
|
+
const refreshedToken = await this.refreshAccessToken(userId);
|
|
334
|
+
if (refreshedToken) {
|
|
333
335
|
return Promise.resolve(true);
|
|
334
336
|
}
|
|
335
|
-
this.
|
|
336
|
-
this.
|
|
337
|
+
this.storageManager.removeSessionData(userId);
|
|
338
|
+
this.storageManager.getTemporaryData(userId);
|
|
337
339
|
return Promise.resolve(false);
|
|
338
340
|
} catch (error) {
|
|
339
341
|
return Promise.reject(error);
|
|
340
342
|
}
|
|
341
343
|
}
|
|
342
344
|
async signOut(userId) {
|
|
343
|
-
const signOutURL = await this.
|
|
345
|
+
const signOutURL = await this.auth.getSignOutUrl(userId);
|
|
344
346
|
if (!signOutURL) {
|
|
345
347
|
return Promise.reject(
|
|
346
348
|
new import_javascript.AsgardeoAuthException(
|
|
@@ -353,28 +355,28 @@ var AsgardeoNodeCore = class _AsgardeoNodeCore {
|
|
|
353
355
|
return Promise.resolve(signOutURL);
|
|
354
356
|
}
|
|
355
357
|
async getUser(userId) {
|
|
356
|
-
return this.
|
|
358
|
+
return this.auth.getUser(userId);
|
|
357
359
|
}
|
|
358
360
|
async getConfigData() {
|
|
359
|
-
return this.
|
|
361
|
+
return this.storageManager.getConfigData();
|
|
360
362
|
}
|
|
361
363
|
async getOpenIDProviderEndpoints() {
|
|
362
|
-
return this.
|
|
364
|
+
return this.auth.getOpenIDProviderEndpoints();
|
|
363
365
|
}
|
|
364
366
|
async getDecodedIdToken(userId, idToken) {
|
|
365
|
-
return this.
|
|
367
|
+
return this.auth.getDecodedIdToken(userId, idToken);
|
|
366
368
|
}
|
|
367
369
|
async getAccessToken(userId) {
|
|
368
|
-
return this.
|
|
370
|
+
return this.auth.getAccessToken(userId);
|
|
369
371
|
}
|
|
370
372
|
async exchangeToken(config, userId) {
|
|
371
|
-
return this.
|
|
373
|
+
return this.auth.exchangeToken(config, userId);
|
|
372
374
|
}
|
|
373
375
|
async reInitialize(config) {
|
|
374
|
-
return this.
|
|
376
|
+
return this.auth.reInitialize(config);
|
|
375
377
|
}
|
|
376
378
|
async revokeAccessToken(userId) {
|
|
377
|
-
return this.
|
|
379
|
+
return this.auth.revokeAccessToken(userId);
|
|
378
380
|
}
|
|
379
381
|
static didSignOutFail(afterSignOutUrl) {
|
|
380
382
|
return _AsgardeoNodeCore.didSignOutFail(afterSignOutUrl);
|
|
@@ -383,10 +385,10 @@ var AsgardeoNodeCore = class _AsgardeoNodeCore {
|
|
|
383
385
|
return _AsgardeoNodeCore.isSignOutSuccessful(afterSignOutUrl);
|
|
384
386
|
}
|
|
385
387
|
getStorageManager() {
|
|
386
|
-
return this.
|
|
388
|
+
return this.storageManager;
|
|
387
389
|
}
|
|
388
390
|
async decodeJwtToken(token) {
|
|
389
|
-
return this.
|
|
391
|
+
return this.auth.decodeJwtToken(token);
|
|
390
392
|
}
|
|
391
393
|
};
|
|
392
394
|
|
|
@@ -413,11 +415,12 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
|
|
|
413
415
|
* @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#constructor
|
|
414
416
|
* @preserve
|
|
415
417
|
*/
|
|
418
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
416
419
|
constructor() {
|
|
417
|
-
__publicField(this, "
|
|
420
|
+
__publicField(this, "authCore");
|
|
418
421
|
}
|
|
419
422
|
async initialize(config, store) {
|
|
420
|
-
this.
|
|
423
|
+
this.authCore = new AsgardeoNodeCore(config, store);
|
|
421
424
|
return Promise.resolve(true);
|
|
422
425
|
}
|
|
423
426
|
/**
|
|
@@ -453,7 +456,7 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
|
|
|
453
456
|
*
|
|
454
457
|
*/
|
|
455
458
|
async signIn(authURLCallback, userId, authorizationCode, sessionState, state, signInConfig) {
|
|
456
|
-
return this.
|
|
459
|
+
return this.authCore.signIn(authURLCallback, userId, authorizationCode, sessionState, state, signInConfig);
|
|
457
460
|
}
|
|
458
461
|
/**
|
|
459
462
|
* Method to get the configuration data.
|
|
@@ -461,7 +464,7 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
|
|
|
461
464
|
* @returns {Promise<AuthClientConfig<Config>>} - A promise that resolves with the configuration data.
|
|
462
465
|
*/
|
|
463
466
|
async getConfigData() {
|
|
464
|
-
return this.
|
|
467
|
+
return this.authCore.getConfigData();
|
|
465
468
|
}
|
|
466
469
|
/**
|
|
467
470
|
* This method clears all session data and returns the sign-out URL.
|
|
@@ -481,7 +484,7 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
|
|
|
481
484
|
*
|
|
482
485
|
*/
|
|
483
486
|
async signOut(userId) {
|
|
484
|
-
return this.
|
|
487
|
+
return this.authCore.signOut(userId);
|
|
485
488
|
}
|
|
486
489
|
/**
|
|
487
490
|
* This method returns a boolean value indicating if the user is authenticated or not.
|
|
@@ -501,7 +504,7 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
|
|
|
501
504
|
*
|
|
502
505
|
*/
|
|
503
506
|
async isSignedIn(userId) {
|
|
504
|
-
return this.
|
|
507
|
+
return this.authCore.isSignedIn(userId);
|
|
505
508
|
}
|
|
506
509
|
/**
|
|
507
510
|
* This method returns the id token.
|
|
@@ -521,7 +524,7 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
|
|
|
521
524
|
*
|
|
522
525
|
*/
|
|
523
526
|
async getIdToken(userId) {
|
|
524
|
-
return this.
|
|
527
|
+
return this.authCore.getIdToken(userId);
|
|
525
528
|
}
|
|
526
529
|
/**
|
|
527
530
|
* This method returns an object containing basic user information obtained from the id token.
|
|
@@ -542,7 +545,7 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
|
|
|
542
545
|
*
|
|
543
546
|
*/
|
|
544
547
|
async getUser(userId) {
|
|
545
|
-
return this.
|
|
548
|
+
return this.authCore.getUser(userId);
|
|
546
549
|
}
|
|
547
550
|
/**
|
|
548
551
|
* This method returns an object containing the OIDC service endpoints returned by the `.well-known` endpoint.
|
|
@@ -560,7 +563,7 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
|
|
|
560
563
|
*
|
|
561
564
|
*/
|
|
562
565
|
async getOpenIDProviderEndpoints() {
|
|
563
|
-
return this.
|
|
566
|
+
return this.authCore.getOpenIDProviderEndpoints();
|
|
564
567
|
}
|
|
565
568
|
/**
|
|
566
569
|
* This method returns the decoded ID token payload.
|
|
@@ -581,7 +584,7 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
|
|
|
581
584
|
*
|
|
582
585
|
*/
|
|
583
586
|
async getDecodedIdToken(userId, idToken) {
|
|
584
|
-
return this.
|
|
587
|
+
return this.authCore.getDecodedIdToken(userId, idToken);
|
|
585
588
|
}
|
|
586
589
|
/**
|
|
587
590
|
* This method returns the access token.
|
|
@@ -602,7 +605,7 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
|
|
|
602
605
|
*
|
|
603
606
|
*/
|
|
604
607
|
async getAccessToken(userId) {
|
|
605
|
-
return this.
|
|
608
|
+
return this.authCore.getAccessToken(userId);
|
|
606
609
|
}
|
|
607
610
|
/**
|
|
608
611
|
* This method returns Promise that resolves with the token information
|
|
@@ -645,7 +648,7 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
|
|
|
645
648
|
*
|
|
646
649
|
*/
|
|
647
650
|
async exchangeToken(config, userId) {
|
|
648
|
-
return this.
|
|
651
|
+
return this.authCore.exchangeToken(config, userId);
|
|
649
652
|
}
|
|
650
653
|
/**
|
|
651
654
|
* This method can be used to update the configurations passed into the constructor of the AsgardeoAuthClient.
|
|
@@ -667,10 +670,10 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
|
|
|
667
670
|
*
|
|
668
671
|
*/
|
|
669
672
|
async reInitialize(config) {
|
|
670
|
-
return this.
|
|
673
|
+
return this.authCore.reInitialize(config);
|
|
671
674
|
}
|
|
672
675
|
async getSignInUrl(requestConfig, userId) {
|
|
673
|
-
return this.
|
|
676
|
+
return this.authCore.getAuthURL(userId, requestConfig);
|
|
674
677
|
}
|
|
675
678
|
/**
|
|
676
679
|
* This method returns a Promise that resolves with the response returned by the server.
|
|
@@ -690,7 +693,7 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
|
|
|
690
693
|
*
|
|
691
694
|
*/
|
|
692
695
|
async revokeAccessToken(userId) {
|
|
693
|
-
return this.
|
|
696
|
+
return this.authCore.revokeAccessToken(userId);
|
|
694
697
|
}
|
|
695
698
|
/**
|
|
696
699
|
* This method refreshes the access token and returns a Promise that resolves with the new access
|
|
@@ -711,7 +714,7 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
|
|
|
711
714
|
* @memberof AsgardeoNodeClient
|
|
712
715
|
*/
|
|
713
716
|
refreshAccessToken(userId) {
|
|
714
|
-
return this.
|
|
717
|
+
return this.authCore.refreshAccessToken(userId);
|
|
715
718
|
}
|
|
716
719
|
/**
|
|
717
720
|
* This method returns if the user has been successfully signed out or not.
|
|
@@ -754,10 +757,10 @@ var AsgardeoNodeClient = class _AsgardeoNodeClient {
|
|
|
754
757
|
return _AsgardeoNodeClient.didSignOutFail(afterSignOutUrl);
|
|
755
758
|
}
|
|
756
759
|
async getStorageManager() {
|
|
757
|
-
return this.
|
|
760
|
+
return this.authCore.getStorageManager();
|
|
758
761
|
}
|
|
759
762
|
async decodeJwtToken(token) {
|
|
760
|
-
return this.
|
|
763
|
+
return this.authCore.decodeJwtToken(token);
|
|
761
764
|
}
|
|
762
765
|
};
|
|
763
766
|
|