@asgardeo/javascript 0.0.1 → 0.1.0
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/README.md +3 -3
- package/dist/AsgardeoJavaScriptClient.d.ts +2 -1
- package/dist/IsomorphicCrypto.d.ts +4 -4
- package/dist/{__legacy__/data/data-layer.d.ts → StorageManager.d.ts} +26 -25
- package/dist/__legacy__/client.d.ts +82 -98
- package/dist/__legacy__/helpers/authentication-helper.d.ts +8 -8
- package/dist/__legacy__/models/client-config.d.ts +6 -6
- package/dist/__legacy__/models/index.d.ts +0 -5
- package/dist/api/{oidc/getUserInfo.d.ts → getUserInfo.d.ts} +1 -1
- package/dist/api/handleApplicationNativeAuthentication.d.ts +33 -0
- package/dist/api/initializeApplicationNativeAuthentication.d.ts +117 -0
- package/dist/cjs/index.js +1581 -1188
- package/dist/cjs/index.js.map +4 -4
- package/dist/constants/ApplicationNativeAuthenticationConstants.d.ts +39 -0
- package/dist/constants/OIDCRequestConstants.d.ts +14 -0
- package/dist/constants/PKCEConstants.d.ts +1 -0
- package/dist/constants/TokenExchangeConstants.d.ts +1 -1
- package/dist/{__legacy__/exception → errors}/exception.d.ts +3 -0
- package/dist/{__legacy__/data/index.d.ts → i18n/en-US.d.ts} +4 -2
- package/dist/{__legacy__/exception → i18n}/index.d.ts +2 -2
- package/dist/index.d.ts +28 -10
- package/dist/index.js +1562 -1184
- package/dist/index.js.map +4 -4
- package/dist/models/application-native-authentication.d.ts +82 -0
- package/dist/models/client.d.ts +8 -2
- package/dist/models/config.d.ts +26 -1
- package/dist/models/crypto.d.ts +2 -2
- package/dist/{__legacy__/models/custom-grant.d.ts → models/field.d.ts} +13 -9
- package/dist/models/i18n.d.ts +66 -0
- package/dist/{__legacy__/models/authorization-url.d.ts → models/oauth-request.d.ts} +3 -3
- package/dist/models/oauth-response.d.ts +1 -17
- package/dist/models/scim2-schema.d.ts +3 -0
- package/dist/{__legacy__/models/data.d.ts → models/session.d.ts} +4 -0
- package/dist/models/store.d.ts +1 -1
- package/dist/models/token.d.ts +47 -0
- package/dist/models/user.d.ts +11 -84
- package/dist/theme/types.d.ts +0 -1
- package/dist/utils/deepMerge.d.ts +44 -0
- package/dist/utils/extractTenantDomainFromIdTokenPayload.d.ts +1 -1
- package/dist/utils/extractUserClaimsFromIdToken.d.ts +1 -1
- package/dist/utils/flattenUserSchema.d.ts +64 -0
- package/dist/utils/generateFlattenedUserProfile.d.ts +46 -0
- package/dist/utils/generateUserProfile.d.ts +55 -0
- package/dist/utils/get.d.ts +29 -0
- package/dist/utils/getAuthorizeRequestUrlParams.d.ts +59 -0
- package/dist/utils/getI18nBundles.d.ts +26 -0
- package/dist/utils/getLatestStateParam.d.ts +40 -0
- package/dist/utils/processOpenIDScopes.d.ts +36 -0
- package/dist/{__legacy__/core/index.d.ts → utils/resolveFieldName.d.ts} +3 -2
- package/dist/utils/resolveFieldType.d.ts +20 -0
- package/dist/utils/set.d.ts +30 -0
- package/package.json +4 -4
- package/dist/__legacy__/core/authentication-core.d.ts +0 -51
- package/dist/__legacy__/models/fetch.d.ts +0 -55
- package/dist/__legacy__/models/user.d.ts +0 -85
- package/dist/models/id-token.d.ts +0 -55
package/dist/index.js
CHANGED
|
@@ -1,112 +1,148 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __export = (target, all) => {
|
|
4
|
+
for (var name in all)
|
|
5
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
6
|
+
};
|
|
3
7
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
8
|
|
|
5
|
-
// src/
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
9
|
+
// src/StorageManager.ts
|
|
10
|
+
var ASGARDEO_SESSION_ACTIVE = "asgardeo-session-active";
|
|
11
|
+
var StorageManager = class {
|
|
12
|
+
constructor(instanceID, store) {
|
|
13
|
+
__publicField(this, "_id");
|
|
14
|
+
__publicField(this, "_store");
|
|
15
|
+
this._id = instanceID;
|
|
16
|
+
this._store = store;
|
|
17
|
+
}
|
|
18
|
+
async setDataInBulk(key, data) {
|
|
19
|
+
const existingDataJSON = await this._store.getData(key) ?? null;
|
|
20
|
+
const existingData = existingDataJSON && JSON.parse(existingDataJSON);
|
|
21
|
+
const dataToBeSaved = { ...existingData, ...data };
|
|
22
|
+
const dataToBeSavedJSON = JSON.stringify(dataToBeSaved);
|
|
23
|
+
await this._store.setData(key, dataToBeSavedJSON);
|
|
24
|
+
}
|
|
25
|
+
async setValue(key, attribute, value) {
|
|
26
|
+
const existingDataJSON = await this._store.getData(key) ?? null;
|
|
27
|
+
const existingData = existingDataJSON && JSON.parse(existingDataJSON);
|
|
28
|
+
const dataToBeSaved = { ...existingData, [attribute]: value };
|
|
29
|
+
const dataToBeSavedJSON = JSON.stringify(dataToBeSaved);
|
|
30
|
+
await this._store.setData(key, dataToBeSavedJSON);
|
|
31
|
+
}
|
|
32
|
+
async removeValue(key, attribute) {
|
|
33
|
+
const existingDataJSON = await this._store.getData(key) ?? null;
|
|
34
|
+
const existingData = existingDataJSON && JSON.parse(existingDataJSON);
|
|
35
|
+
const dataToBeSaved = { ...existingData };
|
|
36
|
+
delete dataToBeSaved[attribute];
|
|
37
|
+
const dataToBeSavedJSON = JSON.stringify(dataToBeSaved);
|
|
38
|
+
await this._store.setData(key, dataToBeSavedJSON);
|
|
39
|
+
}
|
|
40
|
+
_resolveKey(store, userId) {
|
|
41
|
+
return userId ? `${store}-${this._id}-${userId}` : `${store}-${this._id}`;
|
|
42
|
+
}
|
|
43
|
+
isLocalStorageAvailable() {
|
|
44
|
+
try {
|
|
45
|
+
const testValue = "__ASGARDEO_AUTH_CORE_LOCAL_STORAGE_TEST__";
|
|
46
|
+
localStorage.setItem(testValue, testValue);
|
|
47
|
+
localStorage.removeItem(testValue);
|
|
48
|
+
return true;
|
|
49
|
+
} catch (error) {
|
|
50
|
+
return false;
|
|
26
51
|
}
|
|
27
52
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
this.
|
|
54
|
-
|
|
53
|
+
async setConfigData(config) {
|
|
54
|
+
await this.setDataInBulk(this._resolveKey("config_data" /* ConfigData */), config);
|
|
55
|
+
}
|
|
56
|
+
async setOIDCProviderMetaData(oidcProviderMetaData) {
|
|
57
|
+
this.setDataInBulk(this._resolveKey("oidc_provider_meta_data" /* OIDCProviderMetaData */), oidcProviderMetaData);
|
|
58
|
+
}
|
|
59
|
+
async setTemporaryData(temporaryData, userId) {
|
|
60
|
+
this.setDataInBulk(this._resolveKey("temporary_data" /* TemporaryData */, userId), temporaryData);
|
|
61
|
+
}
|
|
62
|
+
async setSessionData(sessionData, userId) {
|
|
63
|
+
this.setDataInBulk(this._resolveKey("session_data" /* SessionData */, userId), sessionData);
|
|
64
|
+
}
|
|
65
|
+
async setCustomData(key, customData, userId) {
|
|
66
|
+
this.setDataInBulk(this._resolveKey(key, userId), customData);
|
|
67
|
+
}
|
|
68
|
+
async getConfigData() {
|
|
69
|
+
return JSON.parse(await this._store.getData(this._resolveKey("config_data" /* ConfigData */)) ?? null);
|
|
70
|
+
}
|
|
71
|
+
async loadOpenIDProviderConfiguration() {
|
|
72
|
+
return JSON.parse(await this._store.getData(this._resolveKey("oidc_provider_meta_data" /* OIDCProviderMetaData */)) ?? null);
|
|
73
|
+
}
|
|
74
|
+
async getTemporaryData(userId) {
|
|
75
|
+
return JSON.parse(await this._store.getData(this._resolveKey("temporary_data" /* TemporaryData */, userId)) ?? null);
|
|
76
|
+
}
|
|
77
|
+
async getSessionData(userId) {
|
|
78
|
+
return JSON.parse(await this._store.getData(this._resolveKey("session_data" /* SessionData */, userId)) ?? null);
|
|
79
|
+
}
|
|
80
|
+
async getCustomData(key, userId) {
|
|
81
|
+
return JSON.parse(await this._store.getData(this._resolveKey(key, userId)) ?? null);
|
|
82
|
+
}
|
|
83
|
+
setSessionStatus(status) {
|
|
84
|
+
this.isLocalStorageAvailable() && localStorage.setItem(`${ASGARDEO_SESSION_ACTIVE}`, status);
|
|
85
|
+
}
|
|
86
|
+
getSessionStatus() {
|
|
87
|
+
return this.isLocalStorageAvailable() ? localStorage.getItem(`${ASGARDEO_SESSION_ACTIVE}`) ?? "" : "";
|
|
88
|
+
}
|
|
89
|
+
removeSessionStatus() {
|
|
90
|
+
this.isLocalStorageAvailable() && localStorage.removeItem(`${ASGARDEO_SESSION_ACTIVE}`);
|
|
91
|
+
}
|
|
92
|
+
async removeConfigData() {
|
|
93
|
+
await this._store.removeData(this._resolveKey("config_data" /* ConfigData */));
|
|
94
|
+
}
|
|
95
|
+
async removeOIDCProviderMetaData() {
|
|
96
|
+
await this._store.removeData(this._resolveKey("oidc_provider_meta_data" /* OIDCProviderMetaData */));
|
|
97
|
+
}
|
|
98
|
+
async removeTemporaryData(userId) {
|
|
99
|
+
await this._store.removeData(this._resolveKey("temporary_data" /* TemporaryData */, userId));
|
|
100
|
+
}
|
|
101
|
+
async removeSessionData(userId) {
|
|
102
|
+
await this._store.removeData(this._resolveKey("session_data" /* SessionData */, userId));
|
|
103
|
+
}
|
|
104
|
+
async getConfigDataParameter(key) {
|
|
105
|
+
const data = await this._store.getData(this._resolveKey("config_data" /* ConfigData */));
|
|
106
|
+
return data && JSON.parse(data)[key];
|
|
107
|
+
}
|
|
108
|
+
async getOIDCProviderMetaDataParameter(key) {
|
|
109
|
+
const data = await this._store.getData(this._resolveKey("oidc_provider_meta_data" /* OIDCProviderMetaData */));
|
|
110
|
+
return data && JSON.parse(data)[key];
|
|
111
|
+
}
|
|
112
|
+
async getTemporaryDataParameter(key, userId) {
|
|
113
|
+
const data = await this._store.getData(this._resolveKey("temporary_data" /* TemporaryData */, userId));
|
|
114
|
+
return data && JSON.parse(data)[key];
|
|
115
|
+
}
|
|
116
|
+
async getSessionDataParameter(key, userId) {
|
|
117
|
+
const data = await this._store.getData(this._resolveKey("session_data" /* SessionData */, userId));
|
|
118
|
+
return data && JSON.parse(data)[key];
|
|
119
|
+
}
|
|
120
|
+
async setConfigDataParameter(key, value) {
|
|
121
|
+
await this.setValue(this._resolveKey("config_data" /* ConfigData */), key, value);
|
|
122
|
+
}
|
|
123
|
+
async setOIDCProviderMetaDataParameter(key, value) {
|
|
124
|
+
await this.setValue(this._resolveKey("oidc_provider_meta_data" /* OIDCProviderMetaData */), key, value);
|
|
125
|
+
}
|
|
126
|
+
async setTemporaryDataParameter(key, value, userId) {
|
|
127
|
+
await this.setValue(this._resolveKey("temporary_data" /* TemporaryData */, userId), key, value);
|
|
128
|
+
}
|
|
129
|
+
async setSessionDataParameter(key, value, userId) {
|
|
130
|
+
await this.setValue(this._resolveKey("session_data" /* SessionData */, userId), key, value);
|
|
131
|
+
}
|
|
132
|
+
async removeConfigDataParameter(key) {
|
|
133
|
+
await this.removeValue(this._resolveKey("config_data" /* ConfigData */), key);
|
|
134
|
+
}
|
|
135
|
+
async removeOIDCProviderMetaDataParameter(key) {
|
|
136
|
+
await this.removeValue(this._resolveKey("oidc_provider_meta_data" /* OIDCProviderMetaData */), key);
|
|
137
|
+
}
|
|
138
|
+
async removeTemporaryDataParameter(key, userId) {
|
|
139
|
+
await this.removeValue(this._resolveKey("temporary_data" /* TemporaryData */, userId), key);
|
|
140
|
+
}
|
|
141
|
+
async removeSessionDataParameter(key, userId) {
|
|
142
|
+
await this.removeValue(this._resolveKey("session_data" /* SessionData */, userId), key);
|
|
55
143
|
}
|
|
56
144
|
};
|
|
57
|
-
|
|
58
|
-
// src/utils/extractTenantDomainFromIdTokenPayload.ts
|
|
59
|
-
var extractTenantDomainFromIdTokenPayload = (payload, subjectSeparator = "@") => {
|
|
60
|
-
const uid = payload.sub;
|
|
61
|
-
if (!uid) return "";
|
|
62
|
-
const tokens = uid.split(subjectSeparator);
|
|
63
|
-
return tokens.length > 2 ? tokens[tokens.length - 1] : "";
|
|
64
|
-
};
|
|
65
|
-
var extractTenantDomainFromIdTokenPayload_default = extractTenantDomainFromIdTokenPayload;
|
|
66
|
-
|
|
67
|
-
// src/utils/extractUserClaimsFromIdToken.ts
|
|
68
|
-
var extractUserClaimsFromIdToken = (payload) => {
|
|
69
|
-
const filteredPayload = { ...payload };
|
|
70
|
-
const protocolClaims = [
|
|
71
|
-
"iss",
|
|
72
|
-
"aud",
|
|
73
|
-
"exp",
|
|
74
|
-
"iat",
|
|
75
|
-
"acr",
|
|
76
|
-
"amr",
|
|
77
|
-
"azp",
|
|
78
|
-
"auth_time",
|
|
79
|
-
"nonce",
|
|
80
|
-
"c_hash",
|
|
81
|
-
"at_hash",
|
|
82
|
-
"nbf",
|
|
83
|
-
"isk",
|
|
84
|
-
"sid",
|
|
85
|
-
"jti",
|
|
86
|
-
"sub"
|
|
87
|
-
];
|
|
88
|
-
protocolClaims.forEach((claim) => {
|
|
89
|
-
delete filteredPayload[claim];
|
|
90
|
-
});
|
|
91
|
-
const userClaims = {};
|
|
92
|
-
Object.entries(filteredPayload).forEach(([key, value]) => {
|
|
93
|
-
const camelCasedKey = key.split("_").map((part, i) => i === 0 ? part : part[0].toUpperCase() + part.slice(1)).join("");
|
|
94
|
-
userClaims[camelCasedKey] = value;
|
|
95
|
-
});
|
|
96
|
-
return userClaims;
|
|
97
|
-
};
|
|
98
|
-
var extractUserClaimsFromIdToken_default = extractUserClaimsFromIdToken;
|
|
99
|
-
|
|
100
|
-
// src/constants/ScopeConstants.ts
|
|
101
|
-
var ScopeConstants = {
|
|
102
|
-
/**
|
|
103
|
-
* The base OpenID Connect scope.
|
|
104
|
-
* Required for all OpenID Connect flows. Indicates that the client
|
|
105
|
-
* is initiating an OpenID Connect authentication request.
|
|
106
|
-
*/
|
|
107
|
-
OPENID: "openid"
|
|
108
|
-
};
|
|
109
|
-
var ScopeConstants_default = ScopeConstants;
|
|
145
|
+
var StorageManager_default = StorageManager;
|
|
110
146
|
|
|
111
147
|
// src/constants/OIDCDiscoveryConstants.ts
|
|
112
148
|
var OIDCDiscoveryConstants = {
|
|
@@ -227,279 +263,53 @@ var OIDCDiscoveryConstants = {
|
|
|
227
263
|
};
|
|
228
264
|
var OIDCDiscoveryConstants_default = OIDCDiscoveryConstants;
|
|
229
265
|
|
|
230
|
-
// src/constants/
|
|
231
|
-
var
|
|
266
|
+
// src/constants/ScopeConstants.ts
|
|
267
|
+
var ScopeConstants = {
|
|
232
268
|
/**
|
|
233
|
-
*
|
|
234
|
-
*
|
|
235
|
-
*
|
|
269
|
+
* The base OpenID Connect scope.
|
|
270
|
+
* Required for all OpenID Connect flows. Indicates that the client
|
|
271
|
+
* is initiating an OpenID Connect authentication request.
|
|
236
272
|
*/
|
|
237
|
-
|
|
273
|
+
OPENID: "openid"
|
|
274
|
+
};
|
|
275
|
+
var ScopeConstants_default = ScopeConstants;
|
|
276
|
+
|
|
277
|
+
// src/constants/OIDCRequestConstants.ts
|
|
278
|
+
var OIDCRequestConstants = {
|
|
279
|
+
Params: {
|
|
238
280
|
/**
|
|
239
|
-
*
|
|
240
|
-
*
|
|
281
|
+
* The authorization code returned from the authorization endpoint.
|
|
282
|
+
* Used in the authorization code flow.
|
|
241
283
|
*/
|
|
242
|
-
|
|
284
|
+
AUTHORIZATION_CODE: "code",
|
|
243
285
|
/**
|
|
244
|
-
*
|
|
245
|
-
* Used when user identity needs to be included in the exchange.
|
|
286
|
+
* Session state parameter used for session management between the client and the OP.
|
|
246
287
|
*/
|
|
247
|
-
|
|
288
|
+
SESSION_STATE: "session_state",
|
|
248
289
|
/**
|
|
249
|
-
*
|
|
250
|
-
*
|
|
290
|
+
* State parameter used to maintain state between the request and the callback.
|
|
291
|
+
* Helps in preventing CSRF attacks.
|
|
251
292
|
*/
|
|
252
|
-
|
|
293
|
+
STATE: "state",
|
|
253
294
|
/**
|
|
254
|
-
*
|
|
255
|
-
*
|
|
295
|
+
* Indicates whether sign-out was successful during the end-session flow.
|
|
296
|
+
* May be returned by the OP after a logout request.
|
|
256
297
|
*/
|
|
257
|
-
|
|
298
|
+
SIGN_OUT_SUCCESS: "sign_out_success"
|
|
299
|
+
},
|
|
300
|
+
/**
|
|
301
|
+
* Constants related to the OpenID Connect (OIDC) sign-in flow.
|
|
302
|
+
*/
|
|
303
|
+
SignIn: {
|
|
258
304
|
/**
|
|
259
|
-
*
|
|
260
|
-
* Used for client authentication in confidential client flows.
|
|
305
|
+
* Constants related to the payload of the OIDC sign-in request.
|
|
261
306
|
*/
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
// src/__legacy__/helpers/authentication-helper.ts
|
|
268
|
-
var AuthenticationHelper = class {
|
|
269
|
-
constructor(dataLayer, cryptoHelper) {
|
|
270
|
-
__publicField(this, "_dataLayer");
|
|
271
|
-
__publicField(this, "_config");
|
|
272
|
-
__publicField(this, "_oidcProviderMetaData");
|
|
273
|
-
__publicField(this, "_cryptoHelper");
|
|
274
|
-
this._dataLayer = dataLayer;
|
|
275
|
-
this._config = async () => await this._dataLayer.getConfigData();
|
|
276
|
-
this._oidcProviderMetaData = async () => await this._dataLayer.getOIDCProviderMetaData();
|
|
277
|
-
this._cryptoHelper = cryptoHelper;
|
|
278
|
-
}
|
|
279
|
-
async resolveEndpoints(response) {
|
|
280
|
-
const oidcProviderMetaData = {};
|
|
281
|
-
const configData = await this._config();
|
|
282
|
-
configData.endpoints && Object.keys(configData.endpoints).forEach((endpointName) => {
|
|
283
|
-
const snakeCasedName = endpointName.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
|
|
284
|
-
oidcProviderMetaData[snakeCasedName] = configData?.endpoints ? configData.endpoints[endpointName] : "";
|
|
285
|
-
});
|
|
286
|
-
return { ...response, ...oidcProviderMetaData };
|
|
287
|
-
}
|
|
288
|
-
async resolveEndpointsExplicitly() {
|
|
289
|
-
const oidcProviderMetaData = {};
|
|
290
|
-
const configData = await this._config();
|
|
291
|
-
const requiredEndpoints = [
|
|
292
|
-
OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.AUTHORIZATION,
|
|
293
|
-
OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.END_SESSION,
|
|
294
|
-
OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.JWKS,
|
|
295
|
-
OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.SESSION_IFRAME,
|
|
296
|
-
OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.REVOCATION,
|
|
297
|
-
OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.TOKEN,
|
|
298
|
-
OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.ISSUER,
|
|
299
|
-
OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.USERINFO
|
|
300
|
-
];
|
|
301
|
-
const isRequiredEndpointsContains = configData.endpoints ? requiredEndpoints.every((reqEndpointName) => {
|
|
302
|
-
return configData.endpoints ? Object.keys(configData.endpoints).some((endpointName) => {
|
|
303
|
-
const snakeCasedName = endpointName.replace(
|
|
304
|
-
/[A-Z]/g,
|
|
305
|
-
(letter) => `_${letter.toLowerCase()}`
|
|
306
|
-
);
|
|
307
|
-
return snakeCasedName === reqEndpointName;
|
|
308
|
-
}) : false;
|
|
309
|
-
}) : false;
|
|
310
|
-
if (!isRequiredEndpointsContains) {
|
|
311
|
-
throw new AsgardeoAuthException(
|
|
312
|
-
"JS-AUTH_HELPER-REE-NF01",
|
|
313
|
-
"Required endpoints missing",
|
|
314
|
-
"Some or all of the required endpoints are missing in the object passed to the `endpoints` attribute of the`AuthConfig` object."
|
|
315
|
-
);
|
|
316
|
-
}
|
|
317
|
-
configData.endpoints && Object.keys(configData.endpoints).forEach((endpointName) => {
|
|
318
|
-
const snakeCasedName = endpointName.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
|
|
319
|
-
oidcProviderMetaData[snakeCasedName] = configData?.endpoints ? configData.endpoints[endpointName] : "";
|
|
320
|
-
});
|
|
321
|
-
return { ...oidcProviderMetaData };
|
|
322
|
-
}
|
|
323
|
-
async resolveEndpointsByBaseURL() {
|
|
324
|
-
const oidcProviderMetaData = {};
|
|
325
|
-
const configData = await this._config();
|
|
326
|
-
const baseUrl = configData.baseUrl;
|
|
327
|
-
if (!baseUrl) {
|
|
328
|
-
throw new AsgardeoAuthException(
|
|
329
|
-
"JS-AUTH_HELPER_REBO-NF01",
|
|
330
|
-
"Base URL not defined.",
|
|
331
|
-
"Base URL is not defined in AuthClient config."
|
|
332
|
-
);
|
|
333
|
-
}
|
|
334
|
-
configData.endpoints && Object.keys(configData.endpoints).forEach((endpointName) => {
|
|
335
|
-
const snakeCasedName = endpointName.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
|
|
336
|
-
oidcProviderMetaData[snakeCasedName] = configData?.endpoints ? configData.endpoints[endpointName] : "";
|
|
337
|
-
});
|
|
338
|
-
const defaultEndpoints = {
|
|
339
|
-
[OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.AUTHORIZATION]: `${baseUrl}${OIDCDiscoveryConstants_default.Endpoints.AUTHORIZATION}`,
|
|
340
|
-
[OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.END_SESSION]: `${baseUrl}${OIDCDiscoveryConstants_default.Endpoints.END_SESSION}`,
|
|
341
|
-
[OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.ISSUER]: `${baseUrl}${OIDCDiscoveryConstants_default.Endpoints.ISSUER}`,
|
|
342
|
-
[OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.JWKS]: `${baseUrl}${OIDCDiscoveryConstants_default.Endpoints.JWKS}`,
|
|
343
|
-
[OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.SESSION_IFRAME]: `${baseUrl}${OIDCDiscoveryConstants_default.Endpoints.SESSION_IFRAME}`,
|
|
344
|
-
[OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.REVOCATION]: `${baseUrl}${OIDCDiscoveryConstants_default.Endpoints.REVOCATION}`,
|
|
345
|
-
[OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.TOKEN]: `${baseUrl}${OIDCDiscoveryConstants_default.Endpoints.TOKEN}`,
|
|
346
|
-
[OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.USERINFO]: `${baseUrl}${OIDCDiscoveryConstants_default.Endpoints.USERINFO}`
|
|
347
|
-
};
|
|
348
|
-
return { ...defaultEndpoints, ...oidcProviderMetaData };
|
|
349
|
-
}
|
|
350
|
-
async validateIdToken(idToken) {
|
|
351
|
-
const jwksEndpoint = (await this._dataLayer.getOIDCProviderMetaData()).jwks_uri;
|
|
352
|
-
const configData = await this._config();
|
|
353
|
-
if (!jwksEndpoint || jwksEndpoint.trim().length === 0) {
|
|
354
|
-
throw new AsgardeoAuthException(
|
|
355
|
-
"JS_AUTH_HELPER-VIT-NF01",
|
|
356
|
-
"JWKS endpoint not found.",
|
|
357
|
-
"No JWKS endpoint was found in the OIDC provider meta data returned by the well-known endpoint or the JWKS endpoint passed to the SDK is empty."
|
|
358
|
-
);
|
|
359
|
-
}
|
|
360
|
-
let response;
|
|
361
|
-
try {
|
|
362
|
-
response = await fetch(jwksEndpoint, {
|
|
363
|
-
credentials: configData.sendCookiesInRequests ? "include" : "same-origin"
|
|
364
|
-
});
|
|
365
|
-
} catch (error) {
|
|
366
|
-
throw new AsgardeoAuthException(
|
|
367
|
-
"JS-AUTH_HELPER-VIT-NE02",
|
|
368
|
-
"Request to jwks endpoint failed.",
|
|
369
|
-
error ?? "The request sent to get the jwks from the server failed."
|
|
370
|
-
);
|
|
371
|
-
}
|
|
372
|
-
if (response.status !== 200 || !response.ok) {
|
|
373
|
-
throw new AsgardeoAuthException(
|
|
374
|
-
"JS-AUTH_HELPER-VIT-HE03",
|
|
375
|
-
`Invalid response status received for jwks request (${response.statusText}).`,
|
|
376
|
-
await response.json()
|
|
377
|
-
);
|
|
378
|
-
}
|
|
379
|
-
const issuer = (await this._oidcProviderMetaData()).issuer;
|
|
380
|
-
const { keys } = await response.json();
|
|
381
|
-
const jwk = await this._cryptoHelper.getJWKForTheIdToken(idToken.split(".")[0], keys);
|
|
382
|
-
return this._cryptoHelper.isValidIdToken(
|
|
383
|
-
idToken,
|
|
384
|
-
jwk,
|
|
385
|
-
(await this._config()).clientID,
|
|
386
|
-
issuer ?? "",
|
|
387
|
-
this._cryptoHelper.decodeIDToken(idToken).sub,
|
|
388
|
-
(await this._config()).clockTolerance,
|
|
389
|
-
(await this._config()).validateIDTokenIssuer ?? true
|
|
390
|
-
);
|
|
391
|
-
}
|
|
392
|
-
getAuthenticatedUserInfo(idToken) {
|
|
393
|
-
const payload = this._cryptoHelper.decodeIDToken(idToken);
|
|
394
|
-
const tenantDomain = extractTenantDomainFromIdTokenPayload_default(payload);
|
|
395
|
-
const username = payload?.["username"] ?? "";
|
|
396
|
-
const givenName = payload?.["given_name"] ?? "";
|
|
397
|
-
const familyName = payload?.["family_name"] ?? "";
|
|
398
|
-
const fullName = givenName && familyName ? `${givenName} ${familyName}` : givenName ? givenName : familyName ? familyName : "";
|
|
399
|
-
const displayName = payload.preferred_username ?? fullName;
|
|
400
|
-
return {
|
|
401
|
-
displayName,
|
|
402
|
-
tenantDomain,
|
|
403
|
-
username,
|
|
404
|
-
...extractUserClaimsFromIdToken_default(payload)
|
|
405
|
-
};
|
|
406
|
-
}
|
|
407
|
-
async replaceCustomGrantTemplateTags(text, userID) {
|
|
408
|
-
let scope = ScopeConstants_default.OPENID;
|
|
409
|
-
const configData = await this._config();
|
|
410
|
-
const sessionData = await this._dataLayer.getSessionData(userID);
|
|
411
|
-
if (configData.scope && configData.scope.length > 0) {
|
|
412
|
-
if (!configData.scope.includes(ScopeConstants_default.OPENID)) {
|
|
413
|
-
configData.scope.push(ScopeConstants_default.OPENID);
|
|
414
|
-
}
|
|
415
|
-
scope = configData.scope.join(" ");
|
|
416
|
-
}
|
|
417
|
-
return text.replace(TokenExchangeConstants_default.Placeholders.TOKEN, sessionData.access_token).replace(
|
|
418
|
-
TokenExchangeConstants_default.Placeholders.USERNAME,
|
|
419
|
-
this.getAuthenticatedUserInfo(sessionData.id_token).username
|
|
420
|
-
).replace(TokenExchangeConstants_default.Placeholders.SCOPE, scope).replace(TokenExchangeConstants_default.Placeholders.CLIENT_ID, configData.clientID).replace(TokenExchangeConstants_default.Placeholders.CLIENT_SECRET, configData.clientSecret ?? "");
|
|
421
|
-
}
|
|
422
|
-
async clearUserSessionData(userID) {
|
|
423
|
-
await this._dataLayer.removeTemporaryData(userID);
|
|
424
|
-
await this._dataLayer.removeSessionData(userID);
|
|
425
|
-
}
|
|
426
|
-
async handleTokenResponse(response, userID) {
|
|
427
|
-
if (response.status !== 200 || !response.ok) {
|
|
428
|
-
throw new AsgardeoAuthException(
|
|
429
|
-
"JS-AUTH_HELPER-HTR-NE01",
|
|
430
|
-
`Invalid response status received for token request (${response.statusText}).`,
|
|
431
|
-
await response.json()
|
|
432
|
-
);
|
|
433
|
-
}
|
|
434
|
-
const parsedResponse = await response.json();
|
|
435
|
-
parsedResponse.created_at = (/* @__PURE__ */ new Date()).getTime();
|
|
436
|
-
const shouldValidateIdToken = (await this._config()).validateIDToken;
|
|
437
|
-
if (shouldValidateIdToken) {
|
|
438
|
-
return this.validateIdToken(parsedResponse.id_token).then(async () => {
|
|
439
|
-
await this._dataLayer.setSessionData(parsedResponse, userID);
|
|
440
|
-
const tokenResponse = {
|
|
441
|
-
accessToken: parsedResponse.access_token,
|
|
442
|
-
createdAt: parsedResponse.created_at,
|
|
443
|
-
expiresIn: parsedResponse.expires_in,
|
|
444
|
-
idToken: parsedResponse.id_token,
|
|
445
|
-
refreshToken: parsedResponse.refresh_token,
|
|
446
|
-
scope: parsedResponse.scope,
|
|
447
|
-
tokenType: parsedResponse.token_type
|
|
448
|
-
};
|
|
449
|
-
return Promise.resolve(tokenResponse);
|
|
450
|
-
});
|
|
451
|
-
} else {
|
|
452
|
-
const tokenResponse = {
|
|
453
|
-
accessToken: parsedResponse.access_token,
|
|
454
|
-
createdAt: parsedResponse.created_at,
|
|
455
|
-
expiresIn: parsedResponse.expires_in,
|
|
456
|
-
idToken: parsedResponse.id_token,
|
|
457
|
-
refreshToken: parsedResponse.refresh_token,
|
|
458
|
-
scope: parsedResponse.scope,
|
|
459
|
-
tokenType: parsedResponse.token_type
|
|
460
|
-
};
|
|
461
|
-
await this._dataLayer.setSessionData(parsedResponse, userID);
|
|
462
|
-
return Promise.resolve(tokenResponse);
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
};
|
|
466
|
-
|
|
467
|
-
// src/utils/generatePkceStorageKey.ts
|
|
468
|
-
var generatePkceStorageKey = (tempStore) => {
|
|
469
|
-
const keys = [];
|
|
470
|
-
Object.keys(tempStore).forEach((key) => {
|
|
471
|
-
if (key.startsWith(PKCEConstants_default.Storage.StorageKeys.CODE_VERIFIER)) {
|
|
472
|
-
keys.push(key);
|
|
307
|
+
Payload: {
|
|
308
|
+
/**
|
|
309
|
+
* The default scopes used in OIDC sign-in requests.
|
|
310
|
+
*/
|
|
311
|
+
DEFAULT_SCOPES: [ScopeConstants_default.OPENID]
|
|
473
312
|
}
|
|
474
|
-
});
|
|
475
|
-
const lastKey = keys.sort().pop();
|
|
476
|
-
const index = parseInt(lastKey?.split(PKCEConstants_default.Storage.StorageKeys.SEPARATOR)[1] ?? "-1");
|
|
477
|
-
return `${PKCEConstants_default.Storage.StorageKeys.CODE_VERIFIER}${PKCEConstants_default.Storage.StorageKeys.SEPARATOR}${index + 1}`;
|
|
478
|
-
};
|
|
479
|
-
var generatePkceStorageKey_default = generatePkceStorageKey;
|
|
480
|
-
|
|
481
|
-
// src/constants/OIDCRequestConstants.ts
|
|
482
|
-
var OIDCRequestConstants = {
|
|
483
|
-
Params: {
|
|
484
|
-
/**
|
|
485
|
-
* The authorization code returned from the authorization endpoint.
|
|
486
|
-
* Used in the authorization code flow.
|
|
487
|
-
*/
|
|
488
|
-
AUTHORIZATION_CODE: "code",
|
|
489
|
-
/**
|
|
490
|
-
* Session state parameter used for session management between the client and the OP.
|
|
491
|
-
*/
|
|
492
|
-
SESSION_STATE: "session_state",
|
|
493
|
-
/**
|
|
494
|
-
* State parameter used to maintain state between the request and the callback.
|
|
495
|
-
* Helps in preventing CSRF attacks.
|
|
496
|
-
*/
|
|
497
|
-
STATE: "state",
|
|
498
|
-
/**
|
|
499
|
-
* Indicates whether sign-out was successful during the end-session flow.
|
|
500
|
-
* May be returned by the OP after a logout request.
|
|
501
|
-
*/
|
|
502
|
-
SIGN_OUT_SUCCESS: "sign_out_success"
|
|
503
313
|
},
|
|
504
314
|
/**
|
|
505
315
|
* Sign-out related constants for managing the end-session flow in OIDC.
|
|
@@ -525,6 +335,19 @@ var OIDCRequestConstants = {
|
|
|
525
335
|
};
|
|
526
336
|
var OIDCRequestConstants_default = OIDCRequestConstants;
|
|
527
337
|
|
|
338
|
+
// src/errors/exception.ts
|
|
339
|
+
var AsgardeoAuthException = class {
|
|
340
|
+
constructor(code, name, message) {
|
|
341
|
+
__publicField(this, "name");
|
|
342
|
+
__publicField(this, "code");
|
|
343
|
+
__publicField(this, "message");
|
|
344
|
+
this.message = message;
|
|
345
|
+
this.name = name;
|
|
346
|
+
this.code = code;
|
|
347
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
|
|
528
351
|
// src/constants/TokenConstants.ts
|
|
529
352
|
var TokenConstants = {
|
|
530
353
|
/**
|
|
@@ -620,7 +443,7 @@ var IsomorphicCrypto = class {
|
|
|
620
443
|
*
|
|
621
444
|
* @param idToken - id_token received from the IdP.
|
|
622
445
|
* @param jwk - public key used for signing.
|
|
623
|
-
* @param
|
|
446
|
+
* @param clientId - app identification.
|
|
624
447
|
* @param issuer - id_token issuer.
|
|
625
448
|
* @param username - Username.
|
|
626
449
|
* @param clockTolerance - Allowed leeway for id_tokens (in seconds).
|
|
@@ -629,12 +452,12 @@ var IsomorphicCrypto = class {
|
|
|
629
452
|
*
|
|
630
453
|
* @throws
|
|
631
454
|
*/
|
|
632
|
-
isValidIdToken(idToken, jwk,
|
|
455
|
+
isValidIdToken(idToken, jwk, clientId, issuer, username, clockTolerance, validateJwtIssuer) {
|
|
633
456
|
return this._cryptoUtils.verifyJwt(
|
|
634
457
|
idToken,
|
|
635
458
|
jwk,
|
|
636
459
|
TokenConstants_default.SignatureValidation.SUPPORTED_ALGORITHMS,
|
|
637
|
-
|
|
460
|
+
clientId,
|
|
638
461
|
issuer,
|
|
639
462
|
username,
|
|
640
463
|
clockTolerance,
|
|
@@ -661,9 +484,9 @@ var IsomorphicCrypto = class {
|
|
|
661
484
|
*
|
|
662
485
|
* @throws
|
|
663
486
|
*/
|
|
664
|
-
|
|
487
|
+
decodeIdToken(idToken) {
|
|
665
488
|
try {
|
|
666
|
-
const utf8String = this._cryptoUtils.base64URLDecode(idToken
|
|
489
|
+
const utf8String = this._cryptoUtils.base64URLDecode(idToken?.split(".")[1]);
|
|
667
490
|
const payload = JSON.parse(utf8String);
|
|
668
491
|
return payload;
|
|
669
492
|
} catch (error) {
|
|
@@ -672,644 +495,463 @@ var IsomorphicCrypto = class {
|
|
|
672
495
|
}
|
|
673
496
|
};
|
|
674
497
|
|
|
675
|
-
// src/
|
|
676
|
-
var
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
if (configData.scope && configData.scope.length > 0) {
|
|
698
|
-
if (!configData.scope.includes(ScopeConstants_default.OPENID)) {
|
|
699
|
-
configData.scope.push(ScopeConstants_default.OPENID);
|
|
700
|
-
}
|
|
701
|
-
scope = configData.scope.join(" ");
|
|
702
|
-
}
|
|
703
|
-
authorizeRequestParams.set("scope", scope);
|
|
704
|
-
authorizeRequestParams.set("redirect_uri", configData.signInRedirectURL);
|
|
705
|
-
if (configData.responseMode) {
|
|
706
|
-
authorizeRequestParams.set("response_mode", configData.responseMode);
|
|
707
|
-
}
|
|
708
|
-
const tempStore = await this._dataLayer.getTemporaryData(userID);
|
|
709
|
-
const pkceKey = await generatePkceStorageKey_default(tempStore);
|
|
710
|
-
if (configData.enablePKCE) {
|
|
711
|
-
const codeVerifier = this._cryptoHelper?.getCodeVerifier();
|
|
712
|
-
const codeChallenge = this._cryptoHelper?.getCodeChallenge(codeVerifier);
|
|
713
|
-
await this._dataLayer.setTemporaryDataParameter(pkceKey, codeVerifier, userID);
|
|
714
|
-
authorizeRequestParams.set("code_challenge_method", "S256");
|
|
715
|
-
authorizeRequestParams.set("code_challenge", codeChallenge);
|
|
716
|
-
}
|
|
717
|
-
if (configData.prompt) {
|
|
718
|
-
authorizeRequestParams.set("prompt", configData.prompt);
|
|
719
|
-
}
|
|
720
|
-
const customParams = config;
|
|
721
|
-
if (customParams) {
|
|
722
|
-
for (const [key, value] of Object.entries(customParams)) {
|
|
723
|
-
if (key != "" && value != "" && key !== OIDCRequestConstants_default.Params.STATE) {
|
|
724
|
-
authorizeRequestParams.set(key, value.toString());
|
|
725
|
-
}
|
|
726
|
-
}
|
|
727
|
-
}
|
|
728
|
-
authorizeRequestParams.set(
|
|
729
|
-
OIDCRequestConstants_default.Params.STATE,
|
|
730
|
-
generateStateParamForRequestCorrelation_default(
|
|
731
|
-
pkceKey,
|
|
732
|
-
customParams ? customParams[OIDCRequestConstants_default.Params.STATE]?.toString() : ""
|
|
733
|
-
)
|
|
734
|
-
);
|
|
735
|
-
return authorizeRequestParams;
|
|
736
|
-
}
|
|
737
|
-
async getAuthorizationURL(config, userID) {
|
|
738
|
-
const authorizeEndpoint = await this._dataLayer.getOIDCProviderMetaDataParameter(
|
|
739
|
-
OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.AUTHORIZATION
|
|
740
|
-
);
|
|
741
|
-
if (!authorizeEndpoint || authorizeEndpoint.trim().length === 0) {
|
|
742
|
-
throw new AsgardeoAuthException(
|
|
743
|
-
"JS-AUTH_CORE-GAU-NF01",
|
|
744
|
-
"No authorization endpoint found.",
|
|
745
|
-
"No authorization endpoint was found in the OIDC provider meta data from the well-known endpoint or the authorization endpoint passed to the SDK is empty."
|
|
746
|
-
);
|
|
747
|
-
}
|
|
748
|
-
const authorizeRequest = new URL(authorizeEndpoint);
|
|
749
|
-
const authorizeRequestParams = await this.getAuthorizationURLParams(config, userID);
|
|
750
|
-
for (const [key, value] of authorizeRequestParams.entries()) {
|
|
751
|
-
authorizeRequest.searchParams.append(key, value);
|
|
498
|
+
// src/constants/PKCEConstants.ts
|
|
499
|
+
var PKCEConstants = {
|
|
500
|
+
DEFAULT_CODE_CHALLENGE_METHOD: "S256",
|
|
501
|
+
/**
|
|
502
|
+
* Storage-related constants for managing PKCE state
|
|
503
|
+
*/
|
|
504
|
+
Storage: {
|
|
505
|
+
/**
|
|
506
|
+
* Collection of storage keys used in PKCE implementation
|
|
507
|
+
*/
|
|
508
|
+
StorageKeys: {
|
|
509
|
+
/**
|
|
510
|
+
* Key used to store the PKCE code verifier in temporary storage.
|
|
511
|
+
* The code verifier is a cryptographically random string that is
|
|
512
|
+
* used to generate the code challenge.
|
|
513
|
+
*/
|
|
514
|
+
CODE_VERIFIER: "pkce_code_verifier",
|
|
515
|
+
/**
|
|
516
|
+
* Separator used in storage keys to create unique identifiers
|
|
517
|
+
* by combining different parts of the key.
|
|
518
|
+
*/
|
|
519
|
+
SEPARATOR: "#"
|
|
752
520
|
}
|
|
753
|
-
return authorizeRequest.toString();
|
|
754
521
|
}
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
}
|
|
816
|
-
|
|
522
|
+
};
|
|
523
|
+
var PKCEConstants_default = PKCEConstants;
|
|
524
|
+
|
|
525
|
+
// src/utils/extractPkceStorageKeyFromState.ts
|
|
526
|
+
var extractPkceStorageKeyFromState = (state) => {
|
|
527
|
+
const index = parseInt(state.split("request_")[1]);
|
|
528
|
+
return `${PKCEConstants_default.Storage.StorageKeys.CODE_VERIFIER}${PKCEConstants_default.Storage.StorageKeys.SEPARATOR}${index}`;
|
|
529
|
+
};
|
|
530
|
+
var extractPkceStorageKeyFromState_default = extractPkceStorageKeyFromState;
|
|
531
|
+
|
|
532
|
+
// src/utils/extractUserClaimsFromIdToken.ts
|
|
533
|
+
var extractUserClaimsFromIdToken = (payload) => {
|
|
534
|
+
const filteredPayload = { ...payload };
|
|
535
|
+
const protocolClaims = [
|
|
536
|
+
"iss",
|
|
537
|
+
"aud",
|
|
538
|
+
"exp",
|
|
539
|
+
"iat",
|
|
540
|
+
"acr",
|
|
541
|
+
"amr",
|
|
542
|
+
"azp",
|
|
543
|
+
"auth_time",
|
|
544
|
+
"nonce",
|
|
545
|
+
"c_hash",
|
|
546
|
+
"at_hash",
|
|
547
|
+
"nbf",
|
|
548
|
+
"isk",
|
|
549
|
+
"sid",
|
|
550
|
+
"jti",
|
|
551
|
+
"sub"
|
|
552
|
+
];
|
|
553
|
+
protocolClaims.forEach((claim) => {
|
|
554
|
+
delete filteredPayload[claim];
|
|
555
|
+
});
|
|
556
|
+
const userClaims = {};
|
|
557
|
+
Object.entries(filteredPayload).forEach(([key, value]) => {
|
|
558
|
+
const camelCasedKey = key.split("_").map((part, i) => i === 0 ? part : part[0].toUpperCase() + part.slice(1)).join("");
|
|
559
|
+
userClaims[camelCasedKey] = value;
|
|
560
|
+
});
|
|
561
|
+
return userClaims;
|
|
562
|
+
};
|
|
563
|
+
var extractUserClaimsFromIdToken_default = extractUserClaimsFromIdToken;
|
|
564
|
+
|
|
565
|
+
// src/constants/TokenExchangeConstants.ts
|
|
566
|
+
var TokenExchangeConstants = {
|
|
567
|
+
/**
|
|
568
|
+
* Collection of placeholder strings used in token exchange operations.
|
|
569
|
+
* These placeholders are replaced with actual values when processing
|
|
570
|
+
* token exchange requests.
|
|
571
|
+
*/
|
|
572
|
+
Placeholders: {
|
|
573
|
+
/**
|
|
574
|
+
* Placeholder for the token value in exchange requests.
|
|
575
|
+
* Usually replaced with an access token or refresh token.
|
|
576
|
+
*/
|
|
577
|
+
TOKEN: "{{token}}",
|
|
578
|
+
/**
|
|
579
|
+
* Placeholder for the username in token exchange operations.
|
|
580
|
+
* Used when user identity needs to be included in the exchange.
|
|
581
|
+
*/
|
|
582
|
+
USERNAME: "{{username}}",
|
|
583
|
+
/**
|
|
584
|
+
* Placeholder for OAuth scopes in token exchange requests.
|
|
585
|
+
* Replaced with space-separated scope strings.
|
|
586
|
+
*/
|
|
587
|
+
SCOPE: "{{scope}}",
|
|
588
|
+
/**
|
|
589
|
+
* Placeholder for client ID in token exchange operations.
|
|
590
|
+
* Required for client authentication.
|
|
591
|
+
*/
|
|
592
|
+
CLIENT_ID: "{{clientId}}",
|
|
593
|
+
/**
|
|
594
|
+
* Placeholder for client secret in token exchange operations.
|
|
595
|
+
* Used for client authentication in confidential client flows.
|
|
596
|
+
*/
|
|
597
|
+
CLIENT_SECRET: "{{clientSecret}}"
|
|
817
598
|
}
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
}
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
if (configData.clientSecret && configData.clientSecret.trim().length > 0) {
|
|
841
|
-
body.push(`client_secret=${configData.clientSecret}`);
|
|
842
|
-
}
|
|
843
|
-
let tokenResponse;
|
|
844
|
-
try {
|
|
845
|
-
tokenResponse = await fetch(tokenEndpoint, {
|
|
846
|
-
body: body.join("&"),
|
|
847
|
-
credentials: configData.sendCookiesInRequests ? "include" : "same-origin",
|
|
848
|
-
headers: {
|
|
849
|
-
Accept: "application/json",
|
|
850
|
-
"Content-Type": "application/x-www-form-urlencoded"
|
|
851
|
-
},
|
|
852
|
-
method: "POST"
|
|
853
|
-
});
|
|
854
|
-
} catch (error) {
|
|
855
|
-
throw new AsgardeoAuthException(
|
|
856
|
-
"JS-AUTH_CORE-RAT2-NR03",
|
|
857
|
-
"Refresh access token request failed.",
|
|
858
|
-
error ?? "The request to refresh the access token failed."
|
|
859
|
-
);
|
|
860
|
-
}
|
|
861
|
-
if (!tokenResponse.ok) {
|
|
862
|
-
throw new AsgardeoAuthException(
|
|
863
|
-
"JS-AUTH_CORE-RAT2-HE04",
|
|
864
|
-
`Refreshing access token failed with ${tokenResponse.statusText}`,
|
|
865
|
-
await tokenResponse.json()
|
|
866
|
-
);
|
|
599
|
+
};
|
|
600
|
+
var TokenExchangeConstants_default = TokenExchangeConstants;
|
|
601
|
+
|
|
602
|
+
// src/errors/AsgardeoError.ts
|
|
603
|
+
var AsgardeoError = class _AsgardeoError extends Error {
|
|
604
|
+
constructor(message, code, origin) {
|
|
605
|
+
const _origin = _AsgardeoError.resolveOrigin(origin);
|
|
606
|
+
const prefix = `\u{1F6E1}\uFE0F Asgardeo - ${_origin}:`;
|
|
607
|
+
const regex = new RegExp(`\u{1F6E1}\uFE0F\\s*Asgardeo\\s*-\\s*${_origin}:`, "i");
|
|
608
|
+
const sanitized = message.replace(regex, "");
|
|
609
|
+
const _message = `${prefix} ${sanitized.trim()}
|
|
610
|
+
|
|
611
|
+
(code="${code}")
|
|
612
|
+
`;
|
|
613
|
+
super(_message);
|
|
614
|
+
__publicField(this, "code");
|
|
615
|
+
__publicField(this, "origin");
|
|
616
|
+
this.name = new.target.name;
|
|
617
|
+
this.code = code;
|
|
618
|
+
this.origin = _origin;
|
|
619
|
+
if (Error.captureStackTrace) {
|
|
620
|
+
Error.captureStackTrace(this, new.target);
|
|
867
621
|
}
|
|
868
|
-
return this._authenticationHelper.handleTokenResponse(tokenResponse, userID);
|
|
869
622
|
}
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
if (!revokeTokenEndpoint || revokeTokenEndpoint.trim().length === 0) {
|
|
874
|
-
throw new AsgardeoAuthException(
|
|
875
|
-
"JS-AUTH_CORE-RAT3-NF01",
|
|
876
|
-
"No revoke access token endpoint found.",
|
|
877
|
-
"No revoke access token endpoint was found in the OIDC provider meta data returned by the well-known endpoint or the revoke access token endpoint passed to the SDK is empty."
|
|
878
|
-
);
|
|
879
|
-
}
|
|
880
|
-
const body = [];
|
|
881
|
-
body.push(`client_id=${configData.clientID}`);
|
|
882
|
-
body.push(`token=${(await this._dataLayer.getSessionData(userID)).access_token}`);
|
|
883
|
-
body.push("token_type_hint=access_token");
|
|
884
|
-
if (configData.clientSecret && configData.clientSecret.trim().length > 0) {
|
|
885
|
-
body.push(`client_secret=${configData.clientSecret}`);
|
|
886
|
-
}
|
|
887
|
-
let response;
|
|
888
|
-
try {
|
|
889
|
-
response = await fetch(revokeTokenEndpoint, {
|
|
890
|
-
body: body.join("&"),
|
|
891
|
-
credentials: configData.sendCookiesInRequests ? "include" : "same-origin",
|
|
892
|
-
headers: {
|
|
893
|
-
Accept: "application/json",
|
|
894
|
-
"Content-Type": "application/x-www-form-urlencoded"
|
|
895
|
-
},
|
|
896
|
-
method: "POST"
|
|
897
|
-
});
|
|
898
|
-
} catch (error) {
|
|
899
|
-
throw new AsgardeoAuthException(
|
|
900
|
-
"JS-AUTH_CORE-RAT3-NE02",
|
|
901
|
-
"The request to revoke access token failed.",
|
|
902
|
-
error ?? "The request sent to revoke the access token failed."
|
|
903
|
-
);
|
|
904
|
-
}
|
|
905
|
-
if (response.status !== 200 || !response.ok) {
|
|
906
|
-
throw new AsgardeoAuthException(
|
|
907
|
-
"JS-AUTH_CORE-RAT3-HE03",
|
|
908
|
-
`Invalid response status received for revoke access token request (${response.statusText}).`,
|
|
909
|
-
await response.json()
|
|
910
|
-
);
|
|
623
|
+
static resolveOrigin(origin) {
|
|
624
|
+
if (!origin) {
|
|
625
|
+
return "@asgardeo/javascript";
|
|
911
626
|
}
|
|
912
|
-
|
|
913
|
-
return Promise.resolve(response);
|
|
627
|
+
return `@asgardeo/${origin}`;
|
|
914
628
|
}
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
let tokenEndpoint;
|
|
919
|
-
if (customGrantParams.tokenEndpoint && customGrantParams.tokenEndpoint.trim().length !== 0) {
|
|
920
|
-
tokenEndpoint = customGrantParams.tokenEndpoint;
|
|
921
|
-
} else {
|
|
922
|
-
tokenEndpoint = oidcProviderMetadata.token_endpoint;
|
|
923
|
-
}
|
|
924
|
-
if (!tokenEndpoint || tokenEndpoint.trim().length === 0) {
|
|
925
|
-
throw new AsgardeoAuthException(
|
|
926
|
-
"JS-AUTH_CORE-RCG-NF01",
|
|
927
|
-
"Token endpoint not found.",
|
|
928
|
-
"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."
|
|
929
|
-
);
|
|
930
|
-
}
|
|
931
|
-
const data = await Promise.all(
|
|
932
|
-
Object.entries(customGrantParams.data).map(async ([key, value]) => {
|
|
933
|
-
const newValue = await this._authenticationHelper.replaceCustomGrantTemplateTags(
|
|
934
|
-
value,
|
|
935
|
-
userID
|
|
936
|
-
);
|
|
937
|
-
return `${key}=${newValue}`;
|
|
938
|
-
})
|
|
939
|
-
);
|
|
940
|
-
let requestHeaders = {
|
|
941
|
-
Accept: "application/json",
|
|
942
|
-
"Content-Type": "application/x-www-form-urlencoded"
|
|
943
|
-
};
|
|
944
|
-
if (customGrantParams.attachToken) {
|
|
945
|
-
requestHeaders = {
|
|
946
|
-
...requestHeaders,
|
|
947
|
-
Authorization: `Bearer ${(await this._dataLayer.getSessionData(userID)).access_token}`
|
|
948
|
-
};
|
|
949
|
-
}
|
|
950
|
-
const requestConfig = {
|
|
951
|
-
body: data.join("&"),
|
|
952
|
-
credentials: configData.sendCookiesInRequests ? "include" : "same-origin",
|
|
953
|
-
headers: new Headers(requestHeaders),
|
|
954
|
-
method: "POST"
|
|
955
|
-
};
|
|
956
|
-
let response;
|
|
957
|
-
try {
|
|
958
|
-
response = await fetch(tokenEndpoint, requestConfig);
|
|
959
|
-
} catch (error) {
|
|
960
|
-
throw new AsgardeoAuthException(
|
|
961
|
-
"JS-AUTH_CORE-RCG-NE02",
|
|
962
|
-
"The custom grant request failed.",
|
|
963
|
-
error ?? "The request sent to get the custom grant failed."
|
|
964
|
-
);
|
|
965
|
-
}
|
|
966
|
-
if (response.status !== 200 || !response.ok) {
|
|
967
|
-
throw new AsgardeoAuthException(
|
|
968
|
-
"JS-AUTH_CORE-RCG-HE03",
|
|
969
|
-
`Invalid response status received for the custom grant request. (${response.statusText})`,
|
|
970
|
-
await response.json()
|
|
971
|
-
);
|
|
972
|
-
}
|
|
973
|
-
if (customGrantParams.returnsSession) {
|
|
974
|
-
return this._authenticationHelper.handleTokenResponse(response, userID);
|
|
975
|
-
} else {
|
|
976
|
-
return Promise.resolve(await response.json());
|
|
977
|
-
}
|
|
629
|
+
toString() {
|
|
630
|
+
return `[${this.name}]
|
|
631
|
+
Message: ${this.message}`;
|
|
978
632
|
}
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
633
|
+
};
|
|
634
|
+
|
|
635
|
+
// src/errors/AsgardeoRuntimeError.ts
|
|
636
|
+
var AsgardeoRuntimeError = class extends AsgardeoError {
|
|
637
|
+
/**
|
|
638
|
+
* Creates an instance of AsgardeoRuntimeError.
|
|
639
|
+
*
|
|
640
|
+
* @param message - Human-readable description of the error
|
|
641
|
+
* @param code - A unique error code that identifies the error type
|
|
642
|
+
* @param details - Additional details about the error that might be helpful for debugging
|
|
643
|
+
* @param origin - Optional. The SDK origin (e.g. 'react', 'vue'). Defaults to generic 'Asgardeo'
|
|
644
|
+
* @constructor
|
|
645
|
+
*/
|
|
646
|
+
constructor(message, code, origin, details) {
|
|
647
|
+
super(message, code, origin);
|
|
648
|
+
this.details = details;
|
|
649
|
+
Object.defineProperty(this, "name", {
|
|
650
|
+
value: "AsgardeoRuntimeError",
|
|
651
|
+
configurable: true,
|
|
652
|
+
writable: true
|
|
992
653
|
});
|
|
993
|
-
basicUserInfo = { ...basicUserInfo, ...authenticatedUser };
|
|
994
|
-
return basicUserInfo;
|
|
995
654
|
}
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
655
|
+
/**
|
|
656
|
+
* Returns a string representation of the runtime error
|
|
657
|
+
* @returns Formatted error string with name, code, details, and message
|
|
658
|
+
*/
|
|
659
|
+
toString() {
|
|
660
|
+
const details = this.details ? `
|
|
661
|
+
Details: ${JSON.stringify(this.details, null, 2)}` : "";
|
|
662
|
+
return `[${this.name}] (code="${this.code}")${details}
|
|
663
|
+
Message: ${this.message}`;
|
|
1000
664
|
}
|
|
1001
|
-
|
|
1002
|
-
|
|
665
|
+
};
|
|
666
|
+
|
|
667
|
+
// src/utils/processOpenIDScopes.ts
|
|
668
|
+
var processOpenIDScopes = (scopes) => {
|
|
669
|
+
let processedScopes = [];
|
|
670
|
+
if (Array.isArray(scopes)) {
|
|
671
|
+
processedScopes = scopes;
|
|
672
|
+
} else if (typeof scopes === "string") {
|
|
673
|
+
processedScopes = scopes.split(" ");
|
|
674
|
+
} else {
|
|
675
|
+
throw new AsgardeoRuntimeError(
|
|
676
|
+
"Scopes must be a string or an array of strings.",
|
|
677
|
+
"processOpenIDScopes-Invalid-001",
|
|
678
|
+
"javascript",
|
|
679
|
+
"The provided scopes are not in the expected format. Please provide a string or an array of strings."
|
|
680
|
+
);
|
|
1003
681
|
}
|
|
1004
|
-
|
|
1005
|
-
|
|
682
|
+
OIDCRequestConstants_default.SignIn.Payload.DEFAULT_SCOPES.forEach((defaultScope) => {
|
|
683
|
+
if (!processedScopes.includes(defaultScope)) {
|
|
684
|
+
processedScopes.push(defaultScope);
|
|
685
|
+
}
|
|
686
|
+
});
|
|
687
|
+
return processedScopes.join(" ");
|
|
688
|
+
};
|
|
689
|
+
var processOpenIDScopes_default = processOpenIDScopes;
|
|
690
|
+
|
|
691
|
+
// src/__legacy__/helpers/authentication-helper.ts
|
|
692
|
+
var AuthenticationHelper = class {
|
|
693
|
+
constructor(storageManager, cryptoHelper) {
|
|
694
|
+
__publicField(this, "_storageManager");
|
|
695
|
+
__publicField(this, "_config");
|
|
696
|
+
__publicField(this, "_oidcProviderMetaData");
|
|
697
|
+
__publicField(this, "_cryptoHelper");
|
|
698
|
+
this._storageManager = storageManager;
|
|
699
|
+
this._config = async () => await this._storageManager.getConfigData();
|
|
700
|
+
this._oidcProviderMetaData = async () => await this._storageManager.loadOpenIDProviderConfiguration();
|
|
701
|
+
this._cryptoHelper = cryptoHelper;
|
|
1006
702
|
}
|
|
1007
|
-
async
|
|
703
|
+
async resolveEndpoints(response) {
|
|
704
|
+
const oidcProviderMetaData = {};
|
|
1008
705
|
const configData = await this._config();
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
}
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
OIDCDiscoveryConstants_default.Storage.StorageKeys.OPENID_PROVIDER_CONFIG_INITIATED,
|
|
1034
|
-
true
|
|
1035
|
-
);
|
|
1036
|
-
return Promise.resolve();
|
|
1037
|
-
} else if (configData.baseUrl) {
|
|
1038
|
-
try {
|
|
1039
|
-
await this._dataLayer.setOIDCProviderMetaData(await this._authenticationHelper.resolveEndpointsByBaseURL());
|
|
1040
|
-
} catch (error) {
|
|
1041
|
-
throw new AsgardeoAuthException(
|
|
1042
|
-
"JS-AUTH_CORE-GOPMD-IV02",
|
|
1043
|
-
"Resolving endpoints failed.",
|
|
1044
|
-
error ?? "Resolving endpoints by base url failed."
|
|
706
|
+
configData.endpoints && Object.keys(configData.endpoints).forEach((endpointName) => {
|
|
707
|
+
const snakeCasedName = endpointName.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
|
|
708
|
+
oidcProviderMetaData[snakeCasedName] = configData?.endpoints ? configData.endpoints[endpointName] : "";
|
|
709
|
+
});
|
|
710
|
+
return { ...response, ...oidcProviderMetaData };
|
|
711
|
+
}
|
|
712
|
+
async resolveEndpointsExplicitly() {
|
|
713
|
+
const oidcProviderMetaData = {};
|
|
714
|
+
const configData = await this._config();
|
|
715
|
+
const requiredEndpoints = [
|
|
716
|
+
OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.AUTHORIZATION,
|
|
717
|
+
OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.END_SESSION,
|
|
718
|
+
OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.JWKS,
|
|
719
|
+
OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.SESSION_IFRAME,
|
|
720
|
+
OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.REVOCATION,
|
|
721
|
+
OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.TOKEN,
|
|
722
|
+
OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.ISSUER,
|
|
723
|
+
OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.USERINFO
|
|
724
|
+
];
|
|
725
|
+
const isRequiredEndpointsContains = configData.endpoints ? requiredEndpoints.every((reqEndpointName) => {
|
|
726
|
+
return configData.endpoints ? Object.keys(configData.endpoints).some((endpointName) => {
|
|
727
|
+
const snakeCasedName = endpointName.replace(
|
|
728
|
+
/[A-Z]/g,
|
|
729
|
+
(letter) => `_${letter.toLowerCase()}`
|
|
1045
730
|
);
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
await this._dataLayer.setTemporaryDataParameter(
|
|
1055
|
-
OIDCDiscoveryConstants_default.Storage.StorageKeys.OPENID_PROVIDER_CONFIG_INITIATED,
|
|
1056
|
-
true
|
|
731
|
+
return snakeCasedName === reqEndpointName;
|
|
732
|
+
}) : false;
|
|
733
|
+
}) : false;
|
|
734
|
+
if (!isRequiredEndpointsContains) {
|
|
735
|
+
throw new AsgardeoAuthException(
|
|
736
|
+
"JS-AUTH_HELPER-REE-NF01",
|
|
737
|
+
"Required endpoints missing",
|
|
738
|
+
"Some or all of the required endpoints are missing in the object passed to the `endpoints` attribute of the`AuthConfig` object."
|
|
1057
739
|
);
|
|
1058
|
-
return Promise.resolve();
|
|
1059
740
|
}
|
|
741
|
+
configData.endpoints && Object.keys(configData.endpoints).forEach((endpointName) => {
|
|
742
|
+
const snakeCasedName = endpointName.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
|
|
743
|
+
oidcProviderMetaData[snakeCasedName] = configData?.endpoints ? configData.endpoints[endpointName] : "";
|
|
744
|
+
});
|
|
745
|
+
return { ...oidcProviderMetaData };
|
|
1060
746
|
}
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
const
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
747
|
+
async resolveEndpointsByBaseURL() {
|
|
748
|
+
const oidcProviderMetaData = {};
|
|
749
|
+
const configData = await this._config();
|
|
750
|
+
const baseUrl = configData.baseUrl;
|
|
751
|
+
if (!baseUrl) {
|
|
752
|
+
throw new AsgardeoAuthException(
|
|
753
|
+
"JS-AUTH_HELPER_REBO-NF01",
|
|
754
|
+
"Base URL not defined.",
|
|
755
|
+
"Base URL is not defined in AuthClient config."
|
|
756
|
+
);
|
|
757
|
+
}
|
|
758
|
+
configData.endpoints && Object.keys(configData.endpoints).forEach((endpointName) => {
|
|
759
|
+
const snakeCasedName = endpointName.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
|
|
760
|
+
oidcProviderMetaData[snakeCasedName] = configData?.endpoints ? configData.endpoints[endpointName] : "";
|
|
761
|
+
});
|
|
762
|
+
const defaultEndpoints = {
|
|
763
|
+
[OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.AUTHORIZATION]: `${baseUrl}${OIDCDiscoveryConstants_default.Endpoints.AUTHORIZATION}`,
|
|
764
|
+
[OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.END_SESSION]: `${baseUrl}${OIDCDiscoveryConstants_default.Endpoints.END_SESSION}`,
|
|
765
|
+
[OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.ISSUER]: `${baseUrl}${OIDCDiscoveryConstants_default.Endpoints.ISSUER}`,
|
|
766
|
+
[OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.JWKS]: `${baseUrl}${OIDCDiscoveryConstants_default.Endpoints.JWKS}`,
|
|
767
|
+
[OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.SESSION_IFRAME]: `${baseUrl}${OIDCDiscoveryConstants_default.Endpoints.SESSION_IFRAME}`,
|
|
768
|
+
[OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.REVOCATION]: `${baseUrl}${OIDCDiscoveryConstants_default.Endpoints.REVOCATION}`,
|
|
769
|
+
[OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.TOKEN]: `${baseUrl}${OIDCDiscoveryConstants_default.Endpoints.TOKEN}`,
|
|
770
|
+
[OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.USERINFO]: `${baseUrl}${OIDCDiscoveryConstants_default.Endpoints.USERINFO}`
|
|
1075
771
|
};
|
|
772
|
+
return { ...defaultEndpoints, ...oidcProviderMetaData };
|
|
1076
773
|
}
|
|
1077
|
-
async
|
|
1078
|
-
const
|
|
774
|
+
async validateIdToken(idToken) {
|
|
775
|
+
const jwksEndpoint = (await this._storageManager.loadOpenIDProviderConfiguration()).jwks_uri;
|
|
1079
776
|
const configData = await this._config();
|
|
1080
|
-
if (!
|
|
777
|
+
if (!jwksEndpoint || jwksEndpoint.trim().length === 0) {
|
|
1081
778
|
throw new AsgardeoAuthException(
|
|
1082
|
-
"
|
|
1083
|
-
"
|
|
1084
|
-
"No
|
|
779
|
+
"JS_AUTH_HELPER-VIT-NF01",
|
|
780
|
+
"JWKS endpoint not found.",
|
|
781
|
+
"No JWKS endpoint was found in the OIDC provider meta data returned by the well-known endpoint or the JWKS endpoint passed to the SDK is empty."
|
|
1085
782
|
);
|
|
1086
783
|
}
|
|
1087
|
-
|
|
1088
|
-
|
|
784
|
+
let response;
|
|
785
|
+
try {
|
|
786
|
+
response = await fetch(jwksEndpoint, {
|
|
787
|
+
credentials: configData.sendCookiesInRequests ? "include" : "same-origin"
|
|
788
|
+
});
|
|
789
|
+
} catch (error) {
|
|
1089
790
|
throw new AsgardeoAuthException(
|
|
1090
|
-
"JS-
|
|
1091
|
-
"
|
|
1092
|
-
"The
|
|
791
|
+
"JS-AUTH_HELPER-VIT-NE02",
|
|
792
|
+
"Request to jwks endpoint failed.",
|
|
793
|
+
error ?? "The request sent to get the jwks from the server failed."
|
|
1093
794
|
);
|
|
1094
795
|
}
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
"JS-AUTH_CORE-GSOU-NF02",
|
|
1102
|
-
"ID token not found.",
|
|
1103
|
-
"No ID token could be found. Either the session information is lost or you have not signed in."
|
|
1104
|
-
);
|
|
1105
|
-
}
|
|
1106
|
-
queryParams.set("id_token_hint", idToken);
|
|
1107
|
-
} else {
|
|
1108
|
-
queryParams.set("client_id", configData.clientID);
|
|
1109
|
-
}
|
|
1110
|
-
queryParams.set("state", OIDCRequestConstants_default.Params.SIGN_OUT_SUCCESS);
|
|
1111
|
-
return `${logoutEndpoint}?${queryParams.toString()}`;
|
|
1112
|
-
}
|
|
1113
|
-
async clearUserSessionData(userID) {
|
|
1114
|
-
await this._authenticationHelper.clearUserSessionData(userID);
|
|
1115
|
-
}
|
|
1116
|
-
async getAccessToken(userID) {
|
|
1117
|
-
return (await this._dataLayer.getSessionData(userID))?.access_token;
|
|
1118
|
-
}
|
|
1119
|
-
/**
|
|
1120
|
-
* The created timestamp of the token response in milliseconds.
|
|
1121
|
-
*
|
|
1122
|
-
* @param userID - User ID
|
|
1123
|
-
* @returns Created at timestamp of the token response in milliseconds.
|
|
1124
|
-
*/
|
|
1125
|
-
async getCreatedAt(userID) {
|
|
1126
|
-
return (await this._dataLayer.getSessionData(userID))?.created_at;
|
|
1127
|
-
}
|
|
1128
|
-
/**
|
|
1129
|
-
* The expires timestamp of the token response in seconds.
|
|
1130
|
-
*
|
|
1131
|
-
* @param userID - User ID
|
|
1132
|
-
* @returns Expires in timestamp of the token response in seconds.
|
|
1133
|
-
*/
|
|
1134
|
-
async getExpiresIn(userID) {
|
|
1135
|
-
return (await this._dataLayer.getSessionData(userID))?.expires_in;
|
|
1136
|
-
}
|
|
1137
|
-
async isAuthenticated(userID) {
|
|
1138
|
-
const isAccessTokenAvailable = Boolean(await this.getAccessToken(userID));
|
|
1139
|
-
const createdAt = await this.getCreatedAt(userID);
|
|
1140
|
-
const expiresInString = await this.getExpiresIn(userID);
|
|
1141
|
-
if (!expiresInString) {
|
|
1142
|
-
return false;
|
|
796
|
+
if (response.status !== 200 || !response.ok) {
|
|
797
|
+
throw new AsgardeoAuthException(
|
|
798
|
+
"JS-AUTH_HELPER-VIT-HE03",
|
|
799
|
+
`Invalid response status received for jwks request (${response.statusText}).`,
|
|
800
|
+
await response.json()
|
|
801
|
+
);
|
|
1143
802
|
}
|
|
1144
|
-
const
|
|
1145
|
-
const
|
|
1146
|
-
const
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
async updateConfig(config) {
|
|
1157
|
-
await this._dataLayer.setConfigData(config);
|
|
1158
|
-
await this.getOIDCProviderMetaData(true);
|
|
1159
|
-
}
|
|
1160
|
-
};
|
|
1161
|
-
|
|
1162
|
-
// src/__legacy__/data/data-layer.ts
|
|
1163
|
-
var ASGARDEO_SESSION_ACTIVE = "asgardeo-session-active";
|
|
1164
|
-
var DataLayer = class {
|
|
1165
|
-
constructor(instanceID, store) {
|
|
1166
|
-
__publicField(this, "_id");
|
|
1167
|
-
__publicField(this, "_store");
|
|
1168
|
-
this._id = instanceID;
|
|
1169
|
-
this._store = store;
|
|
1170
|
-
}
|
|
1171
|
-
async setDataInBulk(key, data) {
|
|
1172
|
-
const existingDataJSON = await this._store.getData(key) ?? null;
|
|
1173
|
-
const existingData = existingDataJSON && JSON.parse(existingDataJSON);
|
|
1174
|
-
const dataToBeSaved = { ...existingData, ...data };
|
|
1175
|
-
const dataToBeSavedJSON = JSON.stringify(dataToBeSaved);
|
|
1176
|
-
await this._store.setData(key, dataToBeSavedJSON);
|
|
803
|
+
const issuer = (await this._oidcProviderMetaData()).issuer;
|
|
804
|
+
const { keys } = await response.json();
|
|
805
|
+
const jwk = await this._cryptoHelper.getJWKForTheIdToken(idToken.split(".")[0], keys);
|
|
806
|
+
return this._cryptoHelper.isValidIdToken(
|
|
807
|
+
idToken,
|
|
808
|
+
jwk,
|
|
809
|
+
(await this._config()).clientId,
|
|
810
|
+
issuer ?? "",
|
|
811
|
+
this._cryptoHelper.decodeIdToken(idToken).sub,
|
|
812
|
+
(await this._config()).clockTolerance,
|
|
813
|
+
(await this._config()).validateIDTokenIssuer ?? true
|
|
814
|
+
);
|
|
1177
815
|
}
|
|
1178
|
-
|
|
1179
|
-
const
|
|
1180
|
-
const
|
|
1181
|
-
const
|
|
1182
|
-
const
|
|
1183
|
-
|
|
816
|
+
getAuthenticatedUserInfo(idToken) {
|
|
817
|
+
const payload = this._cryptoHelper.decodeIdToken(idToken);
|
|
818
|
+
const username = payload?.["username"] ?? "";
|
|
819
|
+
const givenName = payload?.["given_name"] ?? "";
|
|
820
|
+
const familyName = payload?.["family_name"] ?? "";
|
|
821
|
+
const fullName = givenName && familyName ? `${givenName} ${familyName}` : givenName ? givenName : familyName ? familyName : "";
|
|
822
|
+
const displayName = payload.preferred_username ?? fullName;
|
|
823
|
+
return {
|
|
824
|
+
displayName,
|
|
825
|
+
username,
|
|
826
|
+
...extractUserClaimsFromIdToken_default(payload)
|
|
827
|
+
};
|
|
1184
828
|
}
|
|
1185
|
-
async
|
|
1186
|
-
const
|
|
1187
|
-
const
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
829
|
+
async replaceCustomGrantTemplateTags(text, userId) {
|
|
830
|
+
const configData = await this._config();
|
|
831
|
+
const sessionData = await this._storageManager.getSessionData(userId);
|
|
832
|
+
let scope = processOpenIDScopes_default(configData.scopes);
|
|
833
|
+
return text.replace(TokenExchangeConstants_default.Placeholders.TOKEN, sessionData.access_token).replace(
|
|
834
|
+
TokenExchangeConstants_default.Placeholders.USERNAME,
|
|
835
|
+
this.getAuthenticatedUserInfo(sessionData.id_token).username
|
|
836
|
+
).replace(TokenExchangeConstants_default.Placeholders.SCOPE, scope).replace(TokenExchangeConstants_default.Placeholders.CLIENT_ID, configData.clientId).replace(TokenExchangeConstants_default.Placeholders.CLIENT_SECRET, configData.clientSecret ?? "");
|
|
1192
837
|
}
|
|
1193
|
-
|
|
1194
|
-
|
|
838
|
+
async clearSession(userId) {
|
|
839
|
+
await this._storageManager.removeTemporaryData(userId);
|
|
840
|
+
await this._storageManager.removeSessionData(userId);
|
|
1195
841
|
}
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
842
|
+
async handleTokenResponse(response, userId) {
|
|
843
|
+
if (response.status !== 200 || !response.ok) {
|
|
844
|
+
throw new AsgardeoAuthException(
|
|
845
|
+
"JS-AUTH_HELPER-HTR-NE01",
|
|
846
|
+
`Invalid response status received for token request (${response.statusText}).`,
|
|
847
|
+
await response.json()
|
|
848
|
+
);
|
|
849
|
+
}
|
|
850
|
+
const parsedResponse = await response.json();
|
|
851
|
+
parsedResponse.created_at = (/* @__PURE__ */ new Date()).getTime();
|
|
852
|
+
const shouldValidateIdToken = (await this._config()).validateIDToken;
|
|
853
|
+
if (shouldValidateIdToken) {
|
|
854
|
+
return this.validateIdToken(parsedResponse.id_token).then(async () => {
|
|
855
|
+
await this._storageManager.setSessionData(parsedResponse, userId);
|
|
856
|
+
const tokenResponse = {
|
|
857
|
+
accessToken: parsedResponse.access_token,
|
|
858
|
+
createdAt: parsedResponse.created_at,
|
|
859
|
+
expiresIn: parsedResponse.expires_in,
|
|
860
|
+
idToken: parsedResponse.id_token,
|
|
861
|
+
refreshToken: parsedResponse.refresh_token,
|
|
862
|
+
scope: parsedResponse.scope,
|
|
863
|
+
tokenType: parsedResponse.token_type
|
|
864
|
+
};
|
|
865
|
+
return Promise.resolve(tokenResponse);
|
|
866
|
+
});
|
|
867
|
+
} else {
|
|
868
|
+
const tokenResponse = {
|
|
869
|
+
accessToken: parsedResponse.access_token,
|
|
870
|
+
createdAt: parsedResponse.created_at,
|
|
871
|
+
expiresIn: parsedResponse.expires_in,
|
|
872
|
+
idToken: parsedResponse.id_token,
|
|
873
|
+
refreshToken: parsedResponse.refresh_token,
|
|
874
|
+
scope: parsedResponse.scope,
|
|
875
|
+
tokenType: parsedResponse.token_type
|
|
876
|
+
};
|
|
877
|
+
await this._storageManager.setSessionData(parsedResponse, userId);
|
|
878
|
+
return Promise.resolve(tokenResponse);
|
|
1204
879
|
}
|
|
1205
880
|
}
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
}
|
|
1254
|
-
async removeSessionData(userID) {
|
|
1255
|
-
await this._store.removeData(this._resolveKey("session_data" /* SessionData */, userID));
|
|
1256
|
-
}
|
|
1257
|
-
async getConfigDataParameter(key) {
|
|
1258
|
-
const data = await this._store.getData(this._resolveKey("config_data" /* ConfigData */));
|
|
1259
|
-
return data && JSON.parse(data)[key];
|
|
1260
|
-
}
|
|
1261
|
-
async getOIDCProviderMetaDataParameter(key) {
|
|
1262
|
-
const data = await this._store.getData(this._resolveKey("oidc_provider_meta_data" /* OIDCProviderMetaData */));
|
|
1263
|
-
return data && JSON.parse(data)[key];
|
|
1264
|
-
}
|
|
1265
|
-
async getTemporaryDataParameter(key, userID) {
|
|
1266
|
-
const data = await this._store.getData(this._resolveKey("temporary_data" /* TemporaryData */, userID));
|
|
1267
|
-
return data && JSON.parse(data)[key];
|
|
1268
|
-
}
|
|
1269
|
-
async getSessionDataParameter(key, userID) {
|
|
1270
|
-
const data = await this._store.getData(this._resolveKey("session_data" /* SessionData */, userID));
|
|
1271
|
-
return data && JSON.parse(data)[key];
|
|
1272
|
-
}
|
|
1273
|
-
async setConfigDataParameter(key, value) {
|
|
1274
|
-
await this.setValue(this._resolveKey("config_data" /* ConfigData */), key, value);
|
|
1275
|
-
}
|
|
1276
|
-
async setOIDCProviderMetaDataParameter(key, value) {
|
|
1277
|
-
await this.setValue(this._resolveKey("oidc_provider_meta_data" /* OIDCProviderMetaData */), key, value);
|
|
1278
|
-
}
|
|
1279
|
-
async setTemporaryDataParameter(key, value, userID) {
|
|
1280
|
-
await this.setValue(this._resolveKey("temporary_data" /* TemporaryData */, userID), key, value);
|
|
1281
|
-
}
|
|
1282
|
-
async setSessionDataParameter(key, value, userID) {
|
|
1283
|
-
await this.setValue(this._resolveKey("session_data" /* SessionData */, userID), key, value);
|
|
1284
|
-
}
|
|
1285
|
-
async removeConfigDataParameter(key) {
|
|
1286
|
-
await this.removeValue(this._resolveKey("config_data" /* ConfigData */), key);
|
|
1287
|
-
}
|
|
1288
|
-
async removeOIDCProviderMetaDataParameter(key) {
|
|
1289
|
-
await this.removeValue(this._resolveKey("oidc_provider_meta_data" /* OIDCProviderMetaData */), key);
|
|
881
|
+
};
|
|
882
|
+
|
|
883
|
+
// src/utils/generatePkceStorageKey.ts
|
|
884
|
+
var generatePkceStorageKey = (tempStore) => {
|
|
885
|
+
const keys = [];
|
|
886
|
+
Object.keys(tempStore).forEach((key) => {
|
|
887
|
+
if (key.startsWith(PKCEConstants_default.Storage.StorageKeys.CODE_VERIFIER)) {
|
|
888
|
+
keys.push(key);
|
|
889
|
+
}
|
|
890
|
+
});
|
|
891
|
+
const lastKey = keys.sort().pop();
|
|
892
|
+
const index = parseInt(lastKey?.split(PKCEConstants_default.Storage.StorageKeys.SEPARATOR)[1] ?? "-1");
|
|
893
|
+
return `${PKCEConstants_default.Storage.StorageKeys.CODE_VERIFIER}${PKCEConstants_default.Storage.StorageKeys.SEPARATOR}${index + 1}`;
|
|
894
|
+
};
|
|
895
|
+
var generatePkceStorageKey_default = generatePkceStorageKey;
|
|
896
|
+
|
|
897
|
+
// src/utils/generateStateParamForRequestCorrelation.ts
|
|
898
|
+
var generateStateParamForRequestCorrelation = (pkceKey, state) => {
|
|
899
|
+
const index = parseInt(pkceKey.split(PKCEConstants_default.Storage.StorageKeys.SEPARATOR)[1]);
|
|
900
|
+
return state ? `${state}_request_${index}` : `request_${index}`;
|
|
901
|
+
};
|
|
902
|
+
var generateStateParamForRequestCorrelation_default = generateStateParamForRequestCorrelation;
|
|
903
|
+
|
|
904
|
+
// src/utils/getAuthorizeRequestUrlParams.ts
|
|
905
|
+
var getAuthorizeRequestUrlParams = (options, pkceOptions, customParams) => {
|
|
906
|
+
const { redirectUri, clientId, scopes, responseMode, codeChallenge, codeChallengeMethod, prompt } = options;
|
|
907
|
+
const authorizeRequestParams = /* @__PURE__ */ new Map();
|
|
908
|
+
authorizeRequestParams.set("response_type", "code");
|
|
909
|
+
authorizeRequestParams.set("client_id", clientId);
|
|
910
|
+
authorizeRequestParams.set("scope", scopes);
|
|
911
|
+
authorizeRequestParams.set("redirect_uri", redirectUri);
|
|
912
|
+
if (responseMode) {
|
|
913
|
+
authorizeRequestParams.set("response_mode", responseMode);
|
|
914
|
+
}
|
|
915
|
+
const pkceKey = pkceOptions?.key;
|
|
916
|
+
if (codeChallenge) {
|
|
917
|
+
authorizeRequestParams.set("code_challenge", codeChallenge);
|
|
918
|
+
if (codeChallengeMethod) {
|
|
919
|
+
authorizeRequestParams.set("code_challenge_method", codeChallengeMethod);
|
|
920
|
+
} else {
|
|
921
|
+
throw new AsgardeoRuntimeError(
|
|
922
|
+
"Code challenge method is required when code challenge is provided.",
|
|
923
|
+
"getAuthorizeRequestUrlParams-ValidationError-001",
|
|
924
|
+
"javascript",
|
|
925
|
+
"When PKCE is enabled, the code challenge method must be provided along with the code challenge."
|
|
926
|
+
);
|
|
927
|
+
}
|
|
1290
928
|
}
|
|
1291
|
-
|
|
1292
|
-
|
|
929
|
+
if (prompt) {
|
|
930
|
+
authorizeRequestParams.set("prompt", prompt);
|
|
1293
931
|
}
|
|
1294
|
-
|
|
1295
|
-
|
|
932
|
+
if (customParams) {
|
|
933
|
+
for (const [key, value] of Object.entries(customParams)) {
|
|
934
|
+
if (key !== "" && value !== "" && key !== OIDCRequestConstants_default.Params.STATE) {
|
|
935
|
+
authorizeRequestParams.set(key, value.toString());
|
|
936
|
+
}
|
|
937
|
+
}
|
|
1296
938
|
}
|
|
939
|
+
authorizeRequestParams.set(
|
|
940
|
+
OIDCRequestConstants_default.Params.STATE,
|
|
941
|
+
generateStateParamForRequestCorrelation_default(
|
|
942
|
+
pkceKey,
|
|
943
|
+
customParams ? customParams[OIDCRequestConstants_default.Params.STATE]?.toString() : ""
|
|
944
|
+
)
|
|
945
|
+
);
|
|
946
|
+
return authorizeRequestParams;
|
|
1297
947
|
};
|
|
1298
|
-
|
|
1299
|
-
// src/models/oauth-response.ts
|
|
1300
|
-
var ResponseMode = /* @__PURE__ */ ((ResponseMode2) => {
|
|
1301
|
-
ResponseMode2["FormPost"] = "form_post";
|
|
1302
|
-
ResponseMode2["Query"] = "query";
|
|
1303
|
-
ResponseMode2["Direct"] = "direct";
|
|
1304
|
-
return ResponseMode2;
|
|
1305
|
-
})(ResponseMode || {});
|
|
948
|
+
var getAuthorizeRequestUrlParams_default = getAuthorizeRequestUrlParams;
|
|
1306
949
|
|
|
1307
950
|
// src/__legacy__/client.ts
|
|
1308
951
|
var DefaultConfig = {
|
|
1309
952
|
clockTolerance: 300,
|
|
1310
953
|
enablePKCE: true,
|
|
1311
|
-
responseMode: "query"
|
|
1312
|
-
scope: [ScopeConstants_default.OPENID],
|
|
954
|
+
responseMode: "query",
|
|
1313
955
|
sendCookiesInRequests: true,
|
|
1314
956
|
validateIDToken: true,
|
|
1315
957
|
validateIDTokenIssuer: true
|
|
@@ -1331,8 +973,12 @@ var _AsgardeoAuthClient = class _AsgardeoAuthClient {
|
|
|
1331
973
|
* @preserve
|
|
1332
974
|
*/
|
|
1333
975
|
constructor() {
|
|
1334
|
-
__publicField(this, "
|
|
1335
|
-
__publicField(this, "
|
|
976
|
+
__publicField(this, "_storageManager");
|
|
977
|
+
__publicField(this, "_config");
|
|
978
|
+
__publicField(this, "_oidcProviderMetaData");
|
|
979
|
+
__publicField(this, "_authenticationHelper");
|
|
980
|
+
__publicField(this, "_cryptoUtils");
|
|
981
|
+
__publicField(this, "_cryptoHelper");
|
|
1336
982
|
}
|
|
1337
983
|
/**
|
|
1338
984
|
*
|
|
@@ -1342,8 +988,8 @@ var _AsgardeoAuthClient = class _AsgardeoAuthClient {
|
|
|
1342
988
|
*
|
|
1343
989
|
* @example
|
|
1344
990
|
* const config = \{
|
|
1345
|
-
*
|
|
1346
|
-
*
|
|
991
|
+
* afterSignInUrl: "http://localhost:3000/sign-in",
|
|
992
|
+
* clientId: "client ID",
|
|
1347
993
|
* baseUrl: "https://localhost:9443"
|
|
1348
994
|
* \}
|
|
1349
995
|
*
|
|
@@ -1354,7 +1000,7 @@ var _AsgardeoAuthClient = class _AsgardeoAuthClient {
|
|
|
1354
1000
|
* @preserve
|
|
1355
1001
|
*/
|
|
1356
1002
|
async initialize(config, store, cryptoUtils, instanceID) {
|
|
1357
|
-
const clientId = config.
|
|
1003
|
+
const clientId = config.clientId;
|
|
1358
1004
|
if (!_AsgardeoAuthClient._instanceID) {
|
|
1359
1005
|
_AsgardeoAuthClient._instanceID = 0;
|
|
1360
1006
|
} else {
|
|
@@ -1364,37 +1010,38 @@ var _AsgardeoAuthClient = class _AsgardeoAuthClient {
|
|
|
1364
1010
|
_AsgardeoAuthClient._instanceID = instanceID;
|
|
1365
1011
|
}
|
|
1366
1012
|
if (!clientId) {
|
|
1367
|
-
this.
|
|
1013
|
+
this._storageManager = new StorageManager_default(`instance_${_AsgardeoAuthClient._instanceID}`, store);
|
|
1368
1014
|
} else {
|
|
1369
|
-
this.
|
|
1015
|
+
this._storageManager = new StorageManager_default(`instance_${_AsgardeoAuthClient._instanceID}-${clientId}`, store);
|
|
1370
1016
|
}
|
|
1371
|
-
this.
|
|
1372
|
-
|
|
1373
|
-
|
|
1017
|
+
this._cryptoUtils = cryptoUtils;
|
|
1018
|
+
this._cryptoHelper = new IsomorphicCrypto(cryptoUtils);
|
|
1019
|
+
this._authenticationHelper = new AuthenticationHelper(this._storageManager, this._cryptoHelper);
|
|
1020
|
+
this._config = async () => await this._storageManager.getConfigData();
|
|
1021
|
+
this._oidcProviderMetaData = async () => await this._storageManager.loadOpenIDProviderConfiguration();
|
|
1022
|
+
_AsgardeoAuthClient._authenticationHelper = this._authenticationHelper;
|
|
1023
|
+
await this._storageManager.setConfigData({
|
|
1374
1024
|
...DefaultConfig,
|
|
1375
1025
|
...config,
|
|
1376
|
-
scope:
|
|
1377
|
-
...DefaultConfig.scope ?? [],
|
|
1378
|
-
...config.scope?.filter((scope) => !DefaultConfig?.scope?.includes(scope)) ?? []
|
|
1379
|
-
]
|
|
1026
|
+
scope: processOpenIDScopes_default(config.scopes)
|
|
1380
1027
|
});
|
|
1381
1028
|
}
|
|
1382
1029
|
/**
|
|
1383
|
-
* This method returns the `
|
|
1030
|
+
* This method returns the `StorageManager` object that allows you to access authentication data.
|
|
1384
1031
|
*
|
|
1385
|
-
* @returns - The `
|
|
1032
|
+
* @returns - The `StorageManager` object.
|
|
1386
1033
|
*
|
|
1387
1034
|
* @example
|
|
1388
1035
|
* ```
|
|
1389
|
-
* const data = auth.
|
|
1036
|
+
* const data = auth.getStorageManager();
|
|
1390
1037
|
* ```
|
|
1391
1038
|
*
|
|
1392
|
-
* {@link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#
|
|
1039
|
+
* {@link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getStorageManager}
|
|
1393
1040
|
*
|
|
1394
1041
|
* @preserve
|
|
1395
1042
|
*/
|
|
1396
|
-
|
|
1397
|
-
return this.
|
|
1043
|
+
getStorageManager() {
|
|
1044
|
+
return this._storageManager;
|
|
1398
1045
|
}
|
|
1399
1046
|
/**
|
|
1400
1047
|
* This method returns the `instanceID` variable of the given instance.
|
|
@@ -1403,82 +1050,87 @@ var _AsgardeoAuthClient = class _AsgardeoAuthClient {
|
|
|
1403
1050
|
*
|
|
1404
1051
|
* @example
|
|
1405
1052
|
* ```
|
|
1406
|
-
* const instanceId = auth.
|
|
1053
|
+
* const instanceId = auth.getInstanceId();
|
|
1407
1054
|
* ```
|
|
1408
1055
|
*
|
|
1409
1056
|
* @preserve
|
|
1410
1057
|
*/
|
|
1411
|
-
|
|
1058
|
+
getInstanceId() {
|
|
1412
1059
|
return _AsgardeoAuthClient._instanceID;
|
|
1413
1060
|
}
|
|
1414
|
-
/**
|
|
1415
|
-
* This is an async method that returns a Promise that resolves with the authorization URL parameters.
|
|
1416
|
-
*
|
|
1417
|
-
* @param config - (Optional) A config object to force initialization and pass
|
|
1418
|
-
* custom path parameters such as the `fidp` parameter.
|
|
1419
|
-
* @param userID - (Optional) A unique ID of the user to be authenticated. This is useful in multi-user
|
|
1420
|
-
* scenarios where each user should be uniquely identified.
|
|
1421
|
-
*
|
|
1422
|
-
* @returns - A promise that resolves with the authorization URL parameters.
|
|
1423
|
-
*
|
|
1424
|
-
* @example
|
|
1425
|
-
* ```
|
|
1426
|
-
* auth.getAuthorizationURLParams().then((params)=>{
|
|
1427
|
-
* // console.log(params);
|
|
1428
|
-
* }).catch((error)=>{
|
|
1429
|
-
* // console.error(error);
|
|
1430
|
-
* });
|
|
1431
|
-
* ```
|
|
1432
|
-
*
|
|
1433
|
-
* {@link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getAuthorizationURLParams}
|
|
1434
|
-
*
|
|
1435
|
-
* @preserve
|
|
1436
|
-
*/
|
|
1437
|
-
async getAuthorizationURLParams(config, userID) {
|
|
1438
|
-
const authRequestConfig = { ...config };
|
|
1439
|
-
delete authRequestConfig?.forceInit;
|
|
1440
|
-
if (await this._dataLayer.getTemporaryDataParameter(
|
|
1441
|
-
OIDCDiscoveryConstants_default.Storage.StorageKeys.OPENID_PROVIDER_CONFIG_INITIATED
|
|
1442
|
-
)) {
|
|
1443
|
-
return this._authenticationCore.getAuthorizationURLParams(authRequestConfig, userID);
|
|
1444
|
-
}
|
|
1445
|
-
return this._authenticationCore.getOIDCProviderMetaData(config?.forceInit).then(() => {
|
|
1446
|
-
return this._authenticationCore.getAuthorizationURLParams(authRequestConfig, userID);
|
|
1447
|
-
});
|
|
1448
|
-
}
|
|
1449
1061
|
/**
|
|
1450
1062
|
* This is an async method that returns a Promise that resolves with the authorization URL.
|
|
1451
1063
|
*
|
|
1452
1064
|
* @param config - (Optional) A config object to force initialization and pass
|
|
1453
1065
|
* custom path parameters such as the fidp parameter.
|
|
1454
|
-
* @param
|
|
1066
|
+
* @param userId - (Optional) A unique ID of the user to be authenticated. This is useful in multi-user
|
|
1455
1067
|
* scenarios where each user should be uniquely identified.
|
|
1456
1068
|
*
|
|
1457
1069
|
* @returns - A promise that resolves with the authorization URL.
|
|
1458
1070
|
*
|
|
1459
1071
|
* @example
|
|
1460
1072
|
* ```
|
|
1461
|
-
* auth.
|
|
1073
|
+
* auth.getSignInUrl().then((url)=>{
|
|
1462
1074
|
* // console.log(url);
|
|
1463
1075
|
* }).catch((error)=>{
|
|
1464
1076
|
* // console.error(error);
|
|
1465
1077
|
* });
|
|
1466
1078
|
* ```
|
|
1467
1079
|
*
|
|
1468
|
-
* {@link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#
|
|
1080
|
+
* {@link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getSignInUrl}
|
|
1469
1081
|
*
|
|
1470
1082
|
* @preserve
|
|
1471
1083
|
*/
|
|
1472
|
-
async
|
|
1473
|
-
const authRequestConfig = { ...
|
|
1084
|
+
async getSignInUrl(requestConfig, userId) {
|
|
1085
|
+
const authRequestConfig = { ...requestConfig };
|
|
1474
1086
|
delete authRequestConfig?.forceInit;
|
|
1475
|
-
|
|
1087
|
+
const __TODO__ = async () => {
|
|
1088
|
+
const authorizeEndpoint = await this._storageManager.getOIDCProviderMetaDataParameter(
|
|
1089
|
+
OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.AUTHORIZATION
|
|
1090
|
+
);
|
|
1091
|
+
if (!authorizeEndpoint || authorizeEndpoint.trim().length === 0) {
|
|
1092
|
+
throw new AsgardeoAuthException(
|
|
1093
|
+
"JS-AUTH_CORE-GAU-NF01",
|
|
1094
|
+
"No authorization endpoint found.",
|
|
1095
|
+
"No authorization endpoint was found in the OIDC provider meta data from the well-known endpoint or the authorization endpoint passed to the SDK is empty."
|
|
1096
|
+
);
|
|
1097
|
+
}
|
|
1098
|
+
const authorizeRequest = new URL(authorizeEndpoint);
|
|
1099
|
+
const configData = await this._config();
|
|
1100
|
+
const tempStore = await this._storageManager.getTemporaryData(userId);
|
|
1101
|
+
const pkceKey = await generatePkceStorageKey_default(tempStore);
|
|
1102
|
+
let codeVerifier;
|
|
1103
|
+
let codeChallenge;
|
|
1104
|
+
if (configData.enablePKCE) {
|
|
1105
|
+
codeVerifier = this._cryptoHelper?.getCodeVerifier();
|
|
1106
|
+
codeChallenge = this._cryptoHelper?.getCodeChallenge(codeVerifier);
|
|
1107
|
+
await this._storageManager.setTemporaryDataParameter(pkceKey, codeVerifier, userId);
|
|
1108
|
+
}
|
|
1109
|
+
const authorizeRequestParams = getAuthorizeRequestUrlParams_default(
|
|
1110
|
+
{
|
|
1111
|
+
redirectUri: configData.afterSignInUrl,
|
|
1112
|
+
clientId: configData.clientId,
|
|
1113
|
+
scopes: processOpenIDScopes_default(configData.scopes),
|
|
1114
|
+
responseMode: configData.responseMode,
|
|
1115
|
+
codeChallengeMethod: PKCEConstants_default.DEFAULT_CODE_CHALLENGE_METHOD,
|
|
1116
|
+
codeChallenge,
|
|
1117
|
+
prompt: configData.prompt
|
|
1118
|
+
},
|
|
1119
|
+
{ key: pkceKey },
|
|
1120
|
+
authRequestConfig
|
|
1121
|
+
);
|
|
1122
|
+
for (const [key, value] of authorizeRequestParams.entries()) {
|
|
1123
|
+
authorizeRequest.searchParams.append(key, value);
|
|
1124
|
+
}
|
|
1125
|
+
return authorizeRequest.toString();
|
|
1126
|
+
};
|
|
1127
|
+
if (await this._storageManager.getTemporaryDataParameter(
|
|
1476
1128
|
OIDCDiscoveryConstants_default.Storage.StorageKeys.OPENID_PROVIDER_CONFIG_INITIATED
|
|
1477
1129
|
)) {
|
|
1478
|
-
return
|
|
1130
|
+
return __TODO__();
|
|
1479
1131
|
}
|
|
1480
|
-
return this.
|
|
1481
|
-
return
|
|
1132
|
+
return this.loadOpenIDProviderConfiguration(requestConfig?.forceInit).then(() => {
|
|
1133
|
+
return __TODO__();
|
|
1482
1134
|
});
|
|
1483
1135
|
}
|
|
1484
1136
|
/**
|
|
@@ -1487,7 +1139,7 @@ var _AsgardeoAuthClient = class _AsgardeoAuthClient {
|
|
|
1487
1139
|
*
|
|
1488
1140
|
* @param authorizationCode - The authorization code.
|
|
1489
1141
|
* @param sessionState - The session state.
|
|
1490
|
-
* @param
|
|
1142
|
+
* @param userId - (Optional) A unique ID of the user to be authenticated. This is useful in multi-user
|
|
1491
1143
|
* scenarios where each user should be uniquely identified.
|
|
1492
1144
|
*
|
|
1493
1145
|
* @returns - A Promise that resolves with the token response.
|
|
@@ -1506,32 +1158,139 @@ var _AsgardeoAuthClient = class _AsgardeoAuthClient {
|
|
|
1506
1158
|
*
|
|
1507
1159
|
* @preserve
|
|
1508
1160
|
*/
|
|
1509
|
-
async requestAccessToken(authorizationCode, sessionState, state,
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1161
|
+
async requestAccessToken(authorizationCode, sessionState, state, userId, tokenRequestConfig) {
|
|
1162
|
+
const __TODO__ = async () => {
|
|
1163
|
+
const tokenEndpoint = (await this._oidcProviderMetaData()).token_endpoint;
|
|
1164
|
+
const configData = await this._config();
|
|
1165
|
+
if (!tokenEndpoint || tokenEndpoint.trim().length === 0) {
|
|
1166
|
+
throw new AsgardeoAuthException(
|
|
1167
|
+
"JS-AUTH_CORE-RAT1-NF01",
|
|
1168
|
+
"Token endpoint not found.",
|
|
1169
|
+
"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."
|
|
1170
|
+
);
|
|
1171
|
+
}
|
|
1172
|
+
sessionState && await this._storageManager.setSessionDataParameter(
|
|
1173
|
+
OIDCRequestConstants_default.Params.SESSION_STATE,
|
|
1515
1174
|
sessionState,
|
|
1516
|
-
|
|
1517
|
-
userID,
|
|
1518
|
-
tokenRequestConfig
|
|
1175
|
+
userId
|
|
1519
1176
|
);
|
|
1177
|
+
const body = new URLSearchParams();
|
|
1178
|
+
body.set("client_id", configData.clientId);
|
|
1179
|
+
if (configData.clientSecret && configData.clientSecret.trim().length > 0) {
|
|
1180
|
+
body.set("client_secret", configData.clientSecret);
|
|
1181
|
+
}
|
|
1182
|
+
const code = authorizationCode;
|
|
1183
|
+
body.set("code", code);
|
|
1184
|
+
body.set("grant_type", "authorization_code");
|
|
1185
|
+
body.set("redirect_uri", configData.afterSignInUrl);
|
|
1186
|
+
if (tokenRequestConfig?.params) {
|
|
1187
|
+
Object.entries(tokenRequestConfig.params).forEach(([key, value]) => {
|
|
1188
|
+
body.append(key, value);
|
|
1189
|
+
});
|
|
1190
|
+
}
|
|
1191
|
+
if (configData.enablePKCE) {
|
|
1192
|
+
body.set(
|
|
1193
|
+
"code_verifier",
|
|
1194
|
+
`${await this._storageManager.getTemporaryDataParameter(extractPkceStorageKeyFromState_default(state), userId)}`
|
|
1195
|
+
);
|
|
1196
|
+
await this._storageManager.removeTemporaryDataParameter(extractPkceStorageKeyFromState_default(state), userId);
|
|
1197
|
+
}
|
|
1198
|
+
let tokenResponse;
|
|
1199
|
+
try {
|
|
1200
|
+
tokenResponse = await fetch(tokenEndpoint, {
|
|
1201
|
+
body,
|
|
1202
|
+
credentials: configData.sendCookiesInRequests ? "include" : "same-origin",
|
|
1203
|
+
headers: {
|
|
1204
|
+
Accept: "application/json",
|
|
1205
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
1206
|
+
},
|
|
1207
|
+
method: "POST"
|
|
1208
|
+
});
|
|
1209
|
+
} catch (error) {
|
|
1210
|
+
throw new AsgardeoAuthException(
|
|
1211
|
+
"JS-AUTH_CORE-RAT1-NE02",
|
|
1212
|
+
"Requesting access token failed",
|
|
1213
|
+
error ?? "The request to get the access token from the server failed."
|
|
1214
|
+
);
|
|
1215
|
+
}
|
|
1216
|
+
if (!tokenResponse.ok) {
|
|
1217
|
+
throw new AsgardeoAuthException(
|
|
1218
|
+
"JS-AUTH_CORE-RAT1-HE03",
|
|
1219
|
+
`Requesting access token failed with ${tokenResponse.statusText}`,
|
|
1220
|
+
await tokenResponse.json()
|
|
1221
|
+
);
|
|
1222
|
+
}
|
|
1223
|
+
return await this._authenticationHelper.handleTokenResponse(tokenResponse, userId);
|
|
1224
|
+
};
|
|
1225
|
+
if (await this._storageManager.getTemporaryDataParameter(
|
|
1226
|
+
OIDCDiscoveryConstants_default.Storage.StorageKeys.OPENID_PROVIDER_CONFIG_INITIATED
|
|
1227
|
+
)) {
|
|
1228
|
+
return __TODO__();
|
|
1520
1229
|
}
|
|
1521
|
-
return this.
|
|
1522
|
-
return
|
|
1523
|
-
authorizationCode,
|
|
1524
|
-
sessionState,
|
|
1525
|
-
state,
|
|
1526
|
-
userID,
|
|
1527
|
-
tokenRequestConfig
|
|
1528
|
-
);
|
|
1230
|
+
return this.loadOpenIDProviderConfiguration(false).then(() => {
|
|
1231
|
+
return __TODO__();
|
|
1529
1232
|
});
|
|
1530
1233
|
}
|
|
1234
|
+
async loadOpenIDProviderConfiguration(forceInit) {
|
|
1235
|
+
const configData = await this._config();
|
|
1236
|
+
if (!forceInit && await this._storageManager.getTemporaryDataParameter(
|
|
1237
|
+
OIDCDiscoveryConstants_default.Storage.StorageKeys.OPENID_PROVIDER_CONFIG_INITIATED
|
|
1238
|
+
)) {
|
|
1239
|
+
return Promise.resolve();
|
|
1240
|
+
}
|
|
1241
|
+
const wellKnownEndpoint = configData.wellKnownEndpoint;
|
|
1242
|
+
if (wellKnownEndpoint) {
|
|
1243
|
+
let response;
|
|
1244
|
+
try {
|
|
1245
|
+
response = await fetch(wellKnownEndpoint);
|
|
1246
|
+
if (response.status !== 200 || !response.ok) {
|
|
1247
|
+
throw new Error();
|
|
1248
|
+
}
|
|
1249
|
+
} catch {
|
|
1250
|
+
throw new AsgardeoAuthException(
|
|
1251
|
+
"JS-AUTH_CORE-GOPMD-HE01",
|
|
1252
|
+
"Invalid well-known response",
|
|
1253
|
+
"The well known endpoint response has been failed with an error."
|
|
1254
|
+
);
|
|
1255
|
+
}
|
|
1256
|
+
await this._storageManager.setOIDCProviderMetaData(
|
|
1257
|
+
await this._authenticationHelper.resolveEndpoints(await response.json())
|
|
1258
|
+
);
|
|
1259
|
+
await this._storageManager.setTemporaryDataParameter(
|
|
1260
|
+
OIDCDiscoveryConstants_default.Storage.StorageKeys.OPENID_PROVIDER_CONFIG_INITIATED,
|
|
1261
|
+
true
|
|
1262
|
+
);
|
|
1263
|
+
return Promise.resolve();
|
|
1264
|
+
} else if (configData.baseUrl) {
|
|
1265
|
+
try {
|
|
1266
|
+
await this._storageManager.setOIDCProviderMetaData(
|
|
1267
|
+
await this._authenticationHelper.resolveEndpointsByBaseURL()
|
|
1268
|
+
);
|
|
1269
|
+
} catch (error) {
|
|
1270
|
+
throw new AsgardeoAuthException(
|
|
1271
|
+
"JS-AUTH_CORE-GOPMD-IV02",
|
|
1272
|
+
"Resolving endpoints failed.",
|
|
1273
|
+
error ?? "Resolving endpoints by base url failed."
|
|
1274
|
+
);
|
|
1275
|
+
}
|
|
1276
|
+
await this._storageManager.setTemporaryDataParameter(
|
|
1277
|
+
OIDCDiscoveryConstants_default.Storage.StorageKeys.OPENID_PROVIDER_CONFIG_INITIATED,
|
|
1278
|
+
true
|
|
1279
|
+
);
|
|
1280
|
+
return Promise.resolve();
|
|
1281
|
+
} else {
|
|
1282
|
+
await this._storageManager.setOIDCProviderMetaData(await this._authenticationHelper.resolveEndpointsExplicitly());
|
|
1283
|
+
await this._storageManager.setTemporaryDataParameter(
|
|
1284
|
+
OIDCDiscoveryConstants_default.Storage.StorageKeys.OPENID_PROVIDER_CONFIG_INITIATED,
|
|
1285
|
+
true
|
|
1286
|
+
);
|
|
1287
|
+
return Promise.resolve();
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1531
1290
|
/**
|
|
1532
1291
|
* This method returns the sign-out URL.
|
|
1533
1292
|
*
|
|
1534
|
-
* @param
|
|
1293
|
+
* @param userId - (Optional) A unique ID of the user to be authenticated. This is useful in multi-user
|
|
1535
1294
|
* scenarios where each user should be uniquely identified.
|
|
1536
1295
|
*
|
|
1537
1296
|
* **This doesn't clear the authentication data.**
|
|
@@ -1540,15 +1299,48 @@ var _AsgardeoAuthClient = class _AsgardeoAuthClient {
|
|
|
1540
1299
|
*
|
|
1541
1300
|
* @example
|
|
1542
1301
|
* ```
|
|
1543
|
-
* const signOutUrl = await auth.
|
|
1302
|
+
* const signOutUrl = await auth.getSignOutUrl();
|
|
1544
1303
|
* ```
|
|
1545
1304
|
*
|
|
1546
|
-
* {@link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#
|
|
1305
|
+
* {@link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getSignOutUrl}
|
|
1547
1306
|
*
|
|
1548
1307
|
* @preserve
|
|
1549
1308
|
*/
|
|
1550
|
-
async
|
|
1551
|
-
|
|
1309
|
+
async getSignOutUrl(userId) {
|
|
1310
|
+
const logoutEndpoint = (await this._oidcProviderMetaData())?.end_session_endpoint;
|
|
1311
|
+
const configData = await this._config();
|
|
1312
|
+
if (!logoutEndpoint || logoutEndpoint.trim().length === 0) {
|
|
1313
|
+
throw new AsgardeoAuthException(
|
|
1314
|
+
"JS-AUTH_CORE-GSOU-NF01",
|
|
1315
|
+
"Sign-out endpoint not found.",
|
|
1316
|
+
"No sign-out endpoint was found in the OIDC provider meta data returned by the well-known endpoint or the sign-out endpoint passed to the SDK is empty."
|
|
1317
|
+
);
|
|
1318
|
+
}
|
|
1319
|
+
const callbackURL = configData?.afterSignOutUrl ?? configData?.afterSignInUrl;
|
|
1320
|
+
if (!callbackURL || callbackURL.trim().length === 0) {
|
|
1321
|
+
throw new AsgardeoAuthException(
|
|
1322
|
+
"JS-AUTH_CORE-GSOU-NF03",
|
|
1323
|
+
"No sign-out redirect URL found.",
|
|
1324
|
+
"The sign-out redirect URL cannot be found or the URL passed to the SDK is empty. No sign-in redirect URL has been found either. "
|
|
1325
|
+
);
|
|
1326
|
+
}
|
|
1327
|
+
const queryParams = new URLSearchParams();
|
|
1328
|
+
queryParams.set("post_logout_redirect_uri", callbackURL);
|
|
1329
|
+
if (configData.sendIdTokenInLogoutRequest) {
|
|
1330
|
+
const idToken = (await this._storageManager.getSessionData(userId))?.id_token;
|
|
1331
|
+
if (!idToken || idToken.trim().length === 0) {
|
|
1332
|
+
throw new AsgardeoAuthException(
|
|
1333
|
+
"JS-AUTH_CORE-GSOU-NF02",
|
|
1334
|
+
"ID token not found.",
|
|
1335
|
+
"No ID token could be found. Either the session information is lost or you have not signed in."
|
|
1336
|
+
);
|
|
1337
|
+
}
|
|
1338
|
+
queryParams.set("id_token_hint", idToken);
|
|
1339
|
+
} else {
|
|
1340
|
+
queryParams.set("client_id", configData.clientId);
|
|
1341
|
+
}
|
|
1342
|
+
queryParams.set("state", OIDCRequestConstants_default.Params.SIGN_OUT_SUCCESS);
|
|
1343
|
+
return `${logoutEndpoint}?${queryParams.toString()}`;
|
|
1552
1344
|
}
|
|
1553
1345
|
/**
|
|
1554
1346
|
* This method returns OIDC service endpoints that are fetched from the `.well-known` endpoint.
|
|
@@ -1557,75 +1349,103 @@ var _AsgardeoAuthClient = class _AsgardeoAuthClient {
|
|
|
1557
1349
|
*
|
|
1558
1350
|
* @example
|
|
1559
1351
|
* ```
|
|
1560
|
-
* const endpoints = await auth.
|
|
1352
|
+
* const endpoints = await auth.getOpenIDProviderEndpoints();
|
|
1561
1353
|
* ```
|
|
1562
1354
|
*
|
|
1563
|
-
* {@link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#
|
|
1355
|
+
* {@link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getOpenIDProviderEndpoints}
|
|
1564
1356
|
*
|
|
1565
1357
|
* @preserve
|
|
1566
1358
|
*/
|
|
1567
|
-
async
|
|
1568
|
-
|
|
1359
|
+
async getOpenIDProviderEndpoints() {
|
|
1360
|
+
const oidcProviderMetaData = await this._oidcProviderMetaData();
|
|
1361
|
+
return {
|
|
1362
|
+
authorizationEndpoint: oidcProviderMetaData.authorization_endpoint ?? "",
|
|
1363
|
+
checkSessionIframe: oidcProviderMetaData.check_session_iframe ?? "",
|
|
1364
|
+
endSessionEndpoint: oidcProviderMetaData.end_session_endpoint ?? "",
|
|
1365
|
+
introspectionEndpoint: oidcProviderMetaData.introspection_endpoint ?? "",
|
|
1366
|
+
issuer: oidcProviderMetaData.issuer ?? "",
|
|
1367
|
+
jwksUri: oidcProviderMetaData.jwks_uri ?? "",
|
|
1368
|
+
registrationEndpoint: oidcProviderMetaData.registration_endpoint ?? "",
|
|
1369
|
+
revocationEndpoint: oidcProviderMetaData.revocation_endpoint ?? "",
|
|
1370
|
+
tokenEndpoint: oidcProviderMetaData.token_endpoint ?? "",
|
|
1371
|
+
userinfoEndpoint: oidcProviderMetaData.userinfo_endpoint ?? ""
|
|
1372
|
+
};
|
|
1569
1373
|
}
|
|
1570
1374
|
/**
|
|
1571
1375
|
* This method decodes the payload of the ID token and returns it.
|
|
1572
1376
|
*
|
|
1573
|
-
* @param
|
|
1377
|
+
* @param userId - (Optional) A unique ID of the user to be authenticated. This is useful in multi-user
|
|
1574
1378
|
* scenarios where each user should be uniquely identified.
|
|
1575
1379
|
*
|
|
1576
1380
|
* @returns - A Promise that resolves with the decoded ID token payload.
|
|
1577
1381
|
*
|
|
1578
1382
|
* @example
|
|
1579
1383
|
* ```
|
|
1580
|
-
* const decodedIdToken = await auth.
|
|
1384
|
+
* const decodedIdToken = await auth.getDecodedIdToken();
|
|
1581
1385
|
* ```
|
|
1582
1386
|
*
|
|
1583
|
-
* {@link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#
|
|
1387
|
+
* {@link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getDecodedIdToken}
|
|
1584
1388
|
*
|
|
1585
1389
|
* @preserve
|
|
1586
1390
|
*/
|
|
1587
|
-
async
|
|
1588
|
-
|
|
1391
|
+
async getDecodedIdToken(userId) {
|
|
1392
|
+
const idToken = (await this._storageManager.getSessionData(userId)).id_token;
|
|
1393
|
+
const payload = this._cryptoHelper.decodeIdToken(idToken);
|
|
1394
|
+
return payload;
|
|
1589
1395
|
}
|
|
1590
1396
|
/**
|
|
1591
1397
|
* This method returns the ID token.
|
|
1592
1398
|
*
|
|
1593
|
-
* @param
|
|
1399
|
+
* @param userId - (Optional) A unique ID of the user to be authenticated. This is useful in multi-user
|
|
1594
1400
|
* scenarios where each user should be uniquely identified.
|
|
1595
1401
|
*
|
|
1596
1402
|
* @returns - A Promise that resolves with the ID token.
|
|
1597
1403
|
*
|
|
1598
1404
|
* @example
|
|
1599
1405
|
* ```
|
|
1600
|
-
* const idToken = await auth.
|
|
1406
|
+
* const idToken = await auth.getIdToken();
|
|
1601
1407
|
* ```
|
|
1602
1408
|
*
|
|
1603
|
-
* {@link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#
|
|
1409
|
+
* {@link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getIdToken}
|
|
1604
1410
|
*
|
|
1605
1411
|
* @preserve
|
|
1606
1412
|
*/
|
|
1607
|
-
async
|
|
1608
|
-
return this.
|
|
1413
|
+
async getIdToken(userId) {
|
|
1414
|
+
return (await this._storageManager.getSessionData(userId)).id_token;
|
|
1609
1415
|
}
|
|
1610
1416
|
/**
|
|
1611
1417
|
* This method returns the basic user information obtained from the ID token.
|
|
1612
1418
|
*
|
|
1613
|
-
* @param
|
|
1419
|
+
* @param userId - (Optional) A unique ID of the user to be authenticated. This is useful in multi-user
|
|
1614
1420
|
* scenarios where each user should be uniquely identified.
|
|
1615
1421
|
*
|
|
1616
1422
|
* @returns - A Promise that resolves with an object containing the basic user information.
|
|
1617
1423
|
*
|
|
1618
1424
|
* @example
|
|
1619
1425
|
* ```
|
|
1620
|
-
* const userInfo = await auth.
|
|
1426
|
+
* const userInfo = await auth.getUser();
|
|
1621
1427
|
* ```
|
|
1622
1428
|
*
|
|
1623
|
-
* {@link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#
|
|
1429
|
+
* {@link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getUser}
|
|
1624
1430
|
*
|
|
1625
1431
|
* @preserve
|
|
1626
1432
|
*/
|
|
1627
|
-
async
|
|
1628
|
-
|
|
1433
|
+
async getUser(userId) {
|
|
1434
|
+
const sessionData = await this._storageManager.getSessionData(userId);
|
|
1435
|
+
const authenticatedUser = this._authenticationHelper.getAuthenticatedUserInfo(sessionData?.id_token);
|
|
1436
|
+
Object.keys(authenticatedUser).forEach((key) => {
|
|
1437
|
+
if (authenticatedUser[key] === void 0 || authenticatedUser[key] === "" || authenticatedUser[key] === null) {
|
|
1438
|
+
delete authenticatedUser[key];
|
|
1439
|
+
}
|
|
1440
|
+
});
|
|
1441
|
+
return authenticatedUser;
|
|
1442
|
+
}
|
|
1443
|
+
async getUserSession(userId) {
|
|
1444
|
+
const sessionData = await this._storageManager.getSessionData(userId);
|
|
1445
|
+
return {
|
|
1446
|
+
scopes: sessionData?.scope?.split(" "),
|
|
1447
|
+
sessionState: sessionData?.session_state ?? ""
|
|
1448
|
+
};
|
|
1629
1449
|
}
|
|
1630
1450
|
/**
|
|
1631
1451
|
* This method returns the crypto helper object.
|
|
@@ -1637,17 +1457,17 @@ var _AsgardeoAuthClient = class _AsgardeoAuthClient {
|
|
|
1637
1457
|
* const cryptoHelper = await auth.IsomorphicCrypto();
|
|
1638
1458
|
* ```
|
|
1639
1459
|
*
|
|
1640
|
-
* {@link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#
|
|
1460
|
+
* {@link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getCrypto}
|
|
1641
1461
|
*
|
|
1642
1462
|
* @preserve
|
|
1643
1463
|
*/
|
|
1644
|
-
async
|
|
1645
|
-
return this.
|
|
1464
|
+
async getCrypto() {
|
|
1465
|
+
return this._cryptoHelper;
|
|
1646
1466
|
}
|
|
1647
1467
|
/**
|
|
1648
1468
|
* This method revokes the access token.
|
|
1649
1469
|
*
|
|
1650
|
-
* @param
|
|
1470
|
+
* @param userId - (Optional) A unique ID of the user to be authenticated. This is useful in multi-user
|
|
1651
1471
|
* scenarios where each user should be uniquely identified.
|
|
1652
1472
|
*
|
|
1653
1473
|
* **This method also clears the authentication data.**
|
|
@@ -1667,14 +1487,56 @@ var _AsgardeoAuthClient = class _AsgardeoAuthClient {
|
|
|
1667
1487
|
*
|
|
1668
1488
|
* @preserve
|
|
1669
1489
|
*/
|
|
1670
|
-
revokeAccessToken(
|
|
1671
|
-
|
|
1490
|
+
async revokeAccessToken(userId) {
|
|
1491
|
+
const revokeTokenEndpoint = (await this._oidcProviderMetaData()).revocation_endpoint;
|
|
1492
|
+
const configData = await this._config();
|
|
1493
|
+
if (!revokeTokenEndpoint || revokeTokenEndpoint.trim().length === 0) {
|
|
1494
|
+
throw new AsgardeoAuthException(
|
|
1495
|
+
"JS-AUTH_CORE-RAT3-NF01",
|
|
1496
|
+
"No revoke access token endpoint found.",
|
|
1497
|
+
"No revoke access token endpoint was found in the OIDC provider meta data returned by the well-known endpoint or the revoke access token endpoint passed to the SDK is empty."
|
|
1498
|
+
);
|
|
1499
|
+
}
|
|
1500
|
+
const body = [];
|
|
1501
|
+
body.push(`client_id=${configData.clientId}`);
|
|
1502
|
+
body.push(`token=${(await this._storageManager.getSessionData(userId)).access_token}`);
|
|
1503
|
+
body.push("token_type_hint=access_token");
|
|
1504
|
+
if (configData.clientSecret && configData.clientSecret.trim().length > 0) {
|
|
1505
|
+
body.push(`client_secret=${configData.clientSecret}`);
|
|
1506
|
+
}
|
|
1507
|
+
let response;
|
|
1508
|
+
try {
|
|
1509
|
+
response = await fetch(revokeTokenEndpoint, {
|
|
1510
|
+
body: body.join("&"),
|
|
1511
|
+
credentials: configData.sendCookiesInRequests ? "include" : "same-origin",
|
|
1512
|
+
headers: {
|
|
1513
|
+
Accept: "application/json",
|
|
1514
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
1515
|
+
},
|
|
1516
|
+
method: "POST"
|
|
1517
|
+
});
|
|
1518
|
+
} catch (error) {
|
|
1519
|
+
throw new AsgardeoAuthException(
|
|
1520
|
+
"JS-AUTH_CORE-RAT3-NE02",
|
|
1521
|
+
"The request to revoke access token failed.",
|
|
1522
|
+
error ?? "The request sent to revoke the access token failed."
|
|
1523
|
+
);
|
|
1524
|
+
}
|
|
1525
|
+
if (response.status !== 200 || !response.ok) {
|
|
1526
|
+
throw new AsgardeoAuthException(
|
|
1527
|
+
"JS-AUTH_CORE-RAT3-HE03",
|
|
1528
|
+
`Invalid response status received for revoke access token request (${response.statusText}).`,
|
|
1529
|
+
await response.json()
|
|
1530
|
+
);
|
|
1531
|
+
}
|
|
1532
|
+
this._authenticationHelper.clearSession(userId);
|
|
1533
|
+
return Promise.resolve(response);
|
|
1672
1534
|
}
|
|
1673
1535
|
/**
|
|
1674
1536
|
* This method refreshes the access token and returns a Promise that resolves with the new access
|
|
1675
1537
|
* token and other relevant data.
|
|
1676
1538
|
*
|
|
1677
|
-
* @param
|
|
1539
|
+
* @param userId - (Optional) A unique ID of the user to be authenticated. This is useful in multi-user
|
|
1678
1540
|
* scenarios where each user should be uniquely identified.
|
|
1679
1541
|
*
|
|
1680
1542
|
* @returns - A Promise that resolves with the token response.
|
|
@@ -1692,13 +1554,62 @@ var _AsgardeoAuthClient = class _AsgardeoAuthClient {
|
|
|
1692
1554
|
*
|
|
1693
1555
|
* @preserve
|
|
1694
1556
|
*/
|
|
1695
|
-
refreshAccessToken(
|
|
1696
|
-
|
|
1557
|
+
async refreshAccessToken(userId) {
|
|
1558
|
+
const tokenEndpoint = (await this._oidcProviderMetaData()).token_endpoint;
|
|
1559
|
+
const configData = await this._config();
|
|
1560
|
+
const sessionData = await this._storageManager.getSessionData(userId);
|
|
1561
|
+
if (!sessionData.refresh_token) {
|
|
1562
|
+
throw new AsgardeoAuthException(
|
|
1563
|
+
"JS-AUTH_CORE-RAT2-NF01",
|
|
1564
|
+
"No refresh token found.",
|
|
1565
|
+
"There was no refresh token found. Asgardeo doesn't return a refresh token if the refresh token grant is not enabled."
|
|
1566
|
+
);
|
|
1567
|
+
}
|
|
1568
|
+
if (!tokenEndpoint || tokenEndpoint.trim().length === 0) {
|
|
1569
|
+
throw new AsgardeoAuthException(
|
|
1570
|
+
"JS-AUTH_CORE-RAT2-NF02",
|
|
1571
|
+
"No refresh token endpoint found.",
|
|
1572
|
+
"No refresh token endpoint was in the OIDC provider meta data returned by the well-known endpoint or the refresh token endpoint passed to the SDK is empty."
|
|
1573
|
+
);
|
|
1574
|
+
}
|
|
1575
|
+
const body = [];
|
|
1576
|
+
body.push(`client_id=${configData.clientId}`);
|
|
1577
|
+
body.push(`refresh_token=${sessionData.refresh_token}`);
|
|
1578
|
+
body.push("grant_type=refresh_token");
|
|
1579
|
+
if (configData.clientSecret && configData.clientSecret.trim().length > 0) {
|
|
1580
|
+
body.push(`client_secret=${configData.clientSecret}`);
|
|
1581
|
+
}
|
|
1582
|
+
let tokenResponse;
|
|
1583
|
+
try {
|
|
1584
|
+
tokenResponse = await fetch(tokenEndpoint, {
|
|
1585
|
+
body: body.join("&"),
|
|
1586
|
+
credentials: configData.sendCookiesInRequests ? "include" : "same-origin",
|
|
1587
|
+
headers: {
|
|
1588
|
+
Accept: "application/json",
|
|
1589
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
1590
|
+
},
|
|
1591
|
+
method: "POST"
|
|
1592
|
+
});
|
|
1593
|
+
} catch (error) {
|
|
1594
|
+
throw new AsgardeoAuthException(
|
|
1595
|
+
"JS-AUTH_CORE-RAT2-NR03",
|
|
1596
|
+
"Refresh access token request failed.",
|
|
1597
|
+
error ?? "The request to refresh the access token failed."
|
|
1598
|
+
);
|
|
1599
|
+
}
|
|
1600
|
+
if (!tokenResponse.ok) {
|
|
1601
|
+
throw new AsgardeoAuthException(
|
|
1602
|
+
"JS-AUTH_CORE-RAT2-HE04",
|
|
1603
|
+
`Refreshing access token failed with ${tokenResponse.statusText}`,
|
|
1604
|
+
await tokenResponse.json()
|
|
1605
|
+
);
|
|
1606
|
+
}
|
|
1607
|
+
return this._authenticationHelper.handleTokenResponse(tokenResponse, userId);
|
|
1697
1608
|
}
|
|
1698
1609
|
/**
|
|
1699
1610
|
* This method returns the access token.
|
|
1700
1611
|
*
|
|
1701
|
-
* @param
|
|
1612
|
+
* @param userId - (Optional) A unique ID of the user to be authenticated. This is useful in multi-user
|
|
1702
1613
|
* scenarios where each user should be uniquely identified.
|
|
1703
1614
|
*
|
|
1704
1615
|
* @returns - A Promise that resolves with the access token.
|
|
@@ -1712,15 +1623,15 @@ var _AsgardeoAuthClient = class _AsgardeoAuthClient {
|
|
|
1712
1623
|
*
|
|
1713
1624
|
* @preserve
|
|
1714
1625
|
*/
|
|
1715
|
-
async getAccessToken(
|
|
1716
|
-
return this.
|
|
1626
|
+
async getAccessToken(userId) {
|
|
1627
|
+
return (await this._storageManager.getSessionData(userId))?.access_token;
|
|
1717
1628
|
}
|
|
1718
1629
|
/**
|
|
1719
1630
|
* This method sends a custom-grant request and returns a Promise that resolves with the response
|
|
1720
1631
|
* depending on the config passed.
|
|
1721
1632
|
*
|
|
1722
1633
|
* @param config - A config object containing the custom grant configurations.
|
|
1723
|
-
* @param
|
|
1634
|
+
* @param userId - (Optional) A unique ID of the user to be authenticated. This is useful in multi-user
|
|
1724
1635
|
* scenarios where each user should be uniquely identified.
|
|
1725
1636
|
*
|
|
1726
1637
|
* @returns - A Promise that resolves with the response depending
|
|
@@ -1731,7 +1642,7 @@ var _AsgardeoAuthClient = class _AsgardeoAuthClient {
|
|
|
1731
1642
|
* const config = {
|
|
1732
1643
|
* attachToken: false,
|
|
1733
1644
|
* data: {
|
|
1734
|
-
* client_id: "{{
|
|
1645
|
+
* client_id: "{{clientId}}",
|
|
1735
1646
|
* grant_type: "account_switch",
|
|
1736
1647
|
* scope: "{{scope}}",
|
|
1737
1648
|
* token: "{{token}}",
|
|
@@ -1742,44 +1653,115 @@ var _AsgardeoAuthClient = class _AsgardeoAuthClient {
|
|
|
1742
1653
|
* signInRequired: true
|
|
1743
1654
|
* }
|
|
1744
1655
|
*
|
|
1745
|
-
* auth.
|
|
1656
|
+
* auth.exchangeToken(config).then((response)=>{
|
|
1746
1657
|
* // console.log(response);
|
|
1747
1658
|
* }).catch((error)=>{
|
|
1748
1659
|
* // console.error(error);
|
|
1749
1660
|
* });
|
|
1750
1661
|
* ```
|
|
1751
1662
|
*
|
|
1752
|
-
* {@link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#
|
|
1663
|
+
* {@link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#exchangeToken}
|
|
1753
1664
|
*
|
|
1754
1665
|
* @preserve
|
|
1755
1666
|
*/
|
|
1756
|
-
|
|
1757
|
-
|
|
1667
|
+
async exchangeToken(config, userId) {
|
|
1668
|
+
const oidcProviderMetadata = await this._oidcProviderMetaData();
|
|
1669
|
+
const configData = await this._config();
|
|
1670
|
+
let tokenEndpoint;
|
|
1671
|
+
if (config.tokenEndpoint && config.tokenEndpoint.trim().length !== 0) {
|
|
1672
|
+
tokenEndpoint = config.tokenEndpoint;
|
|
1673
|
+
} else {
|
|
1674
|
+
tokenEndpoint = oidcProviderMetadata.token_endpoint;
|
|
1675
|
+
}
|
|
1676
|
+
if (!tokenEndpoint || tokenEndpoint.trim().length === 0) {
|
|
1677
|
+
throw new AsgardeoAuthException(
|
|
1678
|
+
"JS-AUTH_CORE-RCG-NF01",
|
|
1679
|
+
"Token endpoint not found.",
|
|
1680
|
+
"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."
|
|
1681
|
+
);
|
|
1682
|
+
}
|
|
1683
|
+
const data = await Promise.all(
|
|
1684
|
+
Object.entries(config.data).map(async ([key, value]) => {
|
|
1685
|
+
const newValue = await this._authenticationHelper.replaceCustomGrantTemplateTags(
|
|
1686
|
+
value,
|
|
1687
|
+
userId
|
|
1688
|
+
);
|
|
1689
|
+
return `${key}=${newValue}`;
|
|
1690
|
+
})
|
|
1691
|
+
);
|
|
1692
|
+
let requestHeaders = {
|
|
1693
|
+
Accept: "application/json",
|
|
1694
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
1695
|
+
};
|
|
1696
|
+
if (config.attachToken) {
|
|
1697
|
+
requestHeaders = {
|
|
1698
|
+
...requestHeaders,
|
|
1699
|
+
Authorization: `Bearer ${(await this._storageManager.getSessionData(userId)).access_token}`
|
|
1700
|
+
};
|
|
1701
|
+
}
|
|
1702
|
+
const requestConfig = {
|
|
1703
|
+
body: data.join("&"),
|
|
1704
|
+
credentials: configData.sendCookiesInRequests ? "include" : "same-origin",
|
|
1705
|
+
headers: new Headers(requestHeaders),
|
|
1706
|
+
method: "POST"
|
|
1707
|
+
};
|
|
1708
|
+
let response;
|
|
1709
|
+
try {
|
|
1710
|
+
response = await fetch(tokenEndpoint, requestConfig);
|
|
1711
|
+
} catch (error) {
|
|
1712
|
+
throw new AsgardeoAuthException(
|
|
1713
|
+
"JS-AUTH_CORE-RCG-NE02",
|
|
1714
|
+
"The custom grant request failed.",
|
|
1715
|
+
error ?? "The request sent to get the custom grant failed."
|
|
1716
|
+
);
|
|
1717
|
+
}
|
|
1718
|
+
if (response.status !== 200 || !response.ok) {
|
|
1719
|
+
throw new AsgardeoAuthException(
|
|
1720
|
+
"JS-AUTH_CORE-RCG-HE03",
|
|
1721
|
+
`Invalid response status received for the custom grant request. (${response.statusText})`,
|
|
1722
|
+
await response.json()
|
|
1723
|
+
);
|
|
1724
|
+
}
|
|
1725
|
+
if (config.returnsSession) {
|
|
1726
|
+
return this._authenticationHelper.handleTokenResponse(response, userId);
|
|
1727
|
+
} else {
|
|
1728
|
+
return Promise.resolve(await response.json());
|
|
1729
|
+
}
|
|
1758
1730
|
}
|
|
1759
1731
|
/**
|
|
1760
1732
|
* This method returns if the user is authenticated or not.
|
|
1761
1733
|
*
|
|
1762
|
-
* @param
|
|
1734
|
+
* @param userId - (Optional) A unique ID of the user to be authenticated. This is useful in multi-user
|
|
1763
1735
|
* scenarios where each user should be uniquely identified.
|
|
1764
1736
|
*
|
|
1765
1737
|
* @returns - A Promise that resolves with `true` if the user is authenticated, `false` otherwise.
|
|
1766
1738
|
*
|
|
1767
1739
|
* @example
|
|
1768
1740
|
* ```
|
|
1769
|
-
* await auth.
|
|
1741
|
+
* await auth.isSignedIn();
|
|
1770
1742
|
* ```
|
|
1771
1743
|
*
|
|
1772
|
-
* {@link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#
|
|
1744
|
+
* {@link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#isSignedIn}
|
|
1773
1745
|
*
|
|
1774
1746
|
* @preserve
|
|
1775
1747
|
*/
|
|
1776
|
-
async
|
|
1777
|
-
|
|
1748
|
+
async isSignedIn(userId) {
|
|
1749
|
+
const isAccessTokenAvailable = Boolean(await this.getAccessToken(userId));
|
|
1750
|
+
const createdAt = (await this._storageManager.getSessionData(userId))?.created_at;
|
|
1751
|
+
const expiresInString = (await this._storageManager.getSessionData(userId))?.expires_in;
|
|
1752
|
+
if (!expiresInString) {
|
|
1753
|
+
return false;
|
|
1754
|
+
}
|
|
1755
|
+
const expiresIn = parseInt(expiresInString) * 1e3;
|
|
1756
|
+
const currentTime = (/* @__PURE__ */ new Date()).getTime();
|
|
1757
|
+
const isAccessTokenValid = createdAt + expiresIn > currentTime;
|
|
1758
|
+
const isSignedIn = isAccessTokenAvailable && isAccessTokenValid;
|
|
1759
|
+
return isSignedIn;
|
|
1778
1760
|
}
|
|
1779
1761
|
/**
|
|
1780
1762
|
* This method returns the PKCE code generated during the generation of the authentication URL.
|
|
1781
1763
|
*
|
|
1782
|
-
* @param
|
|
1764
|
+
* @param userId - (Optional) A unique ID of the user to be authenticated. This is useful in multi-user
|
|
1783
1765
|
* scenarios where each user should be uniquely identified.
|
|
1784
1766
|
* @param state - The state parameter that was passed in the authentication URL.
|
|
1785
1767
|
*
|
|
@@ -1794,15 +1776,18 @@ var _AsgardeoAuthClient = class _AsgardeoAuthClient {
|
|
|
1794
1776
|
*
|
|
1795
1777
|
* @preserve
|
|
1796
1778
|
*/
|
|
1797
|
-
async getPKCECode(state,
|
|
1798
|
-
return this.
|
|
1779
|
+
async getPKCECode(state, userId) {
|
|
1780
|
+
return await this._storageManager.getTemporaryDataParameter(
|
|
1781
|
+
extractPkceStorageKeyFromState_default(state),
|
|
1782
|
+
userId
|
|
1783
|
+
);
|
|
1799
1784
|
}
|
|
1800
1785
|
/**
|
|
1801
1786
|
* This method sets the PKCE code to the data store.
|
|
1802
1787
|
*
|
|
1803
1788
|
* @param pkce - The PKCE code.
|
|
1804
1789
|
* @param state - The state parameter that was passed in the authentication URL.
|
|
1805
|
-
* @param
|
|
1790
|
+
* @param userId - (Optional) A unique ID of the user to be authenticated. This is useful in multi-user
|
|
1806
1791
|
* scenarios where each user should be uniquely identified.
|
|
1807
1792
|
*
|
|
1808
1793
|
* @example
|
|
@@ -1814,15 +1799,15 @@ var _AsgardeoAuthClient = class _AsgardeoAuthClient {
|
|
|
1814
1799
|
*
|
|
1815
1800
|
* @preserve
|
|
1816
1801
|
*/
|
|
1817
|
-
async setPKCECode(pkce, state,
|
|
1818
|
-
await this.
|
|
1802
|
+
async setPKCECode(pkce, state, userId) {
|
|
1803
|
+
return await this._storageManager.setTemporaryDataParameter(extractPkceStorageKeyFromState_default(state), pkce, userId);
|
|
1819
1804
|
}
|
|
1820
1805
|
/**
|
|
1821
1806
|
* This method returns if the sign-out is successful or not.
|
|
1822
1807
|
*
|
|
1823
1808
|
* @param signOutRedirectUrl - The URL to which the user has been redirected to after signing-out.
|
|
1824
1809
|
*
|
|
1825
|
-
* **The server appends path parameters to the `
|
|
1810
|
+
* **The server appends path parameters to the `afterSignOutUrl` and these path parameters
|
|
1826
1811
|
* are required for this method to function.**
|
|
1827
1812
|
*
|
|
1828
1813
|
* @returns - `true` if successful, `false` otherwise.
|
|
@@ -1831,8 +1816,8 @@ var _AsgardeoAuthClient = class _AsgardeoAuthClient {
|
|
|
1831
1816
|
*
|
|
1832
1817
|
* @preserve
|
|
1833
1818
|
*/
|
|
1834
|
-
static isSignOutSuccessful(
|
|
1835
|
-
const url = new URL(
|
|
1819
|
+
static isSignOutSuccessful(afterSignOutUrl) {
|
|
1820
|
+
const url = new URL(afterSignOutUrl);
|
|
1836
1821
|
const stateParam = url.searchParams.get(OIDCRequestConstants_default.Params.STATE);
|
|
1837
1822
|
const error = Boolean(url.searchParams.get("error"));
|
|
1838
1823
|
return stateParam ? stateParam === OIDCRequestConstants_default.Params.SIGN_OUT_SUCCESS && !error : false;
|
|
@@ -1842,7 +1827,7 @@ var _AsgardeoAuthClient = class _AsgardeoAuthClient {
|
|
|
1842
1827
|
*
|
|
1843
1828
|
* @param signOutRedirectUrl - The URL to which the user has been redirected to after signing-out.
|
|
1844
1829
|
*
|
|
1845
|
-
* **The server appends path parameters to the `
|
|
1830
|
+
* **The server appends path parameters to the `afterSignOutUrl` and these path parameters
|
|
1846
1831
|
* are required for this method to function.**
|
|
1847
1832
|
*
|
|
1848
1833
|
* @returns - `true` if successful, `false` otherwise.
|
|
@@ -1851,8 +1836,8 @@ var _AsgardeoAuthClient = class _AsgardeoAuthClient {
|
|
|
1851
1836
|
*
|
|
1852
1837
|
* @preserve
|
|
1853
1838
|
*/
|
|
1854
|
-
static didSignOutFail(
|
|
1855
|
-
const url = new URL(
|
|
1839
|
+
static didSignOutFail(afterSignOutUrl) {
|
|
1840
|
+
const url = new URL(afterSignOutUrl);
|
|
1856
1841
|
const stateParam = url.searchParams.get(OIDCRequestConstants_default.Params.STATE);
|
|
1857
1842
|
const error = Boolean(url.searchParams.get("error"));
|
|
1858
1843
|
return stateParam ? stateParam === OIDCRequestConstants_default.Params.SIGN_OUT_SUCCESS && error : false;
|
|
@@ -1865,61 +1850,31 @@ var _AsgardeoAuthClient = class _AsgardeoAuthClient {
|
|
|
1865
1850
|
* @example
|
|
1866
1851
|
* ```
|
|
1867
1852
|
* const config = {
|
|
1868
|
-
*
|
|
1869
|
-
*
|
|
1853
|
+
* afterSignInUrl: "http://localhost:3000/sign-in",
|
|
1854
|
+
* clientId: "client ID",
|
|
1870
1855
|
* baseUrl: "https://localhost:9443"
|
|
1871
1856
|
* }
|
|
1872
1857
|
*
|
|
1873
|
-
* await auth.
|
|
1858
|
+
* await auth.reInitialize(config);
|
|
1874
1859
|
* ```
|
|
1875
|
-
* {@link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#
|
|
1860
|
+
* {@link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#reInitialize}
|
|
1876
1861
|
*
|
|
1877
1862
|
* @preserve
|
|
1878
1863
|
*/
|
|
1879
|
-
async
|
|
1880
|
-
await this.
|
|
1864
|
+
async reInitialize(config) {
|
|
1865
|
+
await this._storageManager.setConfigData(config);
|
|
1866
|
+
await this.loadOpenIDProviderConfiguration(true);
|
|
1881
1867
|
}
|
|
1882
|
-
static async
|
|
1883
|
-
await this.
|
|
1868
|
+
static async clearSession(userId) {
|
|
1869
|
+
await this._authenticationHelper.clearSession(userId);
|
|
1884
1870
|
}
|
|
1885
1871
|
};
|
|
1886
1872
|
__publicField(_AsgardeoAuthClient, "_instanceID");
|
|
1887
|
-
|
|
1873
|
+
// FIXME: Validate this.
|
|
1874
|
+
// Ref: https://github.com/asgardeo/asgardeo-auth-js-core/pull/205
|
|
1875
|
+
__publicField(_AsgardeoAuthClient, "_authenticationHelper");
|
|
1888
1876
|
var AsgardeoAuthClient = _AsgardeoAuthClient;
|
|
1889
1877
|
|
|
1890
|
-
// src/errors/AsgardeoError.ts
|
|
1891
|
-
var AsgardeoError = class _AsgardeoError extends Error {
|
|
1892
|
-
constructor(message, code, origin) {
|
|
1893
|
-
const _origin = _AsgardeoError.resolveOrigin(origin);
|
|
1894
|
-
const prefix = `\u{1F6E1}\uFE0F Asgardeo - ${_origin}:`;
|
|
1895
|
-
const regex = new RegExp(`\u{1F6E1}\uFE0F\\s*Asgardeo\\s*-\\s*${_origin}:`, "i");
|
|
1896
|
-
const sanitized = message.replace(regex, "");
|
|
1897
|
-
const _message = `${prefix} ${sanitized.trim()}
|
|
1898
|
-
|
|
1899
|
-
(code="${code}")
|
|
1900
|
-
`;
|
|
1901
|
-
super(_message);
|
|
1902
|
-
__publicField(this, "code");
|
|
1903
|
-
__publicField(this, "origin");
|
|
1904
|
-
this.name = new.target.name;
|
|
1905
|
-
this.code = code;
|
|
1906
|
-
this.origin = _origin;
|
|
1907
|
-
if (Error.captureStackTrace) {
|
|
1908
|
-
Error.captureStackTrace(this, new.target);
|
|
1909
|
-
}
|
|
1910
|
-
}
|
|
1911
|
-
static resolveOrigin(origin) {
|
|
1912
|
-
if (!origin) {
|
|
1913
|
-
return "@asgardeo/javascript";
|
|
1914
|
-
}
|
|
1915
|
-
return `@asgardeo/${origin}`;
|
|
1916
|
-
}
|
|
1917
|
-
toString() {
|
|
1918
|
-
return `[${this.name}]
|
|
1919
|
-
Message: ${this.message}`;
|
|
1920
|
-
}
|
|
1921
|
-
};
|
|
1922
|
-
|
|
1923
1878
|
// src/errors/AsgardeoAPIError.ts
|
|
1924
1879
|
var AsgardeoAPIError = class extends AsgardeoError {
|
|
1925
1880
|
/**
|
|
@@ -1953,7 +1908,95 @@ Message: ${this.message}`;
|
|
|
1953
1908
|
}
|
|
1954
1909
|
};
|
|
1955
1910
|
|
|
1956
|
-
// src/api/
|
|
1911
|
+
// src/api/initializeApplicationNativeAuthentication.ts
|
|
1912
|
+
var initializeApplicationNativeAuthentication = async ({
|
|
1913
|
+
url,
|
|
1914
|
+
baseUrl,
|
|
1915
|
+
payload,
|
|
1916
|
+
...requestConfig
|
|
1917
|
+
}) => {
|
|
1918
|
+
if (!payload) {
|
|
1919
|
+
throw new AsgardeoAPIError(
|
|
1920
|
+
"Authorization payload is required",
|
|
1921
|
+
"initializeApplicationNativeAuthentication-ValidationError-002",
|
|
1922
|
+
"javascript",
|
|
1923
|
+
400,
|
|
1924
|
+
"If an authorization payload is not provided, the request cannot be constructed correctly."
|
|
1925
|
+
);
|
|
1926
|
+
}
|
|
1927
|
+
const searchParams = new URLSearchParams();
|
|
1928
|
+
Object.entries(payload).forEach(([key, value]) => {
|
|
1929
|
+
if (value !== void 0 && value !== null) {
|
|
1930
|
+
searchParams.append(key, String(value));
|
|
1931
|
+
}
|
|
1932
|
+
});
|
|
1933
|
+
const { headers: customHeaders, ...otherConfig } = requestConfig;
|
|
1934
|
+
const response = await fetch(url ?? `${baseUrl}/oauth2/authorize`, {
|
|
1935
|
+
method: requestConfig.method || "POST",
|
|
1936
|
+
headers: {
|
|
1937
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
1938
|
+
Accept: "application/json",
|
|
1939
|
+
...customHeaders
|
|
1940
|
+
},
|
|
1941
|
+
body: searchParams.toString(),
|
|
1942
|
+
...otherConfig
|
|
1943
|
+
});
|
|
1944
|
+
if (!response.ok) {
|
|
1945
|
+
const errorText = await response.text();
|
|
1946
|
+
throw new AsgardeoAPIError(
|
|
1947
|
+
`Authorization request failed: ${errorText}`,
|
|
1948
|
+
"initializeApplicationNativeAuthentication-ResponseError-001",
|
|
1949
|
+
"javascript",
|
|
1950
|
+
response.status,
|
|
1951
|
+
response.statusText
|
|
1952
|
+
);
|
|
1953
|
+
}
|
|
1954
|
+
return await response.json();
|
|
1955
|
+
};
|
|
1956
|
+
var initializeApplicationNativeAuthentication_default = initializeApplicationNativeAuthentication;
|
|
1957
|
+
|
|
1958
|
+
// src/api/handleApplicationNativeAuthentication.ts
|
|
1959
|
+
var handleApplicationNativeAuthentication = async ({
|
|
1960
|
+
url,
|
|
1961
|
+
baseUrl,
|
|
1962
|
+
payload,
|
|
1963
|
+
...requestConfig
|
|
1964
|
+
}) => {
|
|
1965
|
+
if (!payload) {
|
|
1966
|
+
throw new AsgardeoAPIError(
|
|
1967
|
+
"Authorization payload is required",
|
|
1968
|
+
"handleApplicationNativeAuthentication-ValidationError-002",
|
|
1969
|
+
"javascript",
|
|
1970
|
+
400,
|
|
1971
|
+
"If an authorization payload is not provided, the request cannot be constructed correctly."
|
|
1972
|
+
);
|
|
1973
|
+
}
|
|
1974
|
+
const { headers: customHeaders, ...otherConfig } = requestConfig;
|
|
1975
|
+
const response = await fetch(url ?? `${baseUrl}/oauth2/authn`, {
|
|
1976
|
+
method: requestConfig.method || "POST",
|
|
1977
|
+
headers: {
|
|
1978
|
+
"Content-Type": "application/json",
|
|
1979
|
+
Accept: "application/json",
|
|
1980
|
+
...customHeaders
|
|
1981
|
+
},
|
|
1982
|
+
body: JSON.stringify(payload),
|
|
1983
|
+
...otherConfig
|
|
1984
|
+
});
|
|
1985
|
+
if (!response.ok) {
|
|
1986
|
+
const errorText = await response.text();
|
|
1987
|
+
throw new AsgardeoAPIError(
|
|
1988
|
+
`Authorization request failed: ${errorText}`,
|
|
1989
|
+
"initializeApplicationNativeAuthentication-ResponseError-001",
|
|
1990
|
+
"javascript",
|
|
1991
|
+
response.status,
|
|
1992
|
+
response.statusText
|
|
1993
|
+
);
|
|
1994
|
+
}
|
|
1995
|
+
return await response.json();
|
|
1996
|
+
};
|
|
1997
|
+
var handleApplicationNativeAuthentication_default = handleApplicationNativeAuthentication;
|
|
1998
|
+
|
|
1999
|
+
// src/api/getUserInfo.ts
|
|
1957
2000
|
var getUserInfo = async ({ url, ...requestConfig }) => {
|
|
1958
2001
|
try {
|
|
1959
2002
|
new URL(url);
|
|
@@ -1988,37 +2031,60 @@ var getUserInfo = async ({ url, ...requestConfig }) => {
|
|
|
1988
2031
|
};
|
|
1989
2032
|
var getUserInfo_default = getUserInfo;
|
|
1990
2033
|
|
|
1991
|
-
// src/
|
|
1992
|
-
var
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
writable: true
|
|
2009
|
-
});
|
|
2010
|
-
}
|
|
2011
|
-
/**
|
|
2012
|
-
* Returns a string representation of the runtime error
|
|
2013
|
-
* @returns Formatted error string with name, code, details, and message
|
|
2014
|
-
*/
|
|
2015
|
-
toString() {
|
|
2016
|
-
const details = this.details ? `
|
|
2017
|
-
Details: ${JSON.stringify(this.details, null, 2)}` : "";
|
|
2018
|
-
return `[${this.name}] (code="${this.code}")${details}
|
|
2019
|
-
Message: ${this.message}`;
|
|
2034
|
+
// src/constants/ApplicationNativeAuthenticationConstants.ts
|
|
2035
|
+
var ApplicationNativeAuthenticationConstants = {
|
|
2036
|
+
SupportedAuthenticators: {
|
|
2037
|
+
IdentifierFirst: "SWRlbnRpZmllckV4ZWN1dG9yOkxPQ0FM",
|
|
2038
|
+
EmailOtp: "ZW1haWwtb3RwLWF1dGhlbnRpY2F0b3I6TE9DQUw",
|
|
2039
|
+
Totp: "dG90cDpMT0NBTA",
|
|
2040
|
+
UsernamePassword: "QmFzaWNBdXRoZW50aWNhdG9yOkxPQ0FM",
|
|
2041
|
+
PushNotification: "cHVzaC1ub3RpZmljYXRpb24tYXV0aGVudGljYXRvcjpMT0NBTA",
|
|
2042
|
+
Passkey: "RklET0F1dGhlbnRpY2F0b3I6TE9DQUw",
|
|
2043
|
+
SmsOtp: "c21zLW90cC1hdXRoZW50aWNhdG9yOkxPQ0FM",
|
|
2044
|
+
MagicLink: "TWFnaWNMaW5rQXV0aGVudGljYXRvcjpMT0NBTA",
|
|
2045
|
+
Google: "R29vZ2xlT0lEQ0F1dGhlbnRpY2F0b3I6R29vZ2xl",
|
|
2046
|
+
GitHub: "R2l0aHViQXV0aGVudGljYXRvcjpHaXRIdWI",
|
|
2047
|
+
Microsoft: "T3BlbklEQ29ubmVjdEF1dGhlbnRpY2F0b3I6TWljcm9zb2Z0",
|
|
2048
|
+
Facebook: "RmFjZWJvb2tBdXRoZW50aWNhdG9yOkZhY2Vib29r",
|
|
2049
|
+
LinkedIn: "TGlua2VkSW5PSURDOkxpbmtlZElu",
|
|
2050
|
+
SignInWithEthereum: "T3BlbklEQ29ubmVjdEF1dGhlbnRpY2F0b3I6U2lnbiBJbiBXaXRoIEV0aGVyZXVt"
|
|
2020
2051
|
}
|
|
2021
2052
|
};
|
|
2053
|
+
var ApplicationNativeAuthenticationConstants_default = ApplicationNativeAuthenticationConstants;
|
|
2054
|
+
|
|
2055
|
+
// src/models/application-native-authentication.ts
|
|
2056
|
+
var ApplicationNativeAuthenticationFlowStatus = /* @__PURE__ */ ((ApplicationNativeAuthenticationFlowStatus2) => {
|
|
2057
|
+
ApplicationNativeAuthenticationFlowStatus2["SuccessCompleted"] = "SUCCESS_COMPLETED";
|
|
2058
|
+
ApplicationNativeAuthenticationFlowStatus2["FailCompleted"] = "FAIL_COMPLETED";
|
|
2059
|
+
ApplicationNativeAuthenticationFlowStatus2["FailIncomplete"] = "FAIL_INCOMPLETE";
|
|
2060
|
+
ApplicationNativeAuthenticationFlowStatus2["Incomplete"] = "INCOMPLETE";
|
|
2061
|
+
return ApplicationNativeAuthenticationFlowStatus2;
|
|
2062
|
+
})(ApplicationNativeAuthenticationFlowStatus || {});
|
|
2063
|
+
var ApplicationNativeAuthenticationFlowType = /* @__PURE__ */ ((ApplicationNativeAuthenticationFlowType2) => {
|
|
2064
|
+
ApplicationNativeAuthenticationFlowType2["Authentication"] = "AUTHENTICATION";
|
|
2065
|
+
return ApplicationNativeAuthenticationFlowType2;
|
|
2066
|
+
})(ApplicationNativeAuthenticationFlowType || {});
|
|
2067
|
+
var ApplicationNativeAuthenticationStepType = /* @__PURE__ */ ((ApplicationNativeAuthenticationStepType2) => {
|
|
2068
|
+
ApplicationNativeAuthenticationStepType2["AuthenticatorPrompt"] = "AUTHENTICATOR_PROMPT";
|
|
2069
|
+
ApplicationNativeAuthenticationStepType2["MultOptionsPrompt"] = "MULTI_OPTIONS_PROMPT";
|
|
2070
|
+
return ApplicationNativeAuthenticationStepType2;
|
|
2071
|
+
})(ApplicationNativeAuthenticationStepType || {});
|
|
2072
|
+
var ApplicationNativeAuthenticationAuthenticatorParamType = /* @__PURE__ */ ((ApplicationNativeAuthenticationAuthenticatorParamType2) => {
|
|
2073
|
+
ApplicationNativeAuthenticationAuthenticatorParamType2["String"] = "STRING";
|
|
2074
|
+
ApplicationNativeAuthenticationAuthenticatorParamType2["Integer"] = "INTEGER";
|
|
2075
|
+
ApplicationNativeAuthenticationAuthenticatorParamType2["MultiValued"] = "MULTI_VALUED";
|
|
2076
|
+
return ApplicationNativeAuthenticationAuthenticatorParamType2;
|
|
2077
|
+
})(ApplicationNativeAuthenticationAuthenticatorParamType || {});
|
|
2078
|
+
var ApplicationNativeAuthenticationAuthenticatorKnownIdPType = /* @__PURE__ */ ((ApplicationNativeAuthenticationAuthenticatorKnownIdPType2) => {
|
|
2079
|
+
ApplicationNativeAuthenticationAuthenticatorKnownIdPType2["Local"] = "LOCAL";
|
|
2080
|
+
return ApplicationNativeAuthenticationAuthenticatorKnownIdPType2;
|
|
2081
|
+
})(ApplicationNativeAuthenticationAuthenticatorKnownIdPType || {});
|
|
2082
|
+
var ApplicationNativeAuthenticationAuthenticatorPromptType = /* @__PURE__ */ ((ApplicationNativeAuthenticationAuthenticatorPromptType2) => {
|
|
2083
|
+
ApplicationNativeAuthenticationAuthenticatorPromptType2["UserPrompt"] = "USER_PROMPT";
|
|
2084
|
+
ApplicationNativeAuthenticationAuthenticatorPromptType2["InternalPrompt"] = "INTERNAL_PROMPT";
|
|
2085
|
+
ApplicationNativeAuthenticationAuthenticatorPromptType2["RedirectionPrompt"] = "REDIRECTION_PROMPT";
|
|
2086
|
+
return ApplicationNativeAuthenticationAuthenticatorPromptType2;
|
|
2087
|
+
})(ApplicationNativeAuthenticationAuthenticatorPromptType || {});
|
|
2022
2088
|
|
|
2023
2089
|
// src/models/scim2-schema.ts
|
|
2024
2090
|
var WellKnownSchemaIds = /* @__PURE__ */ ((WellKnownSchemaIds2) => {
|
|
@@ -2030,6 +2096,22 @@ var WellKnownSchemaIds = /* @__PURE__ */ ((WellKnownSchemaIds2) => {
|
|
|
2030
2096
|
return WellKnownSchemaIds2;
|
|
2031
2097
|
})(WellKnownSchemaIds || {});
|
|
2032
2098
|
|
|
2099
|
+
// src/models/field.ts
|
|
2100
|
+
var FieldType = /* @__PURE__ */ ((FieldType2) => {
|
|
2101
|
+
FieldType2["Text"] = "TEXT";
|
|
2102
|
+
FieldType2["Password"] = "PASSWORD";
|
|
2103
|
+
FieldType2["Email"] = "EMAIL";
|
|
2104
|
+
FieldType2["Number"] = "NUMBER";
|
|
2105
|
+
FieldType2["Select"] = "SELECT";
|
|
2106
|
+
FieldType2["Checkbox"] = "CHECKBOX";
|
|
2107
|
+
FieldType2["Radio"] = "RADIO";
|
|
2108
|
+
FieldType2["Otp"] = "OTP";
|
|
2109
|
+
FieldType2["Date"] = "DATE";
|
|
2110
|
+
FieldType2["Time"] = "TIME";
|
|
2111
|
+
FieldType2["Textarea"] = "TEXTAREA";
|
|
2112
|
+
return FieldType2;
|
|
2113
|
+
})(FieldType || {});
|
|
2114
|
+
|
|
2033
2115
|
// src/AsgardeoJavaScriptClient.ts
|
|
2034
2116
|
var AsgardeoJavaScriptClient = class {
|
|
2035
2117
|
};
|
|
@@ -2047,7 +2129,7 @@ var lightTheme = {
|
|
|
2047
2129
|
contrastText: "#ffffff"
|
|
2048
2130
|
},
|
|
2049
2131
|
background: {
|
|
2050
|
-
surface: "#
|
|
2132
|
+
surface: "#ffffff",
|
|
2051
2133
|
disabled: "#f0f0f0",
|
|
2052
2134
|
body: {
|
|
2053
2135
|
main: "#1a1a1a"
|
|
@@ -2057,7 +2139,6 @@ var lightTheme = {
|
|
|
2057
2139
|
main: "#d32f2f",
|
|
2058
2140
|
contrastText: "#ffffff"
|
|
2059
2141
|
},
|
|
2060
|
-
surface: "#f5f5f5",
|
|
2061
2142
|
text: {
|
|
2062
2143
|
primary: "#1a1a1a",
|
|
2063
2144
|
secondary: "#666666"
|
|
@@ -2094,7 +2175,6 @@ var darkTheme = {
|
|
|
2094
2175
|
main: "#d32f2f",
|
|
2095
2176
|
contrastText: "#ffffff"
|
|
2096
2177
|
},
|
|
2097
|
-
surface: "#2d2d2d",
|
|
2098
2178
|
text: {
|
|
2099
2179
|
primary: "#ffffff",
|
|
2100
2180
|
secondary: "#b3b3b3"
|
|
@@ -2121,7 +2201,6 @@ var toCssVariables = (theme) => {
|
|
|
2121
2201
|
cssVars["--asgardeo-color-background-body-main"] = theme.colors.background.body.main;
|
|
2122
2202
|
cssVars["--asgardeo-color-error-main"] = theme.colors.error.main;
|
|
2123
2203
|
cssVars["--asgardeo-color-error-contrastText"] = theme.colors.error.contrastText;
|
|
2124
|
-
cssVars["--asgardeo-color-surface"] = theme.colors.surface;
|
|
2125
2204
|
cssVars["--asgardeo-color-text-primary"] = theme.colors.text.primary;
|
|
2126
2205
|
cssVars["--asgardeo-color-text-secondary"] = theme.colors.text.secondary;
|
|
2127
2206
|
cssVars["--asgardeo-color-border"] = theme.colors.border;
|
|
@@ -2160,27 +2239,326 @@ var createTheme = (config = {}, isDark = false) => {
|
|
|
2160
2239
|
};
|
|
2161
2240
|
var createTheme_default = createTheme;
|
|
2162
2241
|
|
|
2242
|
+
// src/utils/deepMerge.ts
|
|
2243
|
+
var isPlainObject = (value) => {
|
|
2244
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) && !(value instanceof Date) && !(value instanceof RegExp) && Object.prototype.toString.call(value) === "[object Object]";
|
|
2245
|
+
};
|
|
2246
|
+
var deepMerge = (target, ...sources) => {
|
|
2247
|
+
if (!target || typeof target !== "object") {
|
|
2248
|
+
throw new Error("Target must be an object");
|
|
2249
|
+
}
|
|
2250
|
+
const result = { ...target };
|
|
2251
|
+
sources.forEach((source) => {
|
|
2252
|
+
if (!source || typeof source !== "object") {
|
|
2253
|
+
return;
|
|
2254
|
+
}
|
|
2255
|
+
Object.keys(source).forEach((key) => {
|
|
2256
|
+
const sourceValue = source[key];
|
|
2257
|
+
const targetValue = result[key];
|
|
2258
|
+
if (isPlainObject(sourceValue) && isPlainObject(targetValue)) {
|
|
2259
|
+
result[key] = deepMerge(targetValue, sourceValue);
|
|
2260
|
+
} else if (sourceValue !== void 0) {
|
|
2261
|
+
result[key] = sourceValue;
|
|
2262
|
+
}
|
|
2263
|
+
});
|
|
2264
|
+
});
|
|
2265
|
+
return result;
|
|
2266
|
+
};
|
|
2267
|
+
var deepMerge_default = deepMerge;
|
|
2268
|
+
|
|
2269
|
+
// src/utils/flattenUserSchema.ts
|
|
2270
|
+
var flattenUserSchema = (schemas) => {
|
|
2271
|
+
const flattenedAttributes = [];
|
|
2272
|
+
schemas.forEach((schema) => {
|
|
2273
|
+
if (schema.attributes && Array.isArray(schema.attributes)) {
|
|
2274
|
+
schema.attributes.forEach((attribute) => {
|
|
2275
|
+
if (attribute.subAttributes && Array.isArray(attribute.subAttributes)) {
|
|
2276
|
+
attribute.subAttributes.forEach((subAttribute) => {
|
|
2277
|
+
flattenedAttributes.push({
|
|
2278
|
+
...subAttribute,
|
|
2279
|
+
name: `${attribute.name}.${subAttribute.name}`,
|
|
2280
|
+
schemaId: schema.id
|
|
2281
|
+
});
|
|
2282
|
+
});
|
|
2283
|
+
} else {
|
|
2284
|
+
flattenedAttributes.push({
|
|
2285
|
+
...attribute,
|
|
2286
|
+
schemaId: schema.id
|
|
2287
|
+
});
|
|
2288
|
+
}
|
|
2289
|
+
});
|
|
2290
|
+
}
|
|
2291
|
+
});
|
|
2292
|
+
return flattenedAttributes;
|
|
2293
|
+
};
|
|
2294
|
+
var flattenUserSchema_default = flattenUserSchema;
|
|
2295
|
+
|
|
2296
|
+
// src/utils/get.ts
|
|
2297
|
+
var get = (object, path, defaultValue) => {
|
|
2298
|
+
if (!object || !path) return defaultValue;
|
|
2299
|
+
const pathArray = Array.isArray(path) ? path : path.split(".");
|
|
2300
|
+
const result = pathArray.reduce((current, key) => {
|
|
2301
|
+
return current?.[key];
|
|
2302
|
+
}, object);
|
|
2303
|
+
return result !== void 0 ? result : defaultValue;
|
|
2304
|
+
};
|
|
2305
|
+
var get_default = get;
|
|
2306
|
+
|
|
2307
|
+
// src/utils/set.ts
|
|
2308
|
+
var set = (object, path, value) => {
|
|
2309
|
+
if (!object || !path) return object;
|
|
2310
|
+
const pathArray = Array.isArray(path) ? path : path.split(".");
|
|
2311
|
+
const lastIndex = pathArray.length - 1;
|
|
2312
|
+
pathArray.reduce((current, key, index) => {
|
|
2313
|
+
if (index === lastIndex) {
|
|
2314
|
+
current[key] = value;
|
|
2315
|
+
} else {
|
|
2316
|
+
if (!(key in current) || typeof current[key] !== "object" || current[key] === null) {
|
|
2317
|
+
const nextKey = pathArray[index + 1];
|
|
2318
|
+
current[key] = /^\d+$/.test(nextKey) ? [] : {};
|
|
2319
|
+
}
|
|
2320
|
+
}
|
|
2321
|
+
return current[key];
|
|
2322
|
+
}, object);
|
|
2323
|
+
return object;
|
|
2324
|
+
};
|
|
2325
|
+
var set_default = set;
|
|
2326
|
+
|
|
2327
|
+
// src/utils/generateUserProfile.ts
|
|
2328
|
+
var generateUserProfile = (meResponse, processedSchemas) => {
|
|
2329
|
+
const profile = {};
|
|
2330
|
+
processedSchemas.forEach((schema) => {
|
|
2331
|
+
const { name, type, multiValued } = schema;
|
|
2332
|
+
if (!name) return;
|
|
2333
|
+
let value = get_default(meResponse, name);
|
|
2334
|
+
if (value !== void 0) {
|
|
2335
|
+
if (multiValued && !Array.isArray(value)) {
|
|
2336
|
+
value = [value];
|
|
2337
|
+
}
|
|
2338
|
+
} else {
|
|
2339
|
+
if (multiValued) {
|
|
2340
|
+
value = void 0;
|
|
2341
|
+
} else if (type === "STRING") {
|
|
2342
|
+
value = "";
|
|
2343
|
+
} else {
|
|
2344
|
+
value = void 0;
|
|
2345
|
+
}
|
|
2346
|
+
}
|
|
2347
|
+
set_default(profile, name, value);
|
|
2348
|
+
});
|
|
2349
|
+
return profile;
|
|
2350
|
+
};
|
|
2351
|
+
var generateUserProfile_default = generateUserProfile;
|
|
2352
|
+
|
|
2353
|
+
// src/utils/getLatestStateParam.ts
|
|
2354
|
+
var getLatestPkceStorageKey = (tempStore) => {
|
|
2355
|
+
const keys = [];
|
|
2356
|
+
Object.keys(tempStore).forEach((key) => {
|
|
2357
|
+
if (key.startsWith(PKCEConstants_default.Storage.StorageKeys.CODE_VERIFIER)) {
|
|
2358
|
+
keys.push(key);
|
|
2359
|
+
}
|
|
2360
|
+
});
|
|
2361
|
+
const lastKey = keys.sort().pop();
|
|
2362
|
+
return lastKey ?? null;
|
|
2363
|
+
};
|
|
2364
|
+
var getLatestStateParam = (tempStore, state) => {
|
|
2365
|
+
const latestPkceKey = getLatestPkceStorageKey(tempStore);
|
|
2366
|
+
if (!latestPkceKey) {
|
|
2367
|
+
return null;
|
|
2368
|
+
}
|
|
2369
|
+
return generateStateParamForRequestCorrelation_default(latestPkceKey, state);
|
|
2370
|
+
};
|
|
2371
|
+
var getLatestStateParam_default = getLatestStateParam;
|
|
2372
|
+
|
|
2373
|
+
// src/utils/generateFlattenedUserProfile.ts
|
|
2374
|
+
var generateFlattenedUserProfile = (meResponse, processedSchemas) => {
|
|
2375
|
+
const profile = {};
|
|
2376
|
+
const allSchemaNames = processedSchemas.map((schema) => schema.name).filter(Boolean);
|
|
2377
|
+
processedSchemas.forEach((schema) => {
|
|
2378
|
+
const { name, type, multiValued } = schema;
|
|
2379
|
+
if (!name) return;
|
|
2380
|
+
const hasChildProperties = allSchemaNames.some(
|
|
2381
|
+
(schemaName) => schemaName !== name && schemaName.startsWith(name + ".")
|
|
2382
|
+
);
|
|
2383
|
+
if (hasChildProperties) {
|
|
2384
|
+
return;
|
|
2385
|
+
}
|
|
2386
|
+
let value = get_default(meResponse, name);
|
|
2387
|
+
if (value !== void 0) {
|
|
2388
|
+
if (multiValued && !Array.isArray(value)) {
|
|
2389
|
+
value = [value];
|
|
2390
|
+
}
|
|
2391
|
+
} else {
|
|
2392
|
+
if (multiValued) {
|
|
2393
|
+
value = void 0;
|
|
2394
|
+
} else if (type === "STRING") {
|
|
2395
|
+
value = "";
|
|
2396
|
+
} else {
|
|
2397
|
+
value = void 0;
|
|
2398
|
+
}
|
|
2399
|
+
}
|
|
2400
|
+
profile[name] = value;
|
|
2401
|
+
});
|
|
2402
|
+
return profile;
|
|
2403
|
+
};
|
|
2404
|
+
var generateFlattenedUserProfile_default = generateFlattenedUserProfile;
|
|
2405
|
+
|
|
2406
|
+
// src/i18n/index.ts
|
|
2407
|
+
var i18n_exports = {};
|
|
2408
|
+
__export(i18n_exports, {
|
|
2409
|
+
en_US: () => en_US_default
|
|
2410
|
+
});
|
|
2411
|
+
|
|
2412
|
+
// src/i18n/en-US.ts
|
|
2413
|
+
var translations = {
|
|
2414
|
+
/* |---------------------------------------------------------------| */
|
|
2415
|
+
/* | Elements | */
|
|
2416
|
+
/* |---------------------------------------------------------------| */
|
|
2417
|
+
//* Buttons */
|
|
2418
|
+
"elements.buttons.signIn": "Sign In",
|
|
2419
|
+
"elements.buttons.signOut": "Sign Out",
|
|
2420
|
+
"elements.buttons.signUp": "Sign Up",
|
|
2421
|
+
"elements.buttons.facebook": "Continue with Facebook",
|
|
2422
|
+
"elements.buttons.google": "Continue with Google",
|
|
2423
|
+
"elements.buttons.github": "Continue with GitHub",
|
|
2424
|
+
"elements.buttons.microsoft": "Continue with Microsoft",
|
|
2425
|
+
"elements.buttons.linkedin": "Continue with LinkedIn",
|
|
2426
|
+
"elements.buttons.ethereum": "Continue with Sign In Ethereum",
|
|
2427
|
+
"elements.buttons.multi.option": "Continue with {connection}",
|
|
2428
|
+
"elements.buttons.social": "Continue with {connection}",
|
|
2429
|
+
/* Fields */
|
|
2430
|
+
"elements.fields.placeholder": "Enter your {field}",
|
|
2431
|
+
/* |---------------------------------------------------------------| */
|
|
2432
|
+
/* | Widgets | */
|
|
2433
|
+
/* |---------------------------------------------------------------| */
|
|
2434
|
+
/* Base Sign In */
|
|
2435
|
+
"signin.title": "Sign In",
|
|
2436
|
+
/* Email OTP */
|
|
2437
|
+
"email.otp.title": "OTP Verification",
|
|
2438
|
+
"email.otp.subtitle": "Enter the code sent to your email address.",
|
|
2439
|
+
"email.otp.submit.button": "Continue",
|
|
2440
|
+
/* Identifier First */
|
|
2441
|
+
"identifier.first.title": "Sign In",
|
|
2442
|
+
"identifier.first.subtitle": "Enter your username or email address.",
|
|
2443
|
+
"identifier.first.submit.button": "Continue",
|
|
2444
|
+
/* SMS OTP */
|
|
2445
|
+
"sms.otp.title": "OTP Verification",
|
|
2446
|
+
"sms.otp.subtitle": "Enter the code sent to your phone number.",
|
|
2447
|
+
"sms.otp.submit.button": "Continue",
|
|
2448
|
+
/* TOTP */
|
|
2449
|
+
"totp.title": "Verify Your Identity",
|
|
2450
|
+
"totp.subtitle": "Enter the code from your authenticator app.",
|
|
2451
|
+
"totp.submit.button": "Continue",
|
|
2452
|
+
/* Username Password */
|
|
2453
|
+
"username.password.submit.button": "Continue",
|
|
2454
|
+
"username.password.title": "Sign In",
|
|
2455
|
+
"username.password.subtitle": "Enter your username and password to continue.",
|
|
2456
|
+
/* |---------------------------------------------------------------| */
|
|
2457
|
+
/* | Messages | */
|
|
2458
|
+
/* |---------------------------------------------------------------| */
|
|
2459
|
+
"messages.loading": "Loading...",
|
|
2460
|
+
/* |---------------------------------------------------------------| */
|
|
2461
|
+
/* | Errors | */
|
|
2462
|
+
/* |---------------------------------------------------------------| */
|
|
2463
|
+
"errors.title": "Error",
|
|
2464
|
+
"errors.sign.in.initialization": "An error occurred while initializing. Please try again later.",
|
|
2465
|
+
"errors.sign.in.flow.failure": "An error occurred during the sign-in flow. Please try again later.",
|
|
2466
|
+
"errors.sign.in.flow.completion.failure": "An error occurred while completing the sign-in flow. Please try again later.",
|
|
2467
|
+
"errors.sign.in.flow.passkeys.failure": "An error occurred while signing in with passkeys. Please try again later.",
|
|
2468
|
+
"errors.sign.in.flow.passkeys.completion.failure": "An error occurred while completing the passkeys sign-in flow. Please try again later."
|
|
2469
|
+
};
|
|
2470
|
+
var metadata = {
|
|
2471
|
+
localeCode: "en-US",
|
|
2472
|
+
countryCode: "US",
|
|
2473
|
+
languageCode: "en",
|
|
2474
|
+
displayName: "English (United States)",
|
|
2475
|
+
direction: "ltr"
|
|
2476
|
+
};
|
|
2477
|
+
var en_US = {
|
|
2478
|
+
metadata,
|
|
2479
|
+
translations
|
|
2480
|
+
};
|
|
2481
|
+
var en_US_default = en_US;
|
|
2482
|
+
|
|
2483
|
+
// src/utils/getI18nBundles.ts
|
|
2484
|
+
var getI18nBundles = () => {
|
|
2485
|
+
return i18n_exports;
|
|
2486
|
+
};
|
|
2487
|
+
var getI18nBundles_default = getI18nBundles;
|
|
2488
|
+
|
|
2163
2489
|
// src/utils/removeTrailingSlash.ts
|
|
2164
2490
|
var removeTrailingSlash = (path) => path.endsWith("/") ? path.slice(0, -1) : path;
|
|
2165
2491
|
var removeTrailingSlash_default = removeTrailingSlash;
|
|
2492
|
+
|
|
2493
|
+
// src/utils/resolveFieldType.ts
|
|
2494
|
+
var resolveFieldType = (field) => {
|
|
2495
|
+
if (field.type === "STRING" /* String */) {
|
|
2496
|
+
if (field.param === "OTPCode" /* Otp */) {
|
|
2497
|
+
return "OTP" /* Otp */;
|
|
2498
|
+
} else if (field?.confidential) {
|
|
2499
|
+
return "PASSWORD" /* Password */;
|
|
2500
|
+
}
|
|
2501
|
+
return "TEXT" /* Text */;
|
|
2502
|
+
}
|
|
2503
|
+
throw new AsgardeoRuntimeError(
|
|
2504
|
+
"Field type is not supported: " + field.type,
|
|
2505
|
+
"resolveFieldType-Invalid-001",
|
|
2506
|
+
"javascript",
|
|
2507
|
+
"The provided field type is not supported. Please check the field configuration."
|
|
2508
|
+
);
|
|
2509
|
+
};
|
|
2510
|
+
var resolveFieldType_default = resolveFieldType;
|
|
2511
|
+
|
|
2512
|
+
// src/utils/resolveFieldName.ts
|
|
2513
|
+
var resolveFieldName = (field) => {
|
|
2514
|
+
if (field.param) {
|
|
2515
|
+
return field.param;
|
|
2516
|
+
}
|
|
2517
|
+
throw new AsgardeoRuntimeError(
|
|
2518
|
+
"Field name is not supported: ",
|
|
2519
|
+
"resolveFieldName-Invalid-001",
|
|
2520
|
+
"javascript",
|
|
2521
|
+
"The provided field name is not supported. Please check the field configuration."
|
|
2522
|
+
);
|
|
2523
|
+
};
|
|
2524
|
+
var resolveFieldName_default = resolveFieldName;
|
|
2166
2525
|
export {
|
|
2167
|
-
|
|
2526
|
+
ApplicationNativeAuthenticationAuthenticatorKnownIdPType,
|
|
2527
|
+
ApplicationNativeAuthenticationAuthenticatorParamType,
|
|
2528
|
+
ApplicationNativeAuthenticationAuthenticatorPromptType,
|
|
2529
|
+
ApplicationNativeAuthenticationConstants_default as ApplicationNativeAuthenticationConstants,
|
|
2530
|
+
ApplicationNativeAuthenticationFlowStatus,
|
|
2531
|
+
ApplicationNativeAuthenticationFlowType,
|
|
2532
|
+
ApplicationNativeAuthenticationStepType,
|
|
2168
2533
|
AsgardeoAPIError,
|
|
2169
2534
|
AsgardeoAuthClient,
|
|
2170
2535
|
AsgardeoAuthException,
|
|
2171
2536
|
AsgardeoError,
|
|
2172
2537
|
AsgardeoJavaScriptClient_default as AsgardeoJavaScriptClient,
|
|
2173
2538
|
AsgardeoRuntimeError,
|
|
2174
|
-
|
|
2539
|
+
FieldType,
|
|
2175
2540
|
IsomorphicCrypto,
|
|
2176
2541
|
OIDCRequestConstants_default as OIDCRequestConstants,
|
|
2177
|
-
|
|
2542
|
+
StorageManager_default as StorageManager,
|
|
2178
2543
|
TokenConstants_default as TokenConstants,
|
|
2179
2544
|
WellKnownSchemaIds,
|
|
2180
2545
|
createTheme_default as createTheme,
|
|
2546
|
+
deepMerge_default as deepMerge,
|
|
2181
2547
|
extractPkceStorageKeyFromState_default as extractPkceStorageKeyFromState,
|
|
2182
2548
|
extractUserClaimsFromIdToken_default as extractUserClaimsFromIdToken,
|
|
2549
|
+
flattenUserSchema_default as flattenUserSchema,
|
|
2550
|
+
generateFlattenedUserProfile_default as generateFlattenedUserProfile,
|
|
2551
|
+
generateUserProfile_default as generateUserProfile,
|
|
2552
|
+
get_default as get,
|
|
2553
|
+
getI18nBundles_default as getI18nBundles,
|
|
2554
|
+
getLatestStateParam_default as getLatestStateParam,
|
|
2183
2555
|
getUserInfo_default as getUserInfo,
|
|
2184
|
-
|
|
2556
|
+
handleApplicationNativeAuthentication_default as handleApplicationNativeAuthentication,
|
|
2557
|
+
initializeApplicationNativeAuthentication_default as initializeApplicationNativeAuthentication,
|
|
2558
|
+
processOpenIDScopes_default as processOpenIDScopes,
|
|
2559
|
+
removeTrailingSlash_default as removeTrailingSlash,
|
|
2560
|
+
resolveFieldName_default as resolveFieldName,
|
|
2561
|
+
resolveFieldType_default as resolveFieldType,
|
|
2562
|
+
set_default as set
|
|
2185
2563
|
};
|
|
2186
2564
|
//# sourceMappingURL=index.js.map
|