@asgardeo/javascript 0.8.3 → 0.9.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/dist/StorageManager.d.ts +2 -2
- package/dist/__legacy__/models/client-config.d.ts +12 -0
- package/dist/cjs/index.js +105 -74
- package/dist/cjs/index.js.map +2 -2
- package/dist/index.js +105 -74
- package/dist/index.js.map +2 -2
- package/dist/models/config.d.ts +17 -0
- package/dist/models/v2/embedded-flow-v2.d.ts +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -529,7 +529,27 @@ var AuthenticationHelper = class {
|
|
|
529
529
|
}
|
|
530
530
|
async replaceCustomGrantTemplateTags(text, userId) {
|
|
531
531
|
const configData = await this.config();
|
|
532
|
-
const
|
|
532
|
+
const sourceInstanceId = configData.organizationChain?.sourceInstanceId ?? null;
|
|
533
|
+
let sessionData;
|
|
534
|
+
if (sourceInstanceId) {
|
|
535
|
+
const { clientId } = configData;
|
|
536
|
+
let instanceKey;
|
|
537
|
+
if (clientId) {
|
|
538
|
+
instanceKey = `instance_${sourceInstanceId}-${clientId}`;
|
|
539
|
+
} else {
|
|
540
|
+
instanceKey = `instance_${sourceInstanceId}`;
|
|
541
|
+
}
|
|
542
|
+
sessionData = await this.storageManager.getSessionData(userId, instanceKey);
|
|
543
|
+
if (!sessionData || !sessionData.access_token) {
|
|
544
|
+
throw new AsgardeoAuthException(
|
|
545
|
+
"JS-AUTH_HELPER-RCGTT-NE01",
|
|
546
|
+
"No session data found for source instance.",
|
|
547
|
+
"Failed to retrieve session data from the source organization context."
|
|
548
|
+
);
|
|
549
|
+
}
|
|
550
|
+
} else {
|
|
551
|
+
sessionData = await this.storageManager.getSessionData(userId);
|
|
552
|
+
}
|
|
533
553
|
const scope = processOpenIDScopes_default(configData.scopes);
|
|
534
554
|
if (typeof text !== "string") {
|
|
535
555
|
return text;
|
|
@@ -781,8 +801,17 @@ var StorageManager = class _StorageManager {
|
|
|
781
801
|
const dataToBeSavedJSON = JSON.stringify(dataToBeSaved);
|
|
782
802
|
await this.store.setData(key, dataToBeSavedJSON);
|
|
783
803
|
}
|
|
784
|
-
resolveKey(store, userId) {
|
|
785
|
-
|
|
804
|
+
resolveKey(store, userId, instanceId) {
|
|
805
|
+
if (userId && instanceId) {
|
|
806
|
+
return `${store}-${instanceId}-${userId}`;
|
|
807
|
+
}
|
|
808
|
+
if (userId) {
|
|
809
|
+
return `${store}-${this.id}-${userId}`;
|
|
810
|
+
}
|
|
811
|
+
if (instanceId) {
|
|
812
|
+
return `${store}-${instanceId}`;
|
|
813
|
+
}
|
|
814
|
+
return `${store}-${this.id}`;
|
|
786
815
|
}
|
|
787
816
|
static isLocalStorageAvailable() {
|
|
788
817
|
try {
|
|
@@ -818,8 +847,8 @@ var StorageManager = class _StorageManager {
|
|
|
818
847
|
async getTemporaryData(userId) {
|
|
819
848
|
return JSON.parse(await this.store.getData(this.resolveKey("temporary_data" /* TemporaryData */, userId)) ?? null);
|
|
820
849
|
}
|
|
821
|
-
async getSessionData(userId) {
|
|
822
|
-
return JSON.parse(await this.store.getData(this.resolveKey("session_data" /* SessionData */, userId)) ?? null);
|
|
850
|
+
async getSessionData(userId, instanceId) {
|
|
851
|
+
return JSON.parse(await this.store.getData(this.resolveKey("session_data" /* SessionData */, userId, instanceId)) ?? null);
|
|
823
852
|
}
|
|
824
853
|
async getCustomData(key, userId) {
|
|
825
854
|
return JSON.parse(await this.store.getData(this.resolveKey(key, userId)) ?? null);
|
|
@@ -1218,77 +1247,74 @@ var _AsgardeoAuthClient = class _AsgardeoAuthClient {
|
|
|
1218
1247
|
* @preserve
|
|
1219
1248
|
*/
|
|
1220
1249
|
async requestAccessToken(authorizationCode, sessionState, state, userId, tokenRequestConfig) {
|
|
1221
|
-
|
|
1222
|
-
const tokenEndpoint = (await this.oidcProviderMetaDataProvider()).token_endpoint;
|
|
1223
|
-
const configData = await this.configProvider();
|
|
1224
|
-
if (!tokenEndpoint || tokenEndpoint.trim().length === 0) {
|
|
1225
|
-
throw new AsgardeoAuthException(
|
|
1226
|
-
"JS-AUTH_CORE-RAT1-NF01",
|
|
1227
|
-
"Token endpoint not found.",
|
|
1228
|
-
"No token endpoint was found in the OIDC provider meta data returned by the well-known endpoint or the token endpoint passed to the SDK is empty."
|
|
1229
|
-
);
|
|
1230
|
-
}
|
|
1231
|
-
if (sessionState) {
|
|
1232
|
-
await this.storageManager.setSessionDataParameter(
|
|
1233
|
-
OIDCRequestConstants_default.Params.SESSION_STATE,
|
|
1234
|
-
sessionState,
|
|
1235
|
-
userId
|
|
1236
|
-
);
|
|
1237
|
-
}
|
|
1238
|
-
const body = new URLSearchParams();
|
|
1239
|
-
body.set("client_id", configData.clientId);
|
|
1240
|
-
if (configData.clientSecret && configData.clientSecret.trim().length > 0) {
|
|
1241
|
-
body.set("client_secret", configData.clientSecret);
|
|
1242
|
-
}
|
|
1243
|
-
const code = authorizationCode;
|
|
1244
|
-
body.set("code", code);
|
|
1245
|
-
body.set("grant_type", "authorization_code");
|
|
1246
|
-
body.set("redirect_uri", configData.afterSignInUrl);
|
|
1247
|
-
if (tokenRequestConfig?.params) {
|
|
1248
|
-
Object.entries(tokenRequestConfig.params).forEach(([key, value]) => {
|
|
1249
|
-
body.append(key, value);
|
|
1250
|
-
});
|
|
1251
|
-
}
|
|
1252
|
-
if (configData.enablePKCE) {
|
|
1253
|
-
body.set(
|
|
1254
|
-
"code_verifier",
|
|
1255
|
-
`${await this.storageManager.getTemporaryDataParameter(extractPkceStorageKeyFromState_default(state), userId)}`
|
|
1256
|
-
);
|
|
1257
|
-
await this.storageManager.removeTemporaryDataParameter(extractPkceStorageKeyFromState_default(state), userId);
|
|
1258
|
-
}
|
|
1259
|
-
let tokenResponse;
|
|
1260
|
-
try {
|
|
1261
|
-
tokenResponse = await fetch(tokenEndpoint, {
|
|
1262
|
-
body,
|
|
1263
|
-
credentials: configData.sendCookiesInRequests ? "include" : "same-origin",
|
|
1264
|
-
headers: {
|
|
1265
|
-
Accept: "application/json",
|
|
1266
|
-
"Content-Type": "application/x-www-form-urlencoded"
|
|
1267
|
-
},
|
|
1268
|
-
method: "POST"
|
|
1269
|
-
});
|
|
1270
|
-
} catch (error2) {
|
|
1271
|
-
throw new AsgardeoAuthException(
|
|
1272
|
-
"JS-AUTH_CORE-RAT1-NE02",
|
|
1273
|
-
"Requesting access token failed",
|
|
1274
|
-
error2 ?? "The request to get the access token from the server failed."
|
|
1275
|
-
);
|
|
1276
|
-
}
|
|
1277
|
-
if (!tokenResponse.ok) {
|
|
1278
|
-
throw new AsgardeoAuthException(
|
|
1279
|
-
"JS-AUTH_CORE-RAT1-HE03",
|
|
1280
|
-
`Requesting access token failed with ${tokenResponse.statusText}`,
|
|
1281
|
-
await tokenResponse.json()
|
|
1282
|
-
);
|
|
1283
|
-
}
|
|
1284
|
-
return this.authHelper.handleTokenResponse(tokenResponse, userId);
|
|
1285
|
-
};
|
|
1286
|
-
if (await this.storageManager.getTemporaryDataParameter(
|
|
1250
|
+
if (!await this.storageManager.getTemporaryDataParameter(
|
|
1287
1251
|
OIDCDiscoveryConstants_default.Storage.StorageKeys.OPENID_PROVIDER_CONFIG_INITIATED
|
|
1288
1252
|
)) {
|
|
1289
|
-
|
|
1253
|
+
await this.loadOpenIDProviderConfiguration(false);
|
|
1254
|
+
}
|
|
1255
|
+
const tokenEndpoint = (await this.oidcProviderMetaDataProvider()).token_endpoint;
|
|
1256
|
+
const configData = await this.configProvider();
|
|
1257
|
+
if (!tokenEndpoint || tokenEndpoint.trim().length === 0) {
|
|
1258
|
+
throw new AsgardeoAuthException(
|
|
1259
|
+
"JS-AUTH_CORE-RAT1-NF01",
|
|
1260
|
+
"Token endpoint not found.",
|
|
1261
|
+
"No token endpoint was found in the OIDC provider meta data returned by the well-known endpoint or the token endpoint passed to the SDK is empty."
|
|
1262
|
+
);
|
|
1263
|
+
}
|
|
1264
|
+
if (sessionState) {
|
|
1265
|
+
await this.storageManager.setSessionDataParameter(
|
|
1266
|
+
OIDCRequestConstants_default.Params.SESSION_STATE,
|
|
1267
|
+
sessionState,
|
|
1268
|
+
userId
|
|
1269
|
+
);
|
|
1270
|
+
}
|
|
1271
|
+
const body = new URLSearchParams();
|
|
1272
|
+
body.set("client_id", configData.clientId);
|
|
1273
|
+
if (configData.clientSecret && configData.clientSecret.trim().length > 0) {
|
|
1274
|
+
body.set("client_secret", configData.clientSecret);
|
|
1275
|
+
}
|
|
1276
|
+
const code = authorizationCode;
|
|
1277
|
+
body.set("code", code);
|
|
1278
|
+
body.set("grant_type", "authorization_code");
|
|
1279
|
+
body.set("redirect_uri", configData.afterSignInUrl);
|
|
1280
|
+
if (tokenRequestConfig?.params) {
|
|
1281
|
+
Object.entries(tokenRequestConfig.params).forEach(([key, value]) => {
|
|
1282
|
+
body.append(key, value);
|
|
1283
|
+
});
|
|
1284
|
+
}
|
|
1285
|
+
if (configData.enablePKCE) {
|
|
1286
|
+
body.set(
|
|
1287
|
+
"code_verifier",
|
|
1288
|
+
`${await this.storageManager.getTemporaryDataParameter(extractPkceStorageKeyFromState_default(state), userId)}`
|
|
1289
|
+
);
|
|
1290
|
+
await this.storageManager.removeTemporaryDataParameter(extractPkceStorageKeyFromState_default(state), userId);
|
|
1290
1291
|
}
|
|
1291
|
-
|
|
1292
|
+
let tokenResponse;
|
|
1293
|
+
try {
|
|
1294
|
+
tokenResponse = await fetch(tokenEndpoint, {
|
|
1295
|
+
body,
|
|
1296
|
+
credentials: configData.sendCookiesInRequests ? "include" : "same-origin",
|
|
1297
|
+
headers: {
|
|
1298
|
+
Accept: "application/json",
|
|
1299
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
1300
|
+
},
|
|
1301
|
+
method: "POST"
|
|
1302
|
+
});
|
|
1303
|
+
} catch (error2) {
|
|
1304
|
+
throw new AsgardeoAuthException(
|
|
1305
|
+
"JS-AUTH_CORE-RAT1-NE02",
|
|
1306
|
+
"Requesting access token failed",
|
|
1307
|
+
error2 ?? "The request to get the access token from the server failed."
|
|
1308
|
+
);
|
|
1309
|
+
}
|
|
1310
|
+
if (!tokenResponse.ok) {
|
|
1311
|
+
throw new AsgardeoAuthException(
|
|
1312
|
+
"JS-AUTH_CORE-RAT1-HE03",
|
|
1313
|
+
`Requesting access token failed with ${tokenResponse.statusText}`,
|
|
1314
|
+
await tokenResponse.json()
|
|
1315
|
+
);
|
|
1316
|
+
}
|
|
1317
|
+
return this.authHelper.handleTokenResponse(tokenResponse, userId);
|
|
1292
1318
|
}
|
|
1293
1319
|
async loadOpenIDProviderConfiguration(forceInit) {
|
|
1294
1320
|
const configData = await this.configProvider();
|
|
@@ -1734,6 +1760,11 @@ var _AsgardeoAuthClient = class _AsgardeoAuthClient {
|
|
|
1734
1760
|
* @preserve
|
|
1735
1761
|
*/
|
|
1736
1762
|
async exchangeToken(config, userId) {
|
|
1763
|
+
if (!await this.storageManager.getTemporaryDataParameter(
|
|
1764
|
+
OIDCDiscoveryConstants_default.Storage.StorageKeys.OPENID_PROVIDER_CONFIG_INITIATED
|
|
1765
|
+
)) {
|
|
1766
|
+
await this.loadOpenIDProviderConfiguration(false);
|
|
1767
|
+
}
|
|
1737
1768
|
const oidcProviderMetadata = await this.oidcProviderMetaDataProvider();
|
|
1738
1769
|
const configData = await this.configProvider();
|
|
1739
1770
|
let tokenEndpoint;
|
|
@@ -3311,9 +3342,9 @@ var EmbeddedFlowActionVariant = /* @__PURE__ */ ((EmbeddedFlowActionVariant2) =>
|
|
|
3311
3342
|
EmbeddedFlowActionVariant2["Danger"] = "DANGER";
|
|
3312
3343
|
EmbeddedFlowActionVariant2["Info"] = "INFO";
|
|
3313
3344
|
EmbeddedFlowActionVariant2["Link"] = "LINK";
|
|
3345
|
+
EmbeddedFlowActionVariant2["Outlined"] = "OUTLINED";
|
|
3314
3346
|
EmbeddedFlowActionVariant2["Primary"] = "PRIMARY";
|
|
3315
3347
|
EmbeddedFlowActionVariant2["Secondary"] = "SECONDARY";
|
|
3316
|
-
EmbeddedFlowActionVariant2["Social"] = "SOCIAL";
|
|
3317
3348
|
EmbeddedFlowActionVariant2["Success"] = "SUCCESS";
|
|
3318
3349
|
EmbeddedFlowActionVariant2["Tertiary"] = "TERTIARY";
|
|
3319
3350
|
EmbeddedFlowActionVariant2["Warning"] = "WARNING";
|