@asgardeo/node 0.0.1
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/LICENSE +201 -0
- package/README.md +72 -0
- package/dist/AsgardeoNodeClient.d.ts +28 -0
- package/dist/__legacy__/client.d.ts +346 -0
- package/dist/__legacy__/constants/index.d.ts +19 -0
- package/dist/__legacy__/constants/logger-config.d.ts +29 -0
- package/dist/__legacy__/constants/uuid-config.d.ts +18 -0
- package/dist/__legacy__/core/authentication.d.ts +43 -0
- package/dist/__legacy__/core/index.d.ts +18 -0
- package/dist/__legacy__/models/index.d.ts +19 -0
- package/dist/__legacy__/models/session-data.d.ts +22 -0
- package/dist/__legacy__/models/url-callback.d.ts +20 -0
- package/dist/__legacy__/stores/index.d.ts +18 -0
- package/dist/__legacy__/stores/memory-cache-store.d.ts +23 -0
- package/dist/__legacy__/utils/crypto-utils.d.ts +31 -0
- package/dist/__legacy__/utils/index.d.ts +19 -0
- package/dist/__legacy__/utils/logger-utils.d.ts +25 -0
- package/dist/__legacy__/utils/session-utils.d.ts +24 -0
- package/dist/cjs/index.js +795 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/constants/CookieConfig.d.ts +26 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +759 -0
- package/dist/index.js.map +7 -0
- package/dist/models/config.d.ts +29 -0
- package/dist/models/cookies.d.ts +58 -0
- package/dist/utils/generateSessionId.d.ts +19 -0
- package/dist/utils/getSessionCookieOptions.d.ts +40 -0
- package/package.json +68 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,759 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
|
|
5
|
+
// src/index.ts
|
|
6
|
+
import fetch, { Headers, Request, Response } from "cross-fetch";
|
|
7
|
+
|
|
8
|
+
// src/__legacy__/core/authentication.ts
|
|
9
|
+
import {
|
|
10
|
+
AsgardeoAuthClient,
|
|
11
|
+
AsgardeoAuthException
|
|
12
|
+
} from "@asgardeo/javascript";
|
|
13
|
+
|
|
14
|
+
// src/__legacy__/stores/memory-cache-store.ts
|
|
15
|
+
import cache from "memory-cache";
|
|
16
|
+
var MemoryCacheStore = class {
|
|
17
|
+
async setData(key, value) {
|
|
18
|
+
cache.put(key, value);
|
|
19
|
+
}
|
|
20
|
+
async getData(key) {
|
|
21
|
+
return cache.get(key) ?? "{}";
|
|
22
|
+
}
|
|
23
|
+
async removeData(key) {
|
|
24
|
+
cache.del(key);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// src/__legacy__/utils/session-utils.ts
|
|
29
|
+
import { validate as uuidValidate, version as uuidVersion, v4 as uuidv4 } from "uuid";
|
|
30
|
+
|
|
31
|
+
// src/__legacy__/constants/uuid-config.ts
|
|
32
|
+
var UUID_VERSION = 4;
|
|
33
|
+
|
|
34
|
+
// src/__legacy__/constants/logger-config.ts
|
|
35
|
+
var LOGGER_CONFIG = {
|
|
36
|
+
bgGreen: "\x1B[42m",
|
|
37
|
+
bgRed: "\x1B[41m",
|
|
38
|
+
bgWhite: "\x1B[47m",
|
|
39
|
+
bgYellow: "\x1B[43m",
|
|
40
|
+
fgBlack: "\x1B[30m",
|
|
41
|
+
fgGreen: "\x1B[32m",
|
|
42
|
+
fgRed: "\x1B[31m",
|
|
43
|
+
fgWhite: "\x1B[37m",
|
|
44
|
+
fgYellow: "\x1B[33m",
|
|
45
|
+
reset: "\x1B[0m"
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// src/__legacy__/utils/session-utils.ts
|
|
49
|
+
var SessionUtils = class {
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
51
|
+
constructor() {
|
|
52
|
+
}
|
|
53
|
+
static createUUID() {
|
|
54
|
+
const generated_uuid = uuidv4();
|
|
55
|
+
return generated_uuid;
|
|
56
|
+
}
|
|
57
|
+
static validateUUID(uuid) {
|
|
58
|
+
if (uuidValidate(uuid) && uuidVersion(uuid) === UUID_VERSION) {
|
|
59
|
+
return Promise.resolve(true);
|
|
60
|
+
} else {
|
|
61
|
+
return Promise.resolve(false);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
static validateSession(sessionData) {
|
|
65
|
+
const currentTime = Date.now();
|
|
66
|
+
const expiryTimeStamp = sessionData.created_at + parseInt(sessionData.expires_in) * 60 * 1e3;
|
|
67
|
+
if (currentTime < expiryTimeStamp) {
|
|
68
|
+
return Promise.resolve(true);
|
|
69
|
+
} else {
|
|
70
|
+
Logger.warn("Expired Session");
|
|
71
|
+
return Promise.resolve(false);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// src/__legacy__/utils/logger-utils.ts
|
|
77
|
+
var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
|
|
78
|
+
LogLevel2[LogLevel2["DEBUG"] = 0] = "DEBUG";
|
|
79
|
+
LogLevel2[LogLevel2["INFO"] = 1] = "INFO";
|
|
80
|
+
LogLevel2[LogLevel2["WARN"] = 2] = "WARN";
|
|
81
|
+
LogLevel2[LogLevel2["ERROR"] = 3] = "ERROR";
|
|
82
|
+
LogLevel2[LogLevel2["OFF"] = 4] = "OFF";
|
|
83
|
+
return LogLevel2;
|
|
84
|
+
})(LogLevel || {});
|
|
85
|
+
var Logger = class {
|
|
86
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
87
|
+
constructor() {
|
|
88
|
+
}
|
|
89
|
+
static debug(message) {
|
|
90
|
+
if (LogLevel[this.LOG_LEVEL] <= 0 /* DEBUG */)
|
|
91
|
+
console.log(
|
|
92
|
+
LOGGER_CONFIG.bgGreen,
|
|
93
|
+
LOGGER_CONFIG.fgBlack,
|
|
94
|
+
"DEBUG",
|
|
95
|
+
LOGGER_CONFIG.reset,
|
|
96
|
+
LOGGER_CONFIG.fgGreen,
|
|
97
|
+
message,
|
|
98
|
+
LOGGER_CONFIG.reset
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
static info(message) {
|
|
102
|
+
if (LogLevel[this.LOG_LEVEL] <= 1 /* INFO */)
|
|
103
|
+
console.log(
|
|
104
|
+
LOGGER_CONFIG.bgWhite,
|
|
105
|
+
LOGGER_CONFIG.fgBlack,
|
|
106
|
+
"INFO",
|
|
107
|
+
LOGGER_CONFIG.reset,
|
|
108
|
+
LOGGER_CONFIG.fgWhite,
|
|
109
|
+
message,
|
|
110
|
+
LOGGER_CONFIG.reset
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
static warn(message) {
|
|
114
|
+
if (LogLevel[this.LOG_LEVEL] <= 2 /* WARN */)
|
|
115
|
+
console.log(
|
|
116
|
+
LOGGER_CONFIG.bgYellow,
|
|
117
|
+
LOGGER_CONFIG.fgBlack,
|
|
118
|
+
"WARNING",
|
|
119
|
+
LOGGER_CONFIG.reset,
|
|
120
|
+
LOGGER_CONFIG.fgYellow,
|
|
121
|
+
message,
|
|
122
|
+
LOGGER_CONFIG.reset
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
static error(message) {
|
|
126
|
+
if (LogLevel[this.LOG_LEVEL] <= 3 /* ERROR */)
|
|
127
|
+
console.log(
|
|
128
|
+
LOGGER_CONFIG.bgRed,
|
|
129
|
+
LOGGER_CONFIG.fgBlack,
|
|
130
|
+
"ERROR",
|
|
131
|
+
LOGGER_CONFIG.reset,
|
|
132
|
+
LOGGER_CONFIG.fgRed,
|
|
133
|
+
message,
|
|
134
|
+
LOGGER_CONFIG.reset
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
__publicField(Logger, "LOG_LEVEL", process.env["LOG_LEVEL"] ?? LogLevel[4 /* OFF */]);
|
|
139
|
+
|
|
140
|
+
// src/__legacy__/utils/crypto-utils.ts
|
|
141
|
+
import base64url from "base64url";
|
|
142
|
+
import sha256 from "fast-sha256";
|
|
143
|
+
import * as jose from "jose";
|
|
144
|
+
import randombytes from "secure-random-bytes";
|
|
145
|
+
var NodeCryptoUtils = class {
|
|
146
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
147
|
+
constructor() {
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Get URL encoded string.
|
|
151
|
+
*
|
|
152
|
+
* @returns {string} base 64 url encoded value.
|
|
153
|
+
*/
|
|
154
|
+
base64URLEncode(value) {
|
|
155
|
+
return base64url.encode(value).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
156
|
+
}
|
|
157
|
+
base64URLDecode(value) {
|
|
158
|
+
return base64url.decode(value).toString();
|
|
159
|
+
}
|
|
160
|
+
hashSha256(data) {
|
|
161
|
+
return Buffer.from(sha256(new TextEncoder().encode(data)));
|
|
162
|
+
}
|
|
163
|
+
generateRandomBytes(length) {
|
|
164
|
+
return randombytes(length);
|
|
165
|
+
}
|
|
166
|
+
async verifyJwt(idToken, jwk, algorithms, clientID, issuer, subject, clockTolerance) {
|
|
167
|
+
const key = await jose.importJWK(jwk);
|
|
168
|
+
return jose.jwtVerify(idToken, key, {
|
|
169
|
+
algorithms,
|
|
170
|
+
audience: clientID,
|
|
171
|
+
clockTolerance,
|
|
172
|
+
issuer,
|
|
173
|
+
subject
|
|
174
|
+
}).then(() => {
|
|
175
|
+
return Promise.resolve(true);
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
// src/__legacy__/core/authentication.ts
|
|
181
|
+
var AsgardeoNodeCore = class _AsgardeoNodeCore {
|
|
182
|
+
constructor(config, store) {
|
|
183
|
+
__publicField(this, "_auth");
|
|
184
|
+
__publicField(this, "_cryptoUtils");
|
|
185
|
+
__publicField(this, "_store");
|
|
186
|
+
__publicField(this, "_dataLayer");
|
|
187
|
+
if (!store) {
|
|
188
|
+
this._store = new MemoryCacheStore();
|
|
189
|
+
} else {
|
|
190
|
+
this._store = store;
|
|
191
|
+
}
|
|
192
|
+
this._cryptoUtils = new NodeCryptoUtils();
|
|
193
|
+
this._auth = new AsgardeoAuthClient();
|
|
194
|
+
this._auth.initialize(config, this._store, this._cryptoUtils);
|
|
195
|
+
this._dataLayer = this._auth.getDataLayer();
|
|
196
|
+
Logger.debug("Initialized AsgardeoAuthClient successfully");
|
|
197
|
+
}
|
|
198
|
+
async signIn(authURLCallback, userID, authorizationCode, sessionState, state, signInConfig) {
|
|
199
|
+
if (!userID) {
|
|
200
|
+
return Promise.reject(
|
|
201
|
+
new AsgardeoAuthException(
|
|
202
|
+
"NODE-AUTH_CORE-SI-NF01",
|
|
203
|
+
"No user ID was provided.",
|
|
204
|
+
"Unable to sign in the user as no user ID was provided."
|
|
205
|
+
)
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
if (await this.isAuthenticated(userID)) {
|
|
209
|
+
const sessionData = await this._dataLayer.getSessionData(userID);
|
|
210
|
+
return Promise.resolve({
|
|
211
|
+
accessToken: sessionData.access_token,
|
|
212
|
+
createdAt: sessionData.created_at,
|
|
213
|
+
expiresIn: sessionData.expires_in,
|
|
214
|
+
idToken: sessionData.id_token,
|
|
215
|
+
refreshToken: sessionData.refresh_token ?? "",
|
|
216
|
+
scope: sessionData.scope,
|
|
217
|
+
tokenType: sessionData.token_type
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
if (!authorizationCode || !state) {
|
|
221
|
+
if (!authURLCallback || typeof authURLCallback !== "function") {
|
|
222
|
+
return Promise.reject(
|
|
223
|
+
new AsgardeoAuthException(
|
|
224
|
+
"NODE-AUTH_CORE-SI-NF02",
|
|
225
|
+
"Invalid AuthURLCallback function.",
|
|
226
|
+
"The AuthURLCallback is not defined or is not a function."
|
|
227
|
+
)
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
const authURL = await this.getAuthURL(userID, signInConfig);
|
|
231
|
+
authURLCallback(authURL);
|
|
232
|
+
return Promise.resolve({
|
|
233
|
+
accessToken: "",
|
|
234
|
+
createdAt: 0,
|
|
235
|
+
expiresIn: "",
|
|
236
|
+
idToken: "",
|
|
237
|
+
refreshToken: "",
|
|
238
|
+
scope: "",
|
|
239
|
+
session: "",
|
|
240
|
+
tokenType: ""
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
return this.requestAccessToken(authorizationCode, sessionState ?? "", userID, state);
|
|
244
|
+
}
|
|
245
|
+
async getAuthURL(userId, signInConfig) {
|
|
246
|
+
const authURL = await this._auth.getAuthorizationURL(signInConfig, userId);
|
|
247
|
+
if (authURL) {
|
|
248
|
+
return Promise.resolve(authURL.toString());
|
|
249
|
+
} else {
|
|
250
|
+
return Promise.reject(
|
|
251
|
+
new AsgardeoAuthException(
|
|
252
|
+
"NODE-AUTH_CORE-GAU-NF01",
|
|
253
|
+
"Getting Authorization URL failed.",
|
|
254
|
+
"No authorization URL was returned by the Asgardeo Auth JS SDK."
|
|
255
|
+
)
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
async requestAccessToken(authorizationCode, sessionState, userId, state) {
|
|
260
|
+
return this._auth.requestAccessToken(authorizationCode, sessionState, state, userId);
|
|
261
|
+
}
|
|
262
|
+
async getIDToken(userId) {
|
|
263
|
+
const is_logged_in = await this.isAuthenticated(userId);
|
|
264
|
+
if (!is_logged_in) {
|
|
265
|
+
return Promise.reject(
|
|
266
|
+
new AsgardeoAuthException(
|
|
267
|
+
"NODE-AUTH_CORE-GIT-NF01",
|
|
268
|
+
"The user is not logged in.",
|
|
269
|
+
"No session ID was found for the requested user. User is not logged in."
|
|
270
|
+
)
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
const idToken = await this._auth.getIDToken(userId);
|
|
274
|
+
if (idToken) {
|
|
275
|
+
return Promise.resolve(idToken);
|
|
276
|
+
} else {
|
|
277
|
+
return Promise.reject(
|
|
278
|
+
new AsgardeoAuthException(
|
|
279
|
+
"NODE-AUTH_CORE-GIT-NF02",
|
|
280
|
+
"Requesting ID Token Failed",
|
|
281
|
+
"No ID Token was returned by the Asgardeo Auth JS SDK."
|
|
282
|
+
)
|
|
283
|
+
);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
async refreshAccessToken(userId) {
|
|
287
|
+
return this._auth.refreshAccessToken(userId);
|
|
288
|
+
}
|
|
289
|
+
async isAuthenticated(userId) {
|
|
290
|
+
try {
|
|
291
|
+
if (!await this._auth.isAuthenticated(userId)) {
|
|
292
|
+
return Promise.resolve(false);
|
|
293
|
+
}
|
|
294
|
+
if (await SessionUtils.validateSession(await this._dataLayer.getSessionData(userId))) {
|
|
295
|
+
return Promise.resolve(true);
|
|
296
|
+
}
|
|
297
|
+
const refreshed_token = await this.refreshAccessToken(userId);
|
|
298
|
+
if (refreshed_token) {
|
|
299
|
+
return Promise.resolve(true);
|
|
300
|
+
}
|
|
301
|
+
this._dataLayer.removeSessionData(userId);
|
|
302
|
+
this._dataLayer.getTemporaryData(userId);
|
|
303
|
+
return Promise.resolve(false);
|
|
304
|
+
} catch (error) {
|
|
305
|
+
return Promise.reject(error);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
async signOut(userId) {
|
|
309
|
+
const signOutURL = await this._auth.getSignOutURL(userId);
|
|
310
|
+
if (!signOutURL) {
|
|
311
|
+
return Promise.reject(
|
|
312
|
+
new AsgardeoAuthException(
|
|
313
|
+
"NODE-AUTH_CORE-SO-NF01",
|
|
314
|
+
"Signing out the user failed.",
|
|
315
|
+
"Could not obtain the sign-out URL from the server."
|
|
316
|
+
)
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
return Promise.resolve(signOutURL);
|
|
320
|
+
}
|
|
321
|
+
async getBasicUserInfo(userId) {
|
|
322
|
+
return this._auth.getBasicUserInfo(userId);
|
|
323
|
+
}
|
|
324
|
+
async getOIDCServiceEndpoints() {
|
|
325
|
+
return this._auth.getOIDCServiceEndpoints();
|
|
326
|
+
}
|
|
327
|
+
async getDecodedIDToken(userId) {
|
|
328
|
+
return this._auth.getDecodedIDToken(userId);
|
|
329
|
+
}
|
|
330
|
+
async getAccessToken(userId) {
|
|
331
|
+
return this._auth.getAccessToken(userId);
|
|
332
|
+
}
|
|
333
|
+
async requestCustomGrant(config, userId) {
|
|
334
|
+
return this._auth.requestCustomGrant(config, userId);
|
|
335
|
+
}
|
|
336
|
+
async updateConfig(config) {
|
|
337
|
+
return this._auth.updateConfig(config);
|
|
338
|
+
}
|
|
339
|
+
async revokeAccessToken(userId) {
|
|
340
|
+
return this._auth.revokeAccessToken(userId);
|
|
341
|
+
}
|
|
342
|
+
static didSignOutFail(signOutRedirectURL) {
|
|
343
|
+
return _AsgardeoNodeCore.didSignOutFail(signOutRedirectURL);
|
|
344
|
+
}
|
|
345
|
+
static isSignOutSuccessful(signOutRedirectURL) {
|
|
346
|
+
return _AsgardeoNodeCore.isSignOutSuccessful(signOutRedirectURL);
|
|
347
|
+
}
|
|
348
|
+
getDataLayer() {
|
|
349
|
+
return this._dataLayer;
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
// src/__legacy__/client.ts
|
|
354
|
+
var AsgardeoNodeClient = class _AsgardeoNodeClient {
|
|
355
|
+
/**
|
|
356
|
+
* This is the constructor method that returns an instance of the `AsgardeoNodeClient` class.
|
|
357
|
+
*
|
|
358
|
+
* @param {AuthClientConfig<T>} config - The configuration object.
|
|
359
|
+
* @param {Store} store - The store object.
|
|
360
|
+
*
|
|
361
|
+
* @example
|
|
362
|
+
* ```
|
|
363
|
+
* const _store: Store = new DataStore();
|
|
364
|
+
* const _config = {
|
|
365
|
+
signInRedirectURL: "http://localhost:3000/sign-in",
|
|
366
|
+
signOutRedirectURL: "http://localhost:3000/dashboard",
|
|
367
|
+
clientID: "client ID",
|
|
368
|
+
serverOrigin: "https://api.asgardeo.io/t/<org_name>"
|
|
369
|
+
};
|
|
370
|
+
* const auth = new AsgardeoNodeClient(_config,_store);
|
|
371
|
+
* ```
|
|
372
|
+
*
|
|
373
|
+
* @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#constructor
|
|
374
|
+
* @preserve
|
|
375
|
+
*/
|
|
376
|
+
constructor() {
|
|
377
|
+
__publicField(this, "_authCore");
|
|
378
|
+
}
|
|
379
|
+
async initialize(config, store) {
|
|
380
|
+
this._authCore = new AsgardeoNodeCore(config, store);
|
|
381
|
+
return Promise.resolve(true);
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* This method logs in a user. If the authorization code is not available it will resolve with the
|
|
385
|
+
* authorization URL to authorize the user.
|
|
386
|
+
* @param {string} authorizationCode - The authorization code obtained from Asgardeo after a user signs in.
|
|
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
|
|
389
|
+
* scenarios where each user should be uniquely identified.
|
|
390
|
+
* @param {string} state - The state parameter in the redirect URL.
|
|
391
|
+
*
|
|
392
|
+
* @return {Promise<URLResponse | NodeTokenResponse>} - A Promise that resolves with the
|
|
393
|
+
* [`URLResponse`](#URLResponse) object or a Promise that resolves with
|
|
394
|
+
* the [`NodeTokenResponse`](#NodeTokenResponse) object.
|
|
395
|
+
*
|
|
396
|
+
* @example
|
|
397
|
+
* ```
|
|
398
|
+
* authClient.signIn(req.query.code, req.query.session_state).then(response => {
|
|
399
|
+
* //URL property will available if the user has not been authenticated already
|
|
400
|
+
* if (response.hasOwnProperty('url')) {
|
|
401
|
+
* res.redirect(response.url)
|
|
402
|
+
* } else {
|
|
403
|
+
* //Set the cookie
|
|
404
|
+
* res.cookie('ASGARDEO_SESSION_ID', response.session, { maxAge: 900000, httpOnly: true, SameSite: true });
|
|
405
|
+
* res.status(200).send(response)
|
|
406
|
+
* }
|
|
407
|
+
*});
|
|
408
|
+
* ```
|
|
409
|
+
*
|
|
410
|
+
* @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#signIn
|
|
411
|
+
*
|
|
412
|
+
* @memberof AsgardeoNodeClient
|
|
413
|
+
*
|
|
414
|
+
*/
|
|
415
|
+
async signIn(authURLCallback, userId, authorizationCode, sessionState, state, signInConfig) {
|
|
416
|
+
return this._authCore.signIn(authURLCallback, userId, authorizationCode, sessionState, state, signInConfig);
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* This method clears all session data and returns the sign-out URL.
|
|
420
|
+
* @param {string} userId - The userId of the user. (If you are using ExpressJS,
|
|
421
|
+
* you may get this from the request cookies)
|
|
422
|
+
*
|
|
423
|
+
* @return {Promise<string>} - A Promise that resolves with the sign-out URL.
|
|
424
|
+
*
|
|
425
|
+
* @example
|
|
426
|
+
* ```
|
|
427
|
+
* const signOutUrl = await auth.signOut(userId);
|
|
428
|
+
* ```
|
|
429
|
+
*
|
|
430
|
+
* @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#signOut
|
|
431
|
+
*
|
|
432
|
+
* @memberof AsgardeoNodeClient
|
|
433
|
+
*
|
|
434
|
+
*/
|
|
435
|
+
async signOut(userId) {
|
|
436
|
+
return this._authCore.signOut(userId);
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* This method returns a boolean value indicating if the user is authenticated or not.
|
|
440
|
+
* @param {string} userId - The userId of the user.
|
|
441
|
+
* (If you are using ExpressJS, you may get this from the request cookies)
|
|
442
|
+
*
|
|
443
|
+
* @return { Promise<boolean>} -A boolean value that indicates of the user is authenticated or not.
|
|
444
|
+
*
|
|
445
|
+
* @example
|
|
446
|
+
* ```
|
|
447
|
+
* const isAuth = await authClient.isAuthenticated("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
|
|
448
|
+
* ```
|
|
449
|
+
*
|
|
450
|
+
* @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#isAuthenticated
|
|
451
|
+
*
|
|
452
|
+
* @memberof AsgardeoNodeClient
|
|
453
|
+
*
|
|
454
|
+
*/
|
|
455
|
+
async isAuthenticated(userId) {
|
|
456
|
+
return this._authCore.isAuthenticated(userId);
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* This method returns the id token.
|
|
460
|
+
* @param {string} userId - The userId of the user.
|
|
461
|
+
* (If you are using ExpressJS, you may get this from the request cookies)
|
|
462
|
+
*
|
|
463
|
+
* @return {Promise<string>} -A Promise that resolves with the ID Token.
|
|
464
|
+
*
|
|
465
|
+
* @example
|
|
466
|
+
* ```
|
|
467
|
+
* const isAuth = await authClient.getIDToken("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
|
|
468
|
+
* ```
|
|
469
|
+
*
|
|
470
|
+
* @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getIDToken
|
|
471
|
+
*
|
|
472
|
+
* @memberof AsgardeoNodeClient
|
|
473
|
+
*
|
|
474
|
+
*/
|
|
475
|
+
async getIDToken(userId) {
|
|
476
|
+
return this._authCore.getIDToken(userId);
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* This method returns an object containing basic user information obtained from the id token.
|
|
480
|
+
* @param {string} userId - The userId of the user.
|
|
481
|
+
* (If you are using ExpressJS, you may get this from the request cookies)
|
|
482
|
+
*
|
|
483
|
+
* @return {Promise<string>} -A Promise that resolves with the
|
|
484
|
+
* An object containing basic user information obtained from the id token.
|
|
485
|
+
*
|
|
486
|
+
* @example
|
|
487
|
+
* ```
|
|
488
|
+
* const basicInfo = await authClient.getBasicUserInfo("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
|
|
489
|
+
* ```
|
|
490
|
+
*
|
|
491
|
+
* @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getBasicUserInfo
|
|
492
|
+
*
|
|
493
|
+
* @memberof AsgardeoNodeClient
|
|
494
|
+
*
|
|
495
|
+
*/
|
|
496
|
+
async getBasicUserInfo(userId) {
|
|
497
|
+
return this._authCore.getBasicUserInfo(userId);
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* This method returns an object containing the OIDC service endpoints returned by the `.well-known` endpoint.
|
|
501
|
+
* @return {Promise<OIDCEndpoints>} -A Promise that resolves with
|
|
502
|
+
* an object containing the OIDC service endpoints returned by the `.well-known` endpoint.
|
|
503
|
+
*
|
|
504
|
+
* @example
|
|
505
|
+
* ```
|
|
506
|
+
* const oidcEndpoints = await auth.getOIDCServiceEndpoints();
|
|
507
|
+
* ```
|
|
508
|
+
*
|
|
509
|
+
* @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getOIDCServiceEndpoints
|
|
510
|
+
*
|
|
511
|
+
* @memberof AsgardeoNodeClient
|
|
512
|
+
*
|
|
513
|
+
*/
|
|
514
|
+
async getOIDCServiceEndpoints() {
|
|
515
|
+
return this._authCore.getOIDCServiceEndpoints();
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* This method returns the decoded ID token payload.
|
|
519
|
+
* @param {string} userId - The userId of the user.
|
|
520
|
+
* (If you are using ExpressJS, you may get this from the request cookies)
|
|
521
|
+
*
|
|
522
|
+
* @return {Promise<IdTokenPayload>} -A Promise that resolves with
|
|
523
|
+
* an object containing the decoded ID token payload.
|
|
524
|
+
*
|
|
525
|
+
* @example
|
|
526
|
+
* ```
|
|
527
|
+
* const decodedIDTokenPayload = await auth.getDecodedIDToken("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
|
|
528
|
+
* ```
|
|
529
|
+
*
|
|
530
|
+
* @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getDecodedIDToken
|
|
531
|
+
*
|
|
532
|
+
* @memberof AsgardeoNodeClient
|
|
533
|
+
*
|
|
534
|
+
*/
|
|
535
|
+
async getDecodedIDToken(userId) {
|
|
536
|
+
return this._authCore.getDecodedIDToken(userId);
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* This method returns the access token.
|
|
540
|
+
* @param {string} userId - The userId of the user.
|
|
541
|
+
* (If you are using ExpressJS, you may get this from the request cookies)
|
|
542
|
+
*
|
|
543
|
+
* @return {Promise<string>} -A Promise that resolves with
|
|
544
|
+
* the access token stored in the store
|
|
545
|
+
*
|
|
546
|
+
* @example
|
|
547
|
+
* ```
|
|
548
|
+
*const accessToken = await auth.getAccessToken("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
|
|
549
|
+
* ```
|
|
550
|
+
*
|
|
551
|
+
* @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getAccessToken
|
|
552
|
+
*
|
|
553
|
+
* @memberof AsgardeoNodeClient
|
|
554
|
+
*
|
|
555
|
+
*/
|
|
556
|
+
async getAccessToken(userId) {
|
|
557
|
+
return this._authCore.getAccessToken(userId);
|
|
558
|
+
}
|
|
559
|
+
/**
|
|
560
|
+
* This method returns Promise that resolves with the token information
|
|
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
|
|
563
|
+
* to configure the custom grant request.
|
|
564
|
+
*
|
|
565
|
+
* @param {string} userId - The userId of the user.
|
|
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
|
|
569
|
+
* or the response returned by the server depending on the configuration passed.
|
|
570
|
+
*
|
|
571
|
+
* @example
|
|
572
|
+
* ```
|
|
573
|
+
* const config = {
|
|
574
|
+
* attachToken: false,
|
|
575
|
+
* data: {
|
|
576
|
+
* client_id: "{{clientID}}",
|
|
577
|
+
* grant_type: "account_switch",
|
|
578
|
+
* scope: "{{scope}}",
|
|
579
|
+
* token: "{{token}}",
|
|
580
|
+
* },
|
|
581
|
+
* id: "account-switch",
|
|
582
|
+
* returnResponse: true,
|
|
583
|
+
* returnsSession: true,
|
|
584
|
+
* signInRequired: true
|
|
585
|
+
* }
|
|
586
|
+
|
|
587
|
+
* auth.requestCustomGrant(config).then((response)=>{
|
|
588
|
+
* console.log(response);
|
|
589
|
+
* }).catch((error)=>{
|
|
590
|
+
* console.error(error);
|
|
591
|
+
* });
|
|
592
|
+
* ```
|
|
593
|
+
*
|
|
594
|
+
* @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#requestCustomGrant
|
|
595
|
+
*
|
|
596
|
+
* @memberof AsgardeoNodeClient
|
|
597
|
+
*
|
|
598
|
+
*/
|
|
599
|
+
async requestCustomGrant(config, userId) {
|
|
600
|
+
return this._authCore.requestCustomGrant(config, userId);
|
|
601
|
+
}
|
|
602
|
+
/**
|
|
603
|
+
* This method can be used to update the configurations passed into the constructor of the AsgardeoAuthClient.
|
|
604
|
+
* @param {AuthClientConfig<T>} config - The config object containing the attributes
|
|
605
|
+
* that can be used to configure the SDK
|
|
606
|
+
*
|
|
607
|
+
* @return {Promise<void>} -A Promise that resolves with a void.
|
|
608
|
+
*
|
|
609
|
+
* @example
|
|
610
|
+
* ```
|
|
611
|
+
* const updateConfig = await auth.updateConfig({
|
|
612
|
+
* signOutRedirectURL: "http://localhost:3000/sign-out"
|
|
613
|
+
* });
|
|
614
|
+
* ```
|
|
615
|
+
*
|
|
616
|
+
* @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#updateConfig
|
|
617
|
+
*
|
|
618
|
+
* @memberof AsgardeoNodeClient
|
|
619
|
+
*
|
|
620
|
+
*/
|
|
621
|
+
async updateConfig(config) {
|
|
622
|
+
return this._authCore.updateConfig(config);
|
|
623
|
+
}
|
|
624
|
+
/**
|
|
625
|
+
* This method returns a Promise that resolves with the response returned by the server.
|
|
626
|
+
* @param {string} userId - The userId of the user.
|
|
627
|
+
* (If you are using ExpressJS, you may get this from the request cookies)
|
|
628
|
+
*
|
|
629
|
+
* @return {Promise<FetchResponse>} -A Promise that resolves with the response returned by the server.
|
|
630
|
+
*
|
|
631
|
+
* @example
|
|
632
|
+
* ```
|
|
633
|
+
* const revokeToken = await auth.revokeAccessToken("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
|
|
634
|
+
* ```
|
|
635
|
+
*
|
|
636
|
+
* @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#revokeAccessToken
|
|
637
|
+
*
|
|
638
|
+
* @memberof AsgardeoNodeClient
|
|
639
|
+
*
|
|
640
|
+
*/
|
|
641
|
+
async revokeAccessToken(userId) {
|
|
642
|
+
return this._authCore.revokeAccessToken(userId);
|
|
643
|
+
}
|
|
644
|
+
/**
|
|
645
|
+
* This method refreshes the access token and returns a Promise that resolves with the new access
|
|
646
|
+
* token and other relevant data.
|
|
647
|
+
*
|
|
648
|
+
* @param {string} userId - A unique ID of the user to be authenticated. This is useful in multi-user
|
|
649
|
+
* scenarios where each user should be uniquely identified.
|
|
650
|
+
*
|
|
651
|
+
* @returns {Promise<TokenResponse>} - A Promise that resolves with the token response.
|
|
652
|
+
*
|
|
653
|
+
* @example
|
|
654
|
+
* ```
|
|
655
|
+
* const tokenResponse = await auth.refreshAccessToken("a2a2972c-51cd-5e9d-a9ae-058fae9f7927")
|
|
656
|
+
* ```
|
|
657
|
+
*
|
|
658
|
+
* @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#refreshAccessToken
|
|
659
|
+
*
|
|
660
|
+
* @memberof AsgardeoNodeClient
|
|
661
|
+
*/
|
|
662
|
+
refreshAccessToken(userId) {
|
|
663
|
+
return this._authCore.refreshAccessToken(userId);
|
|
664
|
+
}
|
|
665
|
+
/**
|
|
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
|
|
668
|
+
* after signing out from the server.
|
|
669
|
+
*
|
|
670
|
+
* @return {boolean} - A boolean value indicating if the user has been signed out or not.
|
|
671
|
+
*
|
|
672
|
+
* @example
|
|
673
|
+
* ```
|
|
674
|
+
* const isSignedOut = auth.isSignOutSuccessful(<signout_url>);;
|
|
675
|
+
* ```
|
|
676
|
+
*
|
|
677
|
+
* @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#isSignOutSuccessful
|
|
678
|
+
*
|
|
679
|
+
* @memberof AsgardeoNodeClient
|
|
680
|
+
*
|
|
681
|
+
*/
|
|
682
|
+
static isSignOutSuccessful(signOutRedirectURL) {
|
|
683
|
+
return _AsgardeoNodeClient.isSignOutSuccessful(signOutRedirectURL);
|
|
684
|
+
}
|
|
685
|
+
/**
|
|
686
|
+
* This method returns if sign-out failed or not
|
|
687
|
+
* @param {string} signOutRedirectURL - The URL to which the user is redirected to
|
|
688
|
+
* after signing out from the server.
|
|
689
|
+
*
|
|
690
|
+
* @return {boolean} - A boolean value indicating if sign-out failed or not.
|
|
691
|
+
*
|
|
692
|
+
* @example
|
|
693
|
+
* ```
|
|
694
|
+
* const isSignedOut = auth.isSignOutSuccessful(<signout_url>);
|
|
695
|
+
* ```
|
|
696
|
+
*
|
|
697
|
+
* @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#didSignOutFail
|
|
698
|
+
*
|
|
699
|
+
* @memberof AsgardeoNodeClient
|
|
700
|
+
*
|
|
701
|
+
*/
|
|
702
|
+
static didSignOutFail(signOutRedirectURL) {
|
|
703
|
+
return _AsgardeoNodeClient.didSignOutFail(signOutRedirectURL);
|
|
704
|
+
}
|
|
705
|
+
async getDataLayer() {
|
|
706
|
+
return this._authCore.getDataLayer();
|
|
707
|
+
}
|
|
708
|
+
};
|
|
709
|
+
|
|
710
|
+
// src/constants/CookieConfig.ts
|
|
711
|
+
var CookieConfig = class {
|
|
712
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
713
|
+
constructor() {
|
|
714
|
+
}
|
|
715
|
+
};
|
|
716
|
+
__publicField(CookieConfig, "SESSION_COOKIE_NAME", "ASGARDEO_SESSION_ID");
|
|
717
|
+
__publicField(CookieConfig, "DEFAULT_MAX_AGE", 3600);
|
|
718
|
+
__publicField(CookieConfig, "DEFAULT_HTTP_ONLY", true);
|
|
719
|
+
__publicField(CookieConfig, "DEFAULT_SAME_SITE", "lax");
|
|
720
|
+
__publicField(CookieConfig, "DEFAULT_SECURE", true);
|
|
721
|
+
var CookieConfig_default = CookieConfig;
|
|
722
|
+
|
|
723
|
+
// src/utils/generateSessionId.ts
|
|
724
|
+
var generateSessionId = () => (/* @__PURE__ */ new Date()).getTime().toString(36) + Math.random().toString(36).substring(2);
|
|
725
|
+
var generateSessionId_default = generateSessionId;
|
|
726
|
+
|
|
727
|
+
// src/utils/getSessionCookieOptions.ts
|
|
728
|
+
var getSessionCookieOptions = (options) => ({
|
|
729
|
+
...options,
|
|
730
|
+
httpOnly: options.httpOnly ?? CookieConfig_default.DEFAULT_HTTP_ONLY,
|
|
731
|
+
maxAge: options.maxAge ?? CookieConfig_default.DEFAULT_MAX_AGE,
|
|
732
|
+
sameSite: options.sameSite ?? CookieConfig_default.DEFAULT_SAME_SITE,
|
|
733
|
+
secure: options.secure ?? CookieConfig_default.DEFAULT_SECURE
|
|
734
|
+
});
|
|
735
|
+
var getSessionCookieOptions_default = getSessionCookieOptions;
|
|
736
|
+
|
|
737
|
+
// src/AsgardeoNodeClient.ts
|
|
738
|
+
import { AsgardeoJavaScriptClient } from "@asgardeo/javascript";
|
|
739
|
+
var AsgardeoNodeClient2 = class extends AsgardeoJavaScriptClient {
|
|
740
|
+
};
|
|
741
|
+
var AsgardeoNodeClient_default = AsgardeoNodeClient2;
|
|
742
|
+
|
|
743
|
+
// src/index.ts
|
|
744
|
+
export * from "@asgardeo/javascript";
|
|
745
|
+
if (!globalThis.fetch) {
|
|
746
|
+
globalThis.fetch = fetch;
|
|
747
|
+
globalThis.Headers = Headers;
|
|
748
|
+
globalThis.Request = Request;
|
|
749
|
+
globalThis.Response = Response;
|
|
750
|
+
}
|
|
751
|
+
export {
|
|
752
|
+
AsgardeoNodeClient_default as AsgardeoNodeClient,
|
|
753
|
+
CookieConfig_default as CookieConfig,
|
|
754
|
+
AsgardeoNodeClient as LegacyAsgardeoNodeClient,
|
|
755
|
+
Logger,
|
|
756
|
+
generateSessionId_default as generateSessionId,
|
|
757
|
+
getSessionCookieOptions_default as getSessionCookieOptions
|
|
758
|
+
};
|
|
759
|
+
//# sourceMappingURL=index.js.map
|