@thunderid/node 0.0.5 → 0.0.6

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.
Files changed (47) hide show
  1. package/dist/ThunderIDNodeClient.d.ts +18 -8
  2. package/dist/ThunderIDNodeClient.d.ts.map +1 -1
  3. package/dist/cjs/index.cjs +125 -592
  4. package/dist/index.d.ts +9 -6
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +123 -579
  7. package/dist/{__legacy__/constants/logger-config.d.ts → models/AuthURLCallback.d.ts} +9 -15
  8. package/dist/models/AuthURLCallback.d.ts.map +1 -0
  9. package/dist/models/config.d.ts +27 -14
  10. package/dist/models/config.d.ts.map +1 -1
  11. package/dist/{__legacy__/stores/memory-cache-store.d.ts → stores/MemoryCacheStore.d.ts} +7 -2
  12. package/dist/stores/MemoryCacheStore.d.ts.map +1 -0
  13. package/dist/{__legacy__/utils/crypto-utils.d.ts → utils/NodeCryptoUtils.d.ts} +7 -8
  14. package/dist/utils/NodeCryptoUtils.d.ts.map +1 -0
  15. package/dist/{__legacy__/utils/session-utils.d.ts → utils/SessionUtils.d.ts} +21 -2
  16. package/dist/utils/SessionUtils.d.ts.map +1 -0
  17. package/dist/utils/getSessionCookieOptions.d.ts +2 -22
  18. package/dist/utils/getSessionCookieOptions.d.ts.map +1 -1
  19. package/package.json +2 -2
  20. package/dist/__legacy__/client.d.ts +0 -355
  21. package/dist/__legacy__/client.d.ts.map +0 -1
  22. package/dist/__legacy__/constants/index.d.ts +0 -20
  23. package/dist/__legacy__/constants/index.d.ts.map +0 -1
  24. package/dist/__legacy__/constants/logger-config.d.ts.map +0 -1
  25. package/dist/__legacy__/constants/uuid-config.d.ts +0 -19
  26. package/dist/__legacy__/constants/uuid-config.d.ts.map +0 -1
  27. package/dist/__legacy__/core/authentication.d.ts +0 -46
  28. package/dist/__legacy__/core/authentication.d.ts.map +0 -1
  29. package/dist/__legacy__/core/index.d.ts +0 -19
  30. package/dist/__legacy__/core/index.d.ts.map +0 -1
  31. package/dist/__legacy__/models/index.d.ts +0 -20
  32. package/dist/__legacy__/models/index.d.ts.map +0 -1
  33. package/dist/__legacy__/models/session-data.d.ts +0 -23
  34. package/dist/__legacy__/models/session-data.d.ts.map +0 -1
  35. package/dist/__legacy__/models/url-callback.d.ts +0 -19
  36. package/dist/__legacy__/models/url-callback.d.ts.map +0 -1
  37. package/dist/__legacy__/stores/index.d.ts +0 -19
  38. package/dist/__legacy__/stores/index.d.ts.map +0 -1
  39. package/dist/__legacy__/stores/memory-cache-store.d.ts.map +0 -1
  40. package/dist/__legacy__/utils/crypto-utils.d.ts.map +0 -1
  41. package/dist/__legacy__/utils/index.d.ts +0 -20
  42. package/dist/__legacy__/utils/index.d.ts.map +0 -1
  43. package/dist/__legacy__/utils/logger-utils.d.ts +0 -26
  44. package/dist/__legacy__/utils/logger-utils.d.ts.map +0 -1
  45. package/dist/__legacy__/utils/session-utils.d.ts.map +0 -1
  46. package/dist/models/cookies.d.ts +0 -59
  47. package/dist/models/cookies.d.ts.map +0 -1
package/dist/index.js CHANGED
@@ -1,15 +1,19 @@
1
1
  import fetch, { Headers, Request, Response } from "cross-fetch";
2
- import { ThunderIDAuthClient, ThunderIDAuthException, ThunderIDJavaScriptClient, VendorConstants } from "@thunderid/javascript";
2
+ import { ThunderIDAuthException, ThunderIDJavaScriptClient, VendorConstants } from "@thunderid/javascript";
3
3
  import cache from "memory-cache";
4
- import { v4, validate, version } from "uuid";
5
4
  import base64url from "base64url";
6
5
  import sha256 from "fast-sha256";
7
6
  import * as jose from "jose";
8
7
  import randombytes from "secure-random-bytes";
8
+ import { v4, validate, version } from "uuid";
9
9
 
10
10
  export * from "@thunderid/javascript"
11
11
 
12
- //#region src/__legacy__/stores/memory-cache-store.ts
12
+ //#region src/stores/MemoryCacheStore.ts
13
+ /**
14
+ * In-memory key-value store backed by `memory-cache`.
15
+ * Used as the default storage when no custom store is provided to `ThunderIDNodeClient`.
16
+ */
13
17
  var MemoryCacheStore = class {
14
18
  async setData(key, value) {
15
19
  cache.put(key, value);
@@ -21,97 +25,15 @@ var MemoryCacheStore = class {
21
25
  cache.del(key);
22
26
  }
23
27
  };
28
+ var MemoryCacheStore_default = MemoryCacheStore;
24
29
 
25
30
  //#endregion
26
- //#region src/__legacy__/constants/uuid-config.ts
31
+ //#region src/utils/NodeCryptoUtils.ts
27
32
  /**
28
- * Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
29
- *
30
- * WSO2 LLC. licenses this file to you under the Apache License,
31
- * Version 2.0 (the "License"); you may not use this file except
32
- * in compliance with the License.
33
- * You may obtain a copy of the License at
34
- *
35
- * http://www.apache.org/licenses/LICENSE-2.0
36
- *
37
- * Unless required by applicable law or agreed to in writing,
38
- * software distributed under the License is distributed on an
39
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
40
- * KIND, either express or implied. See the License for the
41
- * specific language governing permissions and limitations
42
- * under the License.
33
+ * Node.js crypto utilities implementing the `Crypto` interface.
34
+ * Uses `jose`, `base64url`, `fast-sha256`, and `secure-random-bytes`.
43
35
  */
44
- const UUID_VERSION = 4;
45
-
46
- //#endregion
47
- //#region src/__legacy__/constants/logger-config.ts
48
- const LOGGER_CONFIG = {
49
- bgGreen: "\x1B[42m",
50
- bgRed: "\x1B[41m",
51
- bgWhite: "\x1B[47m",
52
- bgYellow: "\x1B[43m",
53
- fgBlack: "\x1B[30m",
54
- fgGreen: "\x1B[32m",
55
- fgRed: "\x1B[31m",
56
- fgWhite: "\x1B[37m",
57
- fgYellow: "\x1B[33m",
58
- reset: "\x1B[0m"
59
- };
60
-
61
- //#endregion
62
- //#region src/__legacy__/utils/session-utils.ts
63
- var SessionUtils = class {
64
- constructor() {}
65
- static createUUID() {
66
- return v4();
67
- }
68
- static validateUUID(uuid) {
69
- if (validate(uuid) && version(uuid) === UUID_VERSION) return Promise.resolve(true);
70
- return Promise.resolve(false);
71
- }
72
- static validateSession(sessionData) {
73
- if (Date.now() < sessionData.created_at + parseInt(sessionData.expires_in, 10) * 60 * 1e3) return Promise.resolve(true);
74
- Logger.warn("Expired Session");
75
- return Promise.resolve(false);
76
- }
77
- };
78
-
79
- //#endregion
80
- //#region src/__legacy__/utils/logger-utils.ts
81
- var LogLevel = /* @__PURE__ */ function(LogLevel$1) {
82
- LogLevel$1[LogLevel$1["DEBUG"] = 0] = "DEBUG";
83
- LogLevel$1[LogLevel$1["INFO"] = 1] = "INFO";
84
- LogLevel$1[LogLevel$1["WARN"] = 2] = "WARN";
85
- LogLevel$1[LogLevel$1["ERROR"] = 3] = "ERROR";
86
- LogLevel$1[LogLevel$1["OFF"] = 4] = "OFF";
87
- return LogLevel$1;
88
- }(LogLevel || {});
89
- var Logger = class {
90
- static LOG_LEVEL = process.env["LOG_LEVEL"] ?? LogLevel[LogLevel.OFF];
91
- constructor() {}
92
- static debug(message) {
93
- if (LogLevel[this.LOG_LEVEL] <= LogLevel.DEBUG) console.log(LOGGER_CONFIG.bgGreen, LOGGER_CONFIG.fgBlack, "DEBUG", LOGGER_CONFIG.reset, LOGGER_CONFIG.fgGreen, message, LOGGER_CONFIG.reset);
94
- }
95
- static info(message) {
96
- if (LogLevel[this.LOG_LEVEL] <= LogLevel.INFO) console.log(LOGGER_CONFIG.bgWhite, LOGGER_CONFIG.fgBlack, "INFO", LOGGER_CONFIG.reset, LOGGER_CONFIG.fgWhite, message, LOGGER_CONFIG.reset);
97
- }
98
- static warn(message) {
99
- if (LogLevel[this.LOG_LEVEL] <= LogLevel.WARN) console.log(LOGGER_CONFIG.bgYellow, LOGGER_CONFIG.fgBlack, "WARNING", LOGGER_CONFIG.reset, LOGGER_CONFIG.fgYellow, message, LOGGER_CONFIG.reset);
100
- }
101
- static error(message) {
102
- if (LogLevel[this.LOG_LEVEL] <= LogLevel.ERROR) console.log(LOGGER_CONFIG.bgRed, LOGGER_CONFIG.fgBlack, "ERROR", LOGGER_CONFIG.reset, LOGGER_CONFIG.fgRed, message, LOGGER_CONFIG.reset);
103
- }
104
- };
105
-
106
- //#endregion
107
- //#region src/__legacy__/utils/crypto-utils.ts
108
36
  var NodeCryptoUtils = class {
109
- constructor() {}
110
- /**
111
- * Get URL encoded string.
112
- *
113
- * @returns {string} base 64 url encoded value.
114
- */
115
37
  base64URLEncode(value) {
116
38
  return base64url.encode(value).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
117
39
  }
@@ -135,40 +57,83 @@ var NodeCryptoUtils = class {
135
57
  }).then(() => Promise.resolve(true));
136
58
  }
137
59
  };
60
+ var NodeCryptoUtils_default = NodeCryptoUtils;
138
61
 
139
62
  //#endregion
140
- //#region src/__legacy__/core/authentication.ts
141
- var ThunderIDNodeCore = class ThunderIDNodeCore {
142
- auth;
143
- cryptoUtils;
144
- store;
145
- storageManager;
146
- constructor(config, store) {
147
- if (!store) this.store = new MemoryCacheStore();
148
- else this.store = store;
149
- this.cryptoUtils = new NodeCryptoUtils();
150
- this.auth = new ThunderIDAuthClient();
151
- this.auth.initialize(config, this.store, this.cryptoUtils);
152
- this.storageManager = this.auth.getStorageManager();
153
- Logger.debug("Initialized ThunderIDAuthClient successfully");
63
+ //#region src/utils/SessionUtils.ts
64
+ const UUID_VERSION = 4;
65
+ /**
66
+ * Utility class for session validation and UUID management.
67
+ */
68
+ var SessionUtils = class {
69
+ constructor() {}
70
+ /**
71
+ * Generates a new UUID v4 string.
72
+ *
73
+ * @returns A new UUID string.
74
+ */
75
+ static createUUID() {
76
+ return v4();
77
+ }
78
+ /**
79
+ * Returns `true` if the given string is a valid UUID v4.
80
+ *
81
+ * @param uuid - The UUID string to validate.
82
+ */
83
+ static validateUUID(uuid) {
84
+ if (validate(uuid) && version(uuid) === UUID_VERSION) return Promise.resolve(true);
85
+ return Promise.resolve(false);
154
86
  }
155
- async signIn(authURLCallback, userId, authorizationCode, sessionState, state, signInConfig) {
156
- if (!userId) return Promise.reject(new ThunderIDAuthException("NODE-AUTH_CORE-SI-NF01", "No user ID was provided.", "Unable to sign in the user as no user ID was provided."));
87
+ /**
88
+ * Returns `true` if the session token is still within its validity window.
89
+ *
90
+ * @param sessionData - The session data to check.
91
+ */
92
+ static validateSession(sessionData) {
93
+ const currentTime = Date.now();
94
+ const expiryTimeStamp = sessionData.created_at + parseInt(sessionData.expires_in, 10) * 60 * 1e3;
95
+ return Promise.resolve(currentTime < expiryTimeStamp);
96
+ }
97
+ };
98
+ var SessionUtils_default = SessionUtils;
99
+
100
+ //#endregion
101
+ //#region src/ThunderIDNodeClient.ts
102
+ var ThunderIDNodeClient = class extends ThunderIDJavaScriptClient {
103
+ _nodeInstanceId = 0;
104
+ constructor(instanceId = 0) {
105
+ super(void 0, new NodeCryptoUtils_default());
106
+ this._nodeInstanceId = instanceId;
107
+ }
108
+ async initialize(config, storage) {
109
+ const merged = {
110
+ ...config,
111
+ instanceId: this._nodeInstanceId
112
+ };
113
+ const store = storage ?? new MemoryCacheStore_default();
114
+ return super.initialize(merged, store);
115
+ }
116
+ getInstanceId() {
117
+ return this._nodeInstanceId;
118
+ }
119
+ async signIn(...args) {
120
+ const [authURLCallback, userId, authorizationCode, sessionState, state, signInConfig] = args;
121
+ if (!userId) return Promise.reject(new ThunderIDAuthException("NODE-AUTH_CLIENT-SI-NF01", "No user ID was provided.", "Unable to sign in the user as no user ID was provided."));
157
122
  if (await this.isSignedIn(userId)) {
158
- const sessionData = await this.storageManager.getSessionData(userId);
123
+ const sessionData$1 = await this.getStorageManager().getSessionData(userId);
159
124
  return Promise.resolve({
160
- accessToken: sessionData.access_token,
161
- createdAt: sessionData.created_at,
162
- expiresIn: sessionData.expires_in,
163
- idToken: sessionData.id_token,
164
- refreshToken: sessionData.refresh_token ?? "",
165
- scope: sessionData.scope,
166
- tokenType: sessionData.token_type
125
+ accessToken: sessionData$1.access_token,
126
+ createdAt: sessionData$1.created_at,
127
+ expiresIn: sessionData$1.expires_in,
128
+ idToken: sessionData$1.id_token,
129
+ refreshToken: sessionData$1.refresh_token ?? "",
130
+ scope: sessionData$1.scope,
131
+ tokenType: sessionData$1.token_type
167
132
  });
168
133
  }
169
134
  if (!authorizationCode || !state) {
170
- if (!authURLCallback || typeof authURLCallback !== "function") return Promise.reject(new ThunderIDAuthException("NODE-AUTH_CORE-SI-NF02", "Invalid AuthURLCallback function.", "The AuthURLCallback is not defined or is not a function."));
171
- authURLCallback(await this.getAuthURL(userId, signInConfig));
135
+ if (!authURLCallback || typeof authURLCallback !== "function") return Promise.reject(new ThunderIDAuthException("NODE-AUTH_CLIENT-SI-NF02", "Invalid AuthURLCallback function.", "The AuthURLCallback is not defined or is not a function."));
136
+ authURLCallback(await this.getSignInUrl(signInConfig, userId));
172
137
  return Promise.resolve({
173
138
  accessToken: "",
174
139
  createdAt: 0,
@@ -176,460 +141,72 @@ var ThunderIDNodeCore = class ThunderIDNodeCore {
176
141
  idToken: "",
177
142
  refreshToken: "",
178
143
  scope: "",
179
- session: "",
180
144
  tokenType: ""
181
145
  });
182
146
  }
183
- return this.requestAccessToken(authorizationCode, sessionState ?? "", userId, state);
184
- }
185
- async getAuthURL(userId, signInConfig) {
186
- const authURL = await this.auth.getSignInUrl(signInConfig, userId);
187
- if (authURL) return Promise.resolve(authURL.toString());
188
- return Promise.reject(new ThunderIDAuthException("NODE-AUTH_CORE-GAU-NF01", "Getting Authorization URL failed.", "No authorization URL was returned by the ThunderID Auth JS SDK."));
147
+ await this.requestAccessToken(authorizationCode, sessionState ?? "", state, userId);
148
+ const sessionData = await this.getStorageManager().getSessionData(userId);
149
+ return Promise.resolve({
150
+ accessToken: sessionData.access_token,
151
+ createdAt: sessionData.created_at,
152
+ expiresIn: sessionData.expires_in,
153
+ idToken: sessionData.id_token,
154
+ refreshToken: sessionData.refresh_token ?? "",
155
+ scope: sessionData.scope,
156
+ tokenType: sessionData.token_type
157
+ });
189
158
  }
190
- async requestAccessToken(authorizationCode, sessionState, userId, state) {
191
- return this.auth.requestAccessToken(authorizationCode, sessionState, state, userId);
192
- }
193
- async getIdToken(userId) {
194
- if (!await this.isSignedIn(userId)) return Promise.reject(new ThunderIDAuthException("NODE-AUTH_CORE-GIT-NF01", "The user is not logged in.", "No session ID was found for the requested user. User is not logged in."));
195
- const idToken = await this.auth.getIdToken(userId);
196
- if (idToken) return Promise.resolve(idToken);
197
- return Promise.reject(new ThunderIDAuthException("NODE-AUTH_CORE-GIT-NF02", "Requesting ID Token Failed", "No ID Token was returned by the ThunderID Auth JS SDK."));
159
+ async getSignInUrl(requestConfig, userId) {
160
+ const url = await super.getSignInUrl(requestConfig, userId);
161
+ if (!url) return Promise.reject(new ThunderIDAuthException("NODE-AUTH_CLIENT-GSIU-NF01", "Getting authorization URL failed.", "No authorization URL was returned."));
162
+ return url;
198
163
  }
199
- async refreshAccessToken(userId) {
200
- return this.auth.refreshAccessToken(userId);
164
+ async signOut(...args) {
165
+ const userId = typeof args[0] === "string" ? args[0] : void 0;
166
+ const signOutUrl = await this.getSignOutUrl(userId);
167
+ if (!signOutUrl) return Promise.reject(new ThunderIDAuthException("NODE-AUTH_CLIENT-SO-NF01", "Signing out the user failed.", "Could not obtain the sign-out URL from the server."));
168
+ return signOutUrl;
201
169
  }
202
170
  async isSignedIn(userId) {
203
171
  try {
204
- if (!await this.auth.isSignedIn(userId)) return await Promise.resolve(false);
205
- if (await SessionUtils.validateSession(await this.storageManager.getSessionData(userId))) return await Promise.resolve(true);
206
- if (await this.refreshAccessToken(userId)) return await Promise.resolve(true);
207
- this.storageManager.removeSessionData(userId);
208
- this.storageManager.getTemporaryData(userId);
209
- return await Promise.resolve(false);
210
- } catch (error) {
211
- return Promise.reject(error);
172
+ if (!await super.isSignedIn(userId)) return false;
173
+ const sm = this.getStorageManager();
174
+ const sessionData = await sm.getSessionData(userId);
175
+ if (await SessionUtils_default.validateSession(sessionData)) return true;
176
+ if (await this.refreshAccessToken(userId)) return true;
177
+ await sm.removeSessionData(userId);
178
+ return false;
179
+ } catch {
180
+ return false;
212
181
  }
213
182
  }
214
- async signOut(userId) {
215
- const signOutURL = await this.auth.getSignOutUrl(userId);
216
- if (!signOutURL) return Promise.reject(new ThunderIDAuthException("NODE-AUTH_CORE-SO-NF01", "Signing out the user failed.", "Could not obtain the sign-out URL from the server."));
217
- return Promise.resolve(signOutURL);
218
- }
219
- async getUser(userId) {
220
- return this.auth.getUser(userId);
183
+ async getIdToken(userId) {
184
+ if (!await this.isSignedIn(userId)) return Promise.reject(new ThunderIDAuthException("NODE-AUTH_CLIENT-GIT-NF01", "The user is not logged in.", "No session was found for the requested user."));
185
+ return super.getIdToken(userId);
221
186
  }
222
- async getConfigData() {
223
- return this.storageManager.getConfigData();
187
+ async refreshAccessToken(userId) {
188
+ return super.refreshAccessToken(userId);
224
189
  }
225
- async getOpenIDProviderEndpoints() {
226
- return this.auth.getOpenIDProviderEndpoints();
190
+ async revokeAccessToken(userId) {
191
+ return super.revokeAccessToken(userId);
227
192
  }
228
193
  async getDecodedIdToken(userId, idToken) {
229
- return this.auth.getDecodedIdToken(userId, idToken);
194
+ return super.getDecodedIdToken(userId, idToken);
230
195
  }
231
196
  async getAccessToken(userId) {
232
- return this.auth.getAccessToken(userId);
233
- }
234
- async exchangeToken(config, userId) {
235
- return this.auth.exchangeToken(config, userId);
236
- }
237
- async reInitialize(config) {
238
- return this.auth.reInitialize(config);
239
- }
240
- async revokeAccessToken(userId) {
241
- return this.auth.revokeAccessToken(userId);
242
- }
243
- static didSignOutFail(afterSignOutUrl) {
244
- return ThunderIDNodeCore.didSignOutFail(afterSignOutUrl);
245
- }
246
- static isSignOutSuccessful(afterSignOutUrl) {
247
- return ThunderIDNodeCore.isSignOutSuccessful(afterSignOutUrl);
248
- }
249
- getStorageManager() {
250
- return this.storageManager;
251
- }
252
- async decodeJwtToken(token) {
253
- return this.auth.decodeJwtToken(token);
254
- }
255
- };
256
-
257
- //#endregion
258
- //#region src/__legacy__/client.ts
259
- /**
260
- * This class provides the necessary methods needed to implement authentication.
261
- *
262
- * @export
263
- * @class ThunderIDNodeClient
264
- */
265
- var ThunderIDNodeClient = class ThunderIDNodeClient {
266
- authCore;
267
- /**
268
- * This is the constructor method that returns an instance of the `ThunderIDNodeClient` class.
269
- *
270
- * @param {AuthClientConfig<T>} config - The configuration object.
271
- * @param {Storage} store - The store object.
272
- *
273
- * @example
274
- * ```
275
- * const _store: Storage = new DataStore();
276
- * const _config = {
277
- afterSignInUrl: "http://localhost:3000/sign-in",
278
- afterSignOutUrl: "http://localhost:3000/dashboard",
279
- clientId: "client ID",
280
- serverOrigin: "https://api.asgardeo.io/t/<org_name>"
281
- };
282
- * const auth = new ThunderIDNodeClient(_config,_store);
283
- * ```
284
- *
285
- * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#constructor
286
- * @preserve
287
- */
288
- constructor() {}
289
- async initialize(config, store) {
290
- this.authCore = new ThunderIDNodeCore(config, store);
291
- return Promise.resolve(true);
292
- }
293
- /**
294
- * This method logs in a user. If the authorization code is not available it will resolve with the
295
- * authorization URL to authorize the user.
296
- * @param {string} authorizationCode - The authorization code obtained from ThunderID after a user signs in.
297
- * @param {String} sessionState - The session state obtained from ThunderID after a user signs in.
298
- * @param {string} userId - (Optional) A unique ID of the user to be authenticated. This is useful in multi-user
299
- * scenarios where each user should be uniquely identified.
300
- * @param {string} state - The state parameter in the redirect URL.
301
- *
302
- * @return {Promise<URLResponse | NodeTokenResponse>} - A Promise that resolves with the
303
- * [`URLResponse`](#URLResponse) object or a Promise that resolves with
304
- * the [`NodeTokenResponse`](#NodeTokenResponse) object.
305
- *
306
- * @example
307
- * ```
308
- * authClient.signIn(req.query.code, req.query.session_state).then(response => {
309
- * //URL property will available if the user has not been authenticated already
310
- * if (response.hasOwnProperty('url')) {
311
- * res.redirect(response.url)
312
- * } else {
313
- * //Set the cookie
314
- * res.cookie('ASGARDEO_SESSION_ID', response.session, { maxAge: 900000, httpOnly: true, SameSite: true });
315
- * res.status(200).send(response)
316
- * }
317
- *});
318
- * ```
319
- *
320
- * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#signIn
321
- *
322
- * @memberof ThunderIDNodeClient
323
- *
324
- */
325
- async signIn(authURLCallback, userId, authorizationCode, sessionState, state, signInConfig) {
326
- return this.authCore.signIn(authURLCallback, userId, authorizationCode, sessionState, state, signInConfig);
327
- }
328
- /**
329
- * Method to get the configuration data.
330
- *
331
- * @returns {Promise<AuthClientConfig<Config>>} - A promise that resolves with the configuration data.
332
- */
333
- async getConfigData() {
334
- return this.authCore.getConfigData();
335
- }
336
- /**
337
- * This method clears all session data and returns the sign-out URL.
338
- * @param {string} userId - The userId of the user. (If you are using ExpressJS,
339
- * you may get this from the request cookies)
340
- *
341
- * @return {Promise<string>} - A Promise that resolves with the sign-out URL.
342
- *
343
- * @example
344
- * ```
345
- * const signOutUrl = await auth.signOut(userId);
346
- * ```
347
- *
348
- * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#signOut
349
- *
350
- * @memberof ThunderIDNodeClient
351
- *
352
- */
353
- async signOut(userId) {
354
- return this.authCore.signOut(userId);
197
+ return super.getAccessToken(userId);
355
198
  }
356
- /**
357
- * This method returns a boolean value indicating if the user is authenticated or not.
358
- * @param {string} userId - The userId of the user.
359
- * (If you are using ExpressJS, you may get this from the request cookies)
360
- *
361
- * @return { Promise<boolean>} -A boolean value that indicates of the user is authenticated or not.
362
- *
363
- * @example
364
- * ```
365
- * const isAuth = await authClient.isSignedIn("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
366
- * ```
367
- *
368
- * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#isSignedIn
369
- *
370
- * @memberof ThunderIDNodeClient
371
- *
372
- */
373
- async isSignedIn(userId) {
374
- return this.authCore.isSignedIn(userId);
375
- }
376
- /**
377
- * This method returns the id token.
378
- * @param {string} userId - The userId of the user.
379
- * (If you are using ExpressJS, you may get this from the request cookies)
380
- *
381
- * @return {Promise<string>} -A Promise that resolves with the ID Token.
382
- *
383
- * @example
384
- * ```
385
- * const isAuth = await authClient.getIdToken("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
386
- * ```
387
- *
388
- * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getIdToken
389
- *
390
- * @memberof ThunderIDNodeClient
391
- *
392
- */
393
- async getIdToken(userId) {
394
- return this.authCore.getIdToken(userId);
395
- }
396
- /**
397
- * This method returns an object containing basic user information obtained from the id token.
398
- * @param {string} userId - The userId of the user.
399
- * (If you are using ExpressJS, you may get this from the request cookies)
400
- *
401
- * @return {Promise<string>} -A Promise that resolves with the
402
- * An object containing basic user information obtained from the id token.
403
- *
404
- * @example
405
- * ```
406
- * const basicInfo = await authClient.getUser("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
407
- * ```
408
- *
409
- * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getUser
410
- *
411
- * @memberof ThunderIDNodeClient
412
- *
413
- */
414
199
  async getUser(userId) {
415
- return this.authCore.getUser(userId);
200
+ return super.getUser(userId);
416
201
  }
417
- /**
418
- * This method returns an object containing the OIDC service endpoints returned by the `.well-known` endpoint.
419
- * @return {Promise<OIDCEndpoints>} -A Promise that resolves with
420
- * an object containing the OIDC service endpoints returned by the `.well-known` endpoint.
421
- *
422
- * @example
423
- * ```
424
- * const oidcEndpoints = await auth.getOpenIDProviderEndpoints();
425
- * ```
426
- *
427
- * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getOpenIDProviderEndpoints
428
- *
429
- * @memberof ThunderIDNodeClient
430
- *
431
- */
432
202
  async getOpenIDProviderEndpoints() {
433
- return this.authCore.getOpenIDProviderEndpoints();
434
- }
435
- /**
436
- * This method returns the decoded ID token payload.
437
- * @param {string} userId - The userId of the user.
438
- * (If you are using ExpressJS, you may get this from the request cookies)
439
- *
440
- * @return {Promise<IdToken>} -A Promise that resolves with
441
- * an object containing the decoded ID token payload.
442
- *
443
- * @example
444
- * ```
445
- * const decodedIDTokenPayload = await auth.getDecodedIdToken("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
446
- * ```
447
- *
448
- * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getDecodedIdToken
449
- *
450
- * @memberof ThunderIDNodeClient
451
- *
452
- */
453
- async getDecodedIdToken(userId, idToken) {
454
- return this.authCore.getDecodedIdToken(userId, idToken);
203
+ return super.getOpenIDProviderEndpoints();
455
204
  }
456
- /**
457
- * This method returns the access token.
458
- * @param {string} userId - The userId of the user.
459
- * (If you are using ExpressJS, you may get this from the request cookies)
460
- *
461
- * @return {Promise<string>} -A Promise that resolves with
462
- * the access token stored in the store
463
- *
464
- * @example
465
- * ```
466
- *const accessToken = await auth.getAccessToken("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
467
- * ```
468
- *
469
- * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getAccessToken
470
- *
471
- * @memberof ThunderIDNodeClient
472
- *
473
- */
474
- async getAccessToken(userId) {
475
- return this.authCore.getAccessToken(userId);
476
- }
477
- /**
478
- * This method returns Promise that resolves with the token information
479
- * or the response returned by the server depending on the configuration passed.
480
- * @param {TokenExchangeRequestConfig} config - The config object contains attributes that would be used
481
- * to configure the custom grant request.
482
- *
483
- * @param {string} userId - The userId of the user.
484
- * (If you are using ExpressJS, you may get this from the request cookies)
485
- *
486
- * @return {Promise<TokenResponse | Response>} -A Promise that resolves with the token information
487
- * or the response returned by the server depending on the configuration passed.
488
- *
489
- * @example
490
- * ```
491
- * const config = {
492
- * attachToken: false,
493
- * data: {
494
- * client_id: "{{clientId}}",
495
- * grant_type: "account_switch",
496
- * scope: "{{scope}}",
497
- * token: "{{token}}",
498
- * },
499
- * id: "account-switch",
500
- * returnResponse: true,
501
- * returnsSession: true,
502
- * signInRequired: true
503
- * }
504
-
505
- * auth.exchangeToken(config).then((response)=>{
506
- * console.log(response);
507
- * }).catch((error)=>{
508
- * console.error(error);
509
- * });
510
- * ```
511
- *
512
- * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#exchangeToken
513
- *
514
- * @memberof ThunderIDNodeClient
515
- *
516
- */
517
205
  async exchangeToken(config, userId) {
518
- return this.authCore.exchangeToken(config, userId);
519
- }
520
- /**
521
- * This method can be used to update the configurations passed into the constructor of the ThunderIDAuthClient.
522
- * @param {AuthClientConfig<T>} config - The config object containing the attributes
523
- * that can be used to configure the SDK
524
- *
525
- * @return {Promise<void>} -A Promise that resolves with a void.
526
- *
527
- * @example
528
- * ```
529
- * const reInitialize = await auth.reInitialize({
530
- * afterSignOutUrl: "http://localhost:3000/sign-out"
531
- * });
532
- * ```
533
- *
534
- * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#reInitialize
535
- *
536
- * @memberof ThunderIDNodeClient
537
- *
538
- */
539
- async reInitialize(config) {
540
- return this.authCore.reInitialize(config);
541
- }
542
- async getSignInUrl(requestConfig, userId) {
543
- return this.authCore.getAuthURL(userId, requestConfig);
544
- }
545
- /**
546
- * This method returns a Promise that resolves with the response returned by the server.
547
- * @param {string} userId - The userId of the user.
548
- * (If you are using ExpressJS, you may get this from the request cookies)
549
- *
550
- * @return {Promise<Response>} -A Promise that resolves with the response returned by the server.
551
- *
552
- * @example
553
- * ```
554
- * const revokeToken = await auth.revokeAccessToken("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
555
- * ```
556
- *
557
- * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#revokeAccessToken
558
- *
559
- * @memberof ThunderIDNodeClient
560
- *
561
- */
562
- async revokeAccessToken(userId) {
563
- return this.authCore.revokeAccessToken(userId);
564
- }
565
- /**
566
- * This method refreshes the access token and returns a Promise that resolves with the new access
567
- * token and other relevant data.
568
- *
569
- * @param {string} userId - A unique ID of the user to be authenticated. This is useful in multi-user
570
- * scenarios where each user should be uniquely identified.
571
- *
572
- * @returns {Promise<TokenResponse>} - A Promise that resolves with the token response.
573
- *
574
- * @example
575
- * ```
576
- * const tokenResponse = await auth.refreshAccessToken("a2a2972c-51cd-5e9d-a9ae-058fae9f7927")
577
- * ```
578
- *
579
- * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#refreshAccessToken
580
- *
581
- * @memberof ThunderIDNodeClient
582
- */
583
- refreshAccessToken(userId) {
584
- return this.authCore.refreshAccessToken(userId);
585
- }
586
- /**
587
- * This method returns if the user has been successfully signed out or not.
588
- * @param {string} afterSignOutUrl - The URL to which the user is redirected to
589
- * after signing out from the server.
590
- *
591
- * @return {boolean} - A boolean value indicating if the user has been signed out or not.
592
- *
593
- * @example
594
- * ```
595
- * const isSignedOut = auth.isSignOutSuccessful(<signout_url>);;
596
- * ```
597
- *
598
- * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#isSignOutSuccessful
599
- *
600
- * @memberof ThunderIDNodeClient
601
- *
602
- */
603
- static isSignOutSuccessful(afterSignOutUrl) {
604
- return ThunderIDNodeClient.isSignOutSuccessful(afterSignOutUrl);
605
- }
606
- /**
607
- * This method returns if sign-out failed or not
608
- * @param {string} afterSignOutUrl - The URL to which the user is redirected to
609
- * after signing out from the server.
610
- *
611
- * @return {boolean} - A boolean value indicating if sign-out failed or not.
612
- *
613
- * @example
614
- * ```
615
- * const isSignedOut = auth.isSignOutSuccessful(<signout_url>);
616
- * ```
617
- *
618
- * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#didSignOutFail
619
- *
620
- * @memberof ThunderIDNodeClient
621
- *
622
- */
623
- static didSignOutFail(afterSignOutUrl) {
624
- return ThunderIDNodeClient.didSignOutFail(afterSignOutUrl);
625
- }
626
- async getStorageManager() {
627
- return this.authCore.getStorageManager();
628
- }
629
- async decodeJwtToken(token) {
630
- return this.authCore.decodeJwtToken(token);
206
+ return super.exchangeToken(config, userId);
631
207
  }
632
208
  };
209
+ var ThunderIDNodeClient_default = ThunderIDNodeClient;
633
210
 
634
211
  //#endregion
635
212
  //#region src/constants/CookieConfig.ts
@@ -668,46 +245,13 @@ var generateSessionId_default = generateSessionId;
668
245
 
669
246
  //#endregion
670
247
  //#region src/utils/getSessionCookieOptions.ts
671
- /**
672
- * Creates a complete set of cookie options by merging provided options with defaults
673
- *
674
- * @param options - Partial cookie options to override defaults
675
- *
676
- * @returns Complete cookie options with all required fields
677
- *
678
- * @example
679
- * ```ts
680
- * // Use defaults with only maxAge override
681
- * const options = getSessionCookieOptions({ maxAge: 3600 });
682
- *
683
- * // Override multiple defaults
684
- * const options = getSessionCookieOptions({
685
- * maxAge: 3600,
686
- * secure: true,
687
- * sameSite: 'strict'
688
- * });
689
- * ```
690
- */
691
248
  const getSessionCookieOptions = (options) => ({
692
- ...options,
693
249
  httpOnly: options.httpOnly ?? CookieConfig_default.DEFAULT_HTTP_ONLY,
694
- maxAge: options.maxAge ?? CookieConfig_default.DEFAULT_MAX_AGE,
695
250
  sameSite: options.sameSite ?? CookieConfig_default.DEFAULT_SAME_SITE,
696
251
  secure: options.secure ?? CookieConfig_default.DEFAULT_SECURE
697
252
  });
698
253
  var getSessionCookieOptions_default = getSessionCookieOptions;
699
254
 
700
- //#endregion
701
- //#region src/ThunderIDNodeClient.ts
702
- /**
703
- * Base class for implementing ThunderID in Node.js based applications.
704
- * This class provides the core functionality for managing user authentication and sessions.
705
- *getConfigData
706
- * @typeParam T - Configuration type that extends ThunderIDNodeConfig.
707
- */
708
- var ThunderIDNodeClient$1 = class extends ThunderIDJavaScriptClient {};
709
- var ThunderIDNodeClient_default = ThunderIDNodeClient$1;
710
-
711
255
  //#endregion
712
256
  //#region src/index.ts
713
257
  if (!globalThis.fetch) {
@@ -718,4 +262,4 @@ if (!globalThis.fetch) {
718
262
  }
719
263
 
720
264
  //#endregion
721
- export { CookieConfig_default as CookieConfig, CookieOptions, ThunderIDNodeClient as LegacyThunderIDNodeClient, Logger, ThunderIDNodeClient_default as ThunderIDNodeClient, ThunderIDNodeConfig, generateSessionId_default as generateSessionId, getSessionCookieOptions_default as getSessionCookieOptions };
265
+ export { CookieConfig_default as CookieConfig, MemoryCacheStore_default as MemoryCacheStore, NodeCryptoUtils_default as NodeCryptoUtils, SessionUtils_default as SessionUtils, ThunderIDNodeClient_default as ThunderIDNodeClient, generateSessionId_default as generateSessionId, getSessionCookieOptions_default as getSessionCookieOptions };