@asgardeo/javascript 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +57 -0
- package/dist/AsgardeoJavaScriptClient.d.ts +81 -0
- package/dist/IsomorphicCrypto.d.ts +73 -0
- package/dist/__legacy__/client.d.ts +488 -0
- package/dist/__legacy__/core/authentication-core.d.ts +51 -0
- package/dist/__legacy__/core/index.d.ts +18 -0
- package/dist/__legacy__/data/data-layer.d.ts +64 -0
- package/dist/__legacy__/data/index.d.ts +18 -0
- package/dist/__legacy__/exception/exception.d.ts +23 -0
- package/dist/__legacy__/exception/index.d.ts +18 -0
- package/dist/__legacy__/helpers/authentication-helper.d.ts +37 -0
- package/dist/__legacy__/helpers/index.d.ts +18 -0
- package/dist/__legacy__/models/authorization-url.d.ts +23 -0
- package/dist/__legacy__/models/client-config.d.ts +60 -0
- package/dist/__legacy__/models/custom-grant.d.ts +26 -0
- package/dist/__legacy__/models/data.d.ts +27 -0
- package/dist/__legacy__/models/fetch.d.ts +55 -0
- package/dist/__legacy__/models/index.d.ts +23 -0
- package/dist/__legacy__/models/user.d.ts +85 -0
- package/dist/api/oidc/getUserInfo.d.ts +37 -0
- package/dist/cjs/index.js +2227 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/constants/OIDCDiscoveryConstants.d.ts +153 -0
- package/dist/constants/OIDCRequestConstants.d.ts +66 -0
- package/dist/constants/PKCEConstants.d.ts +58 -0
- package/dist/constants/ScopeConstants.d.ts +45 -0
- package/dist/constants/TokenConstants.d.ts +76 -0
- package/dist/constants/TokenExchangeConstants.d.ts +68 -0
- package/dist/errors/AsgardeoAPIError.d.ts +52 -0
- package/dist/errors/AsgardeoError.d.ts +49 -0
- package/dist/errors/AsgardeoRuntimeError.d.ts +50 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.js +2186 -0
- package/dist/index.js.map +7 -0
- package/dist/models/client.d.ts +84 -0
- package/dist/models/config.d.ts +81 -0
- package/dist/models/crypto.d.ts +100 -0
- package/dist/models/id-token.d.ts +55 -0
- package/dist/models/oauth-response.d.ts +34 -0
- package/dist/models/oidc-discovery.d.ts +369 -0
- package/dist/models/oidc-endpoints.d.ts +70 -0
- package/dist/models/scim2-schema.d.ts +62 -0
- package/dist/models/store.d.ts +81 -0
- package/dist/models/token.d.ts +121 -0
- package/dist/models/user.d.ts +106 -0
- package/dist/models/utility-types.d.ts +20 -0
- package/dist/theme/createTheme.d.ts +21 -0
- package/dist/theme/types.d.ts +59 -0
- package/dist/utils/cryptoUtils.d.ts +0 -0
- package/dist/utils/extractPkceStorageKeyFromState.d.ts +32 -0
- package/dist/utils/extractTenantDomainFromIdTokenPayload.d.ts +31 -0
- package/dist/utils/extractUserClaimsFromIdToken.d.ts +44 -0
- package/dist/utils/generatePkceStorageKey.d.ts +34 -0
- package/dist/utils/generateStateParamForRequestCorrelation.d.ts +34 -0
- package/dist/utils/removeTrailingSlash.d.ts +31 -0
- package/package.json +61 -0
|
@@ -0,0 +1,2227 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
20
|
+
|
|
21
|
+
// src/index.ts
|
|
22
|
+
var index_exports = {};
|
|
23
|
+
__export(index_exports, {
|
|
24
|
+
ASGARDEO_SESSION_ACTIVE: () => ASGARDEO_SESSION_ACTIVE,
|
|
25
|
+
AsgardeoAPIError: () => AsgardeoAPIError,
|
|
26
|
+
AsgardeoAuthClient: () => AsgardeoAuthClient,
|
|
27
|
+
AsgardeoAuthException: () => AsgardeoAuthException,
|
|
28
|
+
AsgardeoError: () => AsgardeoError,
|
|
29
|
+
AsgardeoJavaScriptClient: () => AsgardeoJavaScriptClient_default,
|
|
30
|
+
AsgardeoRuntimeError: () => AsgardeoRuntimeError,
|
|
31
|
+
DataLayer: () => DataLayer,
|
|
32
|
+
IsomorphicCrypto: () => IsomorphicCrypto,
|
|
33
|
+
OIDCRequestConstants: () => OIDCRequestConstants_default,
|
|
34
|
+
ResponseMode: () => ResponseMode,
|
|
35
|
+
TokenConstants: () => TokenConstants_default,
|
|
36
|
+
WellKnownSchemaIds: () => WellKnownSchemaIds,
|
|
37
|
+
createTheme: () => createTheme_default,
|
|
38
|
+
extractPkceStorageKeyFromState: () => extractPkceStorageKeyFromState_default,
|
|
39
|
+
extractUserClaimsFromIdToken: () => extractUserClaimsFromIdToken_default,
|
|
40
|
+
getUserInfo: () => getUserInfo_default,
|
|
41
|
+
removeTrailingSlash: () => removeTrailingSlash_default
|
|
42
|
+
});
|
|
43
|
+
module.exports = __toCommonJS(index_exports);
|
|
44
|
+
|
|
45
|
+
// src/constants/PKCEConstants.ts
|
|
46
|
+
var PKCEConstants = {
|
|
47
|
+
/**
|
|
48
|
+
* Storage-related constants for managing PKCE state
|
|
49
|
+
*/
|
|
50
|
+
Storage: {
|
|
51
|
+
/**
|
|
52
|
+
* Collection of storage keys used in PKCE implementation
|
|
53
|
+
*/
|
|
54
|
+
StorageKeys: {
|
|
55
|
+
/**
|
|
56
|
+
* Key used to store the PKCE code verifier in temporary storage.
|
|
57
|
+
* The code verifier is a cryptographically random string that is
|
|
58
|
+
* used to generate the code challenge.
|
|
59
|
+
*/
|
|
60
|
+
CODE_VERIFIER: "pkce_code_verifier",
|
|
61
|
+
/**
|
|
62
|
+
* Separator used in storage keys to create unique identifiers
|
|
63
|
+
* by combining different parts of the key.
|
|
64
|
+
*/
|
|
65
|
+
SEPARATOR: "#"
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
var PKCEConstants_default = PKCEConstants;
|
|
70
|
+
|
|
71
|
+
// src/utils/extractPkceStorageKeyFromState.ts
|
|
72
|
+
var extractPkceStorageKeyFromState = (state) => {
|
|
73
|
+
const index = parseInt(state.split("request_")[1]);
|
|
74
|
+
return `${PKCEConstants_default.Storage.StorageKeys.CODE_VERIFIER}${PKCEConstants_default.Storage.StorageKeys.SEPARATOR}${index}`;
|
|
75
|
+
};
|
|
76
|
+
var extractPkceStorageKeyFromState_default = extractPkceStorageKeyFromState;
|
|
77
|
+
|
|
78
|
+
// src/utils/generateStateParamForRequestCorrelation.ts
|
|
79
|
+
var generateStateParamForRequestCorrelation = (pkceKey, state) => {
|
|
80
|
+
const index = parseInt(pkceKey.split(PKCEConstants_default.Storage.StorageKeys.SEPARATOR)[1]);
|
|
81
|
+
return state ? `${state}_request_${index}` : `request_${index}`;
|
|
82
|
+
};
|
|
83
|
+
var generateStateParamForRequestCorrelation_default = generateStateParamForRequestCorrelation;
|
|
84
|
+
|
|
85
|
+
// src/__legacy__/exception/exception.ts
|
|
86
|
+
var AsgardeoAuthException = class {
|
|
87
|
+
constructor(code, name, message) {
|
|
88
|
+
__publicField(this, "name");
|
|
89
|
+
__publicField(this, "code");
|
|
90
|
+
__publicField(this, "message");
|
|
91
|
+
this.message = message;
|
|
92
|
+
this.name = name;
|
|
93
|
+
this.code = code;
|
|
94
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
// src/utils/extractTenantDomainFromIdTokenPayload.ts
|
|
99
|
+
var extractTenantDomainFromIdTokenPayload = (payload, subjectSeparator = "@") => {
|
|
100
|
+
const uid = payload.sub;
|
|
101
|
+
if (!uid) return "";
|
|
102
|
+
const tokens = uid.split(subjectSeparator);
|
|
103
|
+
return tokens.length > 2 ? tokens[tokens.length - 1] : "";
|
|
104
|
+
};
|
|
105
|
+
var extractTenantDomainFromIdTokenPayload_default = extractTenantDomainFromIdTokenPayload;
|
|
106
|
+
|
|
107
|
+
// src/utils/extractUserClaimsFromIdToken.ts
|
|
108
|
+
var extractUserClaimsFromIdToken = (payload) => {
|
|
109
|
+
const filteredPayload = { ...payload };
|
|
110
|
+
const protocolClaims = [
|
|
111
|
+
"iss",
|
|
112
|
+
"aud",
|
|
113
|
+
"exp",
|
|
114
|
+
"iat",
|
|
115
|
+
"acr",
|
|
116
|
+
"amr",
|
|
117
|
+
"azp",
|
|
118
|
+
"auth_time",
|
|
119
|
+
"nonce",
|
|
120
|
+
"c_hash",
|
|
121
|
+
"at_hash",
|
|
122
|
+
"nbf",
|
|
123
|
+
"isk",
|
|
124
|
+
"sid",
|
|
125
|
+
"jti",
|
|
126
|
+
"sub"
|
|
127
|
+
];
|
|
128
|
+
protocolClaims.forEach((claim) => {
|
|
129
|
+
delete filteredPayload[claim];
|
|
130
|
+
});
|
|
131
|
+
const userClaims = {};
|
|
132
|
+
Object.entries(filteredPayload).forEach(([key, value]) => {
|
|
133
|
+
const camelCasedKey = key.split("_").map((part, i) => i === 0 ? part : part[0].toUpperCase() + part.slice(1)).join("");
|
|
134
|
+
userClaims[camelCasedKey] = value;
|
|
135
|
+
});
|
|
136
|
+
return userClaims;
|
|
137
|
+
};
|
|
138
|
+
var extractUserClaimsFromIdToken_default = extractUserClaimsFromIdToken;
|
|
139
|
+
|
|
140
|
+
// src/constants/ScopeConstants.ts
|
|
141
|
+
var ScopeConstants = {
|
|
142
|
+
/**
|
|
143
|
+
* The base OpenID Connect scope.
|
|
144
|
+
* Required for all OpenID Connect flows. Indicates that the client
|
|
145
|
+
* is initiating an OpenID Connect authentication request.
|
|
146
|
+
*/
|
|
147
|
+
OPENID: "openid"
|
|
148
|
+
};
|
|
149
|
+
var ScopeConstants_default = ScopeConstants;
|
|
150
|
+
|
|
151
|
+
// src/constants/OIDCDiscoveryConstants.ts
|
|
152
|
+
var OIDCDiscoveryConstants = {
|
|
153
|
+
/**
|
|
154
|
+
* Collection of standard OIDC endpoint paths used for authentication flows.
|
|
155
|
+
* These endpoints are relative paths that should be appended to the base URL
|
|
156
|
+
* of your identity provider.
|
|
157
|
+
*/
|
|
158
|
+
Endpoints: {
|
|
159
|
+
/**
|
|
160
|
+
* Authorization endpoint for initiating the OAuth2/OIDC flow.
|
|
161
|
+
* This endpoint is used to request authorization and receive an authorization code.
|
|
162
|
+
*/
|
|
163
|
+
AUTHORIZATION: "/oauth2/authorize",
|
|
164
|
+
/**
|
|
165
|
+
* Session check iframe endpoint for session management.
|
|
166
|
+
* Used to monitor the user's session state through a hidden iframe.
|
|
167
|
+
*/
|
|
168
|
+
SESSION_IFRAME: "/oidc/checksession",
|
|
169
|
+
/**
|
|
170
|
+
* End session endpoint for logout functionality.
|
|
171
|
+
* Used to terminate the user's session and perform logout operations.
|
|
172
|
+
*/
|
|
173
|
+
END_SESSION: "/oidc/logout",
|
|
174
|
+
/**
|
|
175
|
+
* Token issuer endpoint.
|
|
176
|
+
* The endpoint that issues OAuth2/OIDC tokens.
|
|
177
|
+
*/
|
|
178
|
+
ISSUER: "/oauth2/token",
|
|
179
|
+
/**
|
|
180
|
+
* JSON Web Key Set endpoint for key validation.
|
|
181
|
+
* Provides the public keys used to verify token signatures.
|
|
182
|
+
*/
|
|
183
|
+
JWKS: "/oauth2/jwks",
|
|
184
|
+
/**
|
|
185
|
+
* Token revocation endpoint.
|
|
186
|
+
* Used to invalidate access or refresh tokens before they expire.
|
|
187
|
+
*/
|
|
188
|
+
REVOCATION: "/oauth2/revoke",
|
|
189
|
+
/**
|
|
190
|
+
* Token endpoint for obtaining access tokens.
|
|
191
|
+
* Used to exchange authorization codes for access tokens and refresh tokens.
|
|
192
|
+
*/
|
|
193
|
+
TOKEN: "/oauth2/token",
|
|
194
|
+
/**
|
|
195
|
+
* UserInfo endpoint for obtaining user claims.
|
|
196
|
+
* Provides authenticated user information when called with a valid access token.
|
|
197
|
+
*/
|
|
198
|
+
USERINFO: "/oauth2/userinfo"
|
|
199
|
+
},
|
|
200
|
+
/**
|
|
201
|
+
* Storage related constants used for maintaining OIDC state.
|
|
202
|
+
* These constants define the keys used to store OIDC-related data
|
|
203
|
+
* in the browser's storage mechanisms.
|
|
204
|
+
*/
|
|
205
|
+
Storage: {
|
|
206
|
+
/**
|
|
207
|
+
* Storage keys for various OIDC endpoints and configurations.
|
|
208
|
+
* These keys are used to store endpoint URLs and configuration
|
|
209
|
+
* states in the browser's storage.
|
|
210
|
+
*/
|
|
211
|
+
StorageKeys: {
|
|
212
|
+
/**
|
|
213
|
+
* Collection of storage keys for OIDC endpoints.
|
|
214
|
+
* These keys are used to store the discovered endpoint URLs
|
|
215
|
+
* from the OpenID Provider's configuration.
|
|
216
|
+
*/
|
|
217
|
+
Endpoints: {
|
|
218
|
+
/**
|
|
219
|
+
* Storage key for the authorization endpoint URL.
|
|
220
|
+
* Used to store the URL where authorization requests should be sent.
|
|
221
|
+
*/
|
|
222
|
+
AUTHORIZATION: "authorization_endpoint",
|
|
223
|
+
/**
|
|
224
|
+
* Storage key for the token endpoint URL.
|
|
225
|
+
* Used to store the URL where token requests should be sent.
|
|
226
|
+
*/
|
|
227
|
+
TOKEN: "token_endpoint",
|
|
228
|
+
/**
|
|
229
|
+
* Storage key for the revocation endpoint URL.
|
|
230
|
+
* Used to store the URL where token revocation requests should be sent.
|
|
231
|
+
*/
|
|
232
|
+
REVOCATION: "revocation_endpoint",
|
|
233
|
+
/**
|
|
234
|
+
* Storage key for the end session endpoint URL.
|
|
235
|
+
* Used to store the URL where logout requests should be sent.
|
|
236
|
+
*/
|
|
237
|
+
END_SESSION: "end_session_endpoint",
|
|
238
|
+
/**
|
|
239
|
+
* Storage key for the JWKS URI endpoint URL.
|
|
240
|
+
* Used to store the URL where JSON Web Key Sets can be retrieved.
|
|
241
|
+
*/
|
|
242
|
+
JWKS: "jwks_uri",
|
|
243
|
+
/**
|
|
244
|
+
* Storage key for the session check iframe URL.
|
|
245
|
+
* Used to store the URL of the iframe used for session state monitoring.
|
|
246
|
+
*/
|
|
247
|
+
SESSION_IFRAME: "check_session_iframe",
|
|
248
|
+
/**
|
|
249
|
+
* Storage key for the issuer identifier URL.
|
|
250
|
+
* Used to store the URL that identifies the OpenID Provider.
|
|
251
|
+
*/
|
|
252
|
+
ISSUER: "issuer",
|
|
253
|
+
/**
|
|
254
|
+
* Storage key for the userinfo endpoint URL.
|
|
255
|
+
* Used to store the URL where user information can be retrieved.
|
|
256
|
+
*/
|
|
257
|
+
USERINFO: "userinfo_endpoint"
|
|
258
|
+
},
|
|
259
|
+
/**
|
|
260
|
+
* Flag to track if OpenID Provider configuration is initiated.
|
|
261
|
+
* Used to determine if the OIDC discovery process has been started.
|
|
262
|
+
* This helps prevent duplicate initialization attempts.
|
|
263
|
+
*/
|
|
264
|
+
OPENID_PROVIDER_CONFIG_INITIATED: "op_config_initiated"
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
var OIDCDiscoveryConstants_default = OIDCDiscoveryConstants;
|
|
269
|
+
|
|
270
|
+
// src/constants/TokenExchangeConstants.ts
|
|
271
|
+
var TokenExchangeConstants = {
|
|
272
|
+
/**
|
|
273
|
+
* Collection of placeholder strings used in token exchange operations.
|
|
274
|
+
* These placeholders are replaced with actual values when processing
|
|
275
|
+
* token exchange requests.
|
|
276
|
+
*/
|
|
277
|
+
Placeholders: {
|
|
278
|
+
/**
|
|
279
|
+
* Placeholder for the token value in exchange requests.
|
|
280
|
+
* Usually replaced with an access token or refresh token.
|
|
281
|
+
*/
|
|
282
|
+
TOKEN: "{{token}}",
|
|
283
|
+
/**
|
|
284
|
+
* Placeholder for the username in token exchange operations.
|
|
285
|
+
* Used when user identity needs to be included in the exchange.
|
|
286
|
+
*/
|
|
287
|
+
USERNAME: "{{username}}",
|
|
288
|
+
/**
|
|
289
|
+
* Placeholder for OAuth scopes in token exchange requests.
|
|
290
|
+
* Replaced with space-separated scope strings.
|
|
291
|
+
*/
|
|
292
|
+
SCOPE: "{{scope}}",
|
|
293
|
+
/**
|
|
294
|
+
* Placeholder for client ID in token exchange operations.
|
|
295
|
+
* Required for client authentication.
|
|
296
|
+
*/
|
|
297
|
+
CLIENT_ID: "{{clientID}}",
|
|
298
|
+
/**
|
|
299
|
+
* Placeholder for client secret in token exchange operations.
|
|
300
|
+
* Used for client authentication in confidential client flows.
|
|
301
|
+
*/
|
|
302
|
+
CLIENT_SECRET: "{{clientSecret}}"
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
var TokenExchangeConstants_default = TokenExchangeConstants;
|
|
306
|
+
|
|
307
|
+
// src/__legacy__/helpers/authentication-helper.ts
|
|
308
|
+
var AuthenticationHelper = class {
|
|
309
|
+
constructor(dataLayer, cryptoHelper) {
|
|
310
|
+
__publicField(this, "_dataLayer");
|
|
311
|
+
__publicField(this, "_config");
|
|
312
|
+
__publicField(this, "_oidcProviderMetaData");
|
|
313
|
+
__publicField(this, "_cryptoHelper");
|
|
314
|
+
this._dataLayer = dataLayer;
|
|
315
|
+
this._config = async () => await this._dataLayer.getConfigData();
|
|
316
|
+
this._oidcProviderMetaData = async () => await this._dataLayer.getOIDCProviderMetaData();
|
|
317
|
+
this._cryptoHelper = cryptoHelper;
|
|
318
|
+
}
|
|
319
|
+
async resolveEndpoints(response) {
|
|
320
|
+
const oidcProviderMetaData = {};
|
|
321
|
+
const configData = await this._config();
|
|
322
|
+
configData.endpoints && Object.keys(configData.endpoints).forEach((endpointName) => {
|
|
323
|
+
const snakeCasedName = endpointName.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
|
|
324
|
+
oidcProviderMetaData[snakeCasedName] = configData?.endpoints ? configData.endpoints[endpointName] : "";
|
|
325
|
+
});
|
|
326
|
+
return { ...response, ...oidcProviderMetaData };
|
|
327
|
+
}
|
|
328
|
+
async resolveEndpointsExplicitly() {
|
|
329
|
+
const oidcProviderMetaData = {};
|
|
330
|
+
const configData = await this._config();
|
|
331
|
+
const requiredEndpoints = [
|
|
332
|
+
OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.AUTHORIZATION,
|
|
333
|
+
OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.END_SESSION,
|
|
334
|
+
OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.JWKS,
|
|
335
|
+
OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.SESSION_IFRAME,
|
|
336
|
+
OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.REVOCATION,
|
|
337
|
+
OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.TOKEN,
|
|
338
|
+
OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.ISSUER,
|
|
339
|
+
OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.USERINFO
|
|
340
|
+
];
|
|
341
|
+
const isRequiredEndpointsContains = configData.endpoints ? requiredEndpoints.every((reqEndpointName) => {
|
|
342
|
+
return configData.endpoints ? Object.keys(configData.endpoints).some((endpointName) => {
|
|
343
|
+
const snakeCasedName = endpointName.replace(
|
|
344
|
+
/[A-Z]/g,
|
|
345
|
+
(letter) => `_${letter.toLowerCase()}`
|
|
346
|
+
);
|
|
347
|
+
return snakeCasedName === reqEndpointName;
|
|
348
|
+
}) : false;
|
|
349
|
+
}) : false;
|
|
350
|
+
if (!isRequiredEndpointsContains) {
|
|
351
|
+
throw new AsgardeoAuthException(
|
|
352
|
+
"JS-AUTH_HELPER-REE-NF01",
|
|
353
|
+
"Required endpoints missing",
|
|
354
|
+
"Some or all of the required endpoints are missing in the object passed to the `endpoints` attribute of the`AuthConfig` object."
|
|
355
|
+
);
|
|
356
|
+
}
|
|
357
|
+
configData.endpoints && Object.keys(configData.endpoints).forEach((endpointName) => {
|
|
358
|
+
const snakeCasedName = endpointName.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
|
|
359
|
+
oidcProviderMetaData[snakeCasedName] = configData?.endpoints ? configData.endpoints[endpointName] : "";
|
|
360
|
+
});
|
|
361
|
+
return { ...oidcProviderMetaData };
|
|
362
|
+
}
|
|
363
|
+
async resolveEndpointsByBaseURL() {
|
|
364
|
+
const oidcProviderMetaData = {};
|
|
365
|
+
const configData = await this._config();
|
|
366
|
+
const baseUrl = configData.baseUrl;
|
|
367
|
+
if (!baseUrl) {
|
|
368
|
+
throw new AsgardeoAuthException(
|
|
369
|
+
"JS-AUTH_HELPER_REBO-NF01",
|
|
370
|
+
"Base URL not defined.",
|
|
371
|
+
"Base URL is not defined in AuthClient config."
|
|
372
|
+
);
|
|
373
|
+
}
|
|
374
|
+
configData.endpoints && Object.keys(configData.endpoints).forEach((endpointName) => {
|
|
375
|
+
const snakeCasedName = endpointName.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
|
|
376
|
+
oidcProviderMetaData[snakeCasedName] = configData?.endpoints ? configData.endpoints[endpointName] : "";
|
|
377
|
+
});
|
|
378
|
+
const defaultEndpoints = {
|
|
379
|
+
[OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.AUTHORIZATION]: `${baseUrl}${OIDCDiscoveryConstants_default.Endpoints.AUTHORIZATION}`,
|
|
380
|
+
[OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.END_SESSION]: `${baseUrl}${OIDCDiscoveryConstants_default.Endpoints.END_SESSION}`,
|
|
381
|
+
[OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.ISSUER]: `${baseUrl}${OIDCDiscoveryConstants_default.Endpoints.ISSUER}`,
|
|
382
|
+
[OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.JWKS]: `${baseUrl}${OIDCDiscoveryConstants_default.Endpoints.JWKS}`,
|
|
383
|
+
[OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.SESSION_IFRAME]: `${baseUrl}${OIDCDiscoveryConstants_default.Endpoints.SESSION_IFRAME}`,
|
|
384
|
+
[OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.REVOCATION]: `${baseUrl}${OIDCDiscoveryConstants_default.Endpoints.REVOCATION}`,
|
|
385
|
+
[OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.TOKEN]: `${baseUrl}${OIDCDiscoveryConstants_default.Endpoints.TOKEN}`,
|
|
386
|
+
[OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.USERINFO]: `${baseUrl}${OIDCDiscoveryConstants_default.Endpoints.USERINFO}`
|
|
387
|
+
};
|
|
388
|
+
return { ...defaultEndpoints, ...oidcProviderMetaData };
|
|
389
|
+
}
|
|
390
|
+
async validateIdToken(idToken) {
|
|
391
|
+
const jwksEndpoint = (await this._dataLayer.getOIDCProviderMetaData()).jwks_uri;
|
|
392
|
+
const configData = await this._config();
|
|
393
|
+
if (!jwksEndpoint || jwksEndpoint.trim().length === 0) {
|
|
394
|
+
throw new AsgardeoAuthException(
|
|
395
|
+
"JS_AUTH_HELPER-VIT-NF01",
|
|
396
|
+
"JWKS endpoint not found.",
|
|
397
|
+
"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."
|
|
398
|
+
);
|
|
399
|
+
}
|
|
400
|
+
let response;
|
|
401
|
+
try {
|
|
402
|
+
response = await fetch(jwksEndpoint, {
|
|
403
|
+
credentials: configData.sendCookiesInRequests ? "include" : "same-origin"
|
|
404
|
+
});
|
|
405
|
+
} catch (error) {
|
|
406
|
+
throw new AsgardeoAuthException(
|
|
407
|
+
"JS-AUTH_HELPER-VIT-NE02",
|
|
408
|
+
"Request to jwks endpoint failed.",
|
|
409
|
+
error ?? "The request sent to get the jwks from the server failed."
|
|
410
|
+
);
|
|
411
|
+
}
|
|
412
|
+
if (response.status !== 200 || !response.ok) {
|
|
413
|
+
throw new AsgardeoAuthException(
|
|
414
|
+
"JS-AUTH_HELPER-VIT-HE03",
|
|
415
|
+
`Invalid response status received for jwks request (${response.statusText}).`,
|
|
416
|
+
await response.json()
|
|
417
|
+
);
|
|
418
|
+
}
|
|
419
|
+
const issuer = (await this._oidcProviderMetaData()).issuer;
|
|
420
|
+
const { keys } = await response.json();
|
|
421
|
+
const jwk = await this._cryptoHelper.getJWKForTheIdToken(idToken.split(".")[0], keys);
|
|
422
|
+
return this._cryptoHelper.isValidIdToken(
|
|
423
|
+
idToken,
|
|
424
|
+
jwk,
|
|
425
|
+
(await this._config()).clientID,
|
|
426
|
+
issuer ?? "",
|
|
427
|
+
this._cryptoHelper.decodeIDToken(idToken).sub,
|
|
428
|
+
(await this._config()).clockTolerance,
|
|
429
|
+
(await this._config()).validateIDTokenIssuer ?? true
|
|
430
|
+
);
|
|
431
|
+
}
|
|
432
|
+
getAuthenticatedUserInfo(idToken) {
|
|
433
|
+
const payload = this._cryptoHelper.decodeIDToken(idToken);
|
|
434
|
+
const tenantDomain = extractTenantDomainFromIdTokenPayload_default(payload);
|
|
435
|
+
const username = payload?.["username"] ?? "";
|
|
436
|
+
const givenName = payload?.["given_name"] ?? "";
|
|
437
|
+
const familyName = payload?.["family_name"] ?? "";
|
|
438
|
+
const fullName = givenName && familyName ? `${givenName} ${familyName}` : givenName ? givenName : familyName ? familyName : "";
|
|
439
|
+
const displayName = payload.preferred_username ?? fullName;
|
|
440
|
+
return {
|
|
441
|
+
displayName,
|
|
442
|
+
tenantDomain,
|
|
443
|
+
username,
|
|
444
|
+
...extractUserClaimsFromIdToken_default(payload)
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
async replaceCustomGrantTemplateTags(text, userID) {
|
|
448
|
+
let scope = ScopeConstants_default.OPENID;
|
|
449
|
+
const configData = await this._config();
|
|
450
|
+
const sessionData = await this._dataLayer.getSessionData(userID);
|
|
451
|
+
if (configData.scope && configData.scope.length > 0) {
|
|
452
|
+
if (!configData.scope.includes(ScopeConstants_default.OPENID)) {
|
|
453
|
+
configData.scope.push(ScopeConstants_default.OPENID);
|
|
454
|
+
}
|
|
455
|
+
scope = configData.scope.join(" ");
|
|
456
|
+
}
|
|
457
|
+
return text.replace(TokenExchangeConstants_default.Placeholders.TOKEN, sessionData.access_token).replace(
|
|
458
|
+
TokenExchangeConstants_default.Placeholders.USERNAME,
|
|
459
|
+
this.getAuthenticatedUserInfo(sessionData.id_token).username
|
|
460
|
+
).replace(TokenExchangeConstants_default.Placeholders.SCOPE, scope).replace(TokenExchangeConstants_default.Placeholders.CLIENT_ID, configData.clientID).replace(TokenExchangeConstants_default.Placeholders.CLIENT_SECRET, configData.clientSecret ?? "");
|
|
461
|
+
}
|
|
462
|
+
async clearUserSessionData(userID) {
|
|
463
|
+
await this._dataLayer.removeTemporaryData(userID);
|
|
464
|
+
await this._dataLayer.removeSessionData(userID);
|
|
465
|
+
}
|
|
466
|
+
async handleTokenResponse(response, userID) {
|
|
467
|
+
if (response.status !== 200 || !response.ok) {
|
|
468
|
+
throw new AsgardeoAuthException(
|
|
469
|
+
"JS-AUTH_HELPER-HTR-NE01",
|
|
470
|
+
`Invalid response status received for token request (${response.statusText}).`,
|
|
471
|
+
await response.json()
|
|
472
|
+
);
|
|
473
|
+
}
|
|
474
|
+
const parsedResponse = await response.json();
|
|
475
|
+
parsedResponse.created_at = (/* @__PURE__ */ new Date()).getTime();
|
|
476
|
+
const shouldValidateIdToken = (await this._config()).validateIDToken;
|
|
477
|
+
if (shouldValidateIdToken) {
|
|
478
|
+
return this.validateIdToken(parsedResponse.id_token).then(async () => {
|
|
479
|
+
await this._dataLayer.setSessionData(parsedResponse, userID);
|
|
480
|
+
const tokenResponse = {
|
|
481
|
+
accessToken: parsedResponse.access_token,
|
|
482
|
+
createdAt: parsedResponse.created_at,
|
|
483
|
+
expiresIn: parsedResponse.expires_in,
|
|
484
|
+
idToken: parsedResponse.id_token,
|
|
485
|
+
refreshToken: parsedResponse.refresh_token,
|
|
486
|
+
scope: parsedResponse.scope,
|
|
487
|
+
tokenType: parsedResponse.token_type
|
|
488
|
+
};
|
|
489
|
+
return Promise.resolve(tokenResponse);
|
|
490
|
+
});
|
|
491
|
+
} else {
|
|
492
|
+
const tokenResponse = {
|
|
493
|
+
accessToken: parsedResponse.access_token,
|
|
494
|
+
createdAt: parsedResponse.created_at,
|
|
495
|
+
expiresIn: parsedResponse.expires_in,
|
|
496
|
+
idToken: parsedResponse.id_token,
|
|
497
|
+
refreshToken: parsedResponse.refresh_token,
|
|
498
|
+
scope: parsedResponse.scope,
|
|
499
|
+
tokenType: parsedResponse.token_type
|
|
500
|
+
};
|
|
501
|
+
await this._dataLayer.setSessionData(parsedResponse, userID);
|
|
502
|
+
return Promise.resolve(tokenResponse);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
};
|
|
506
|
+
|
|
507
|
+
// src/utils/generatePkceStorageKey.ts
|
|
508
|
+
var generatePkceStorageKey = (tempStore) => {
|
|
509
|
+
const keys = [];
|
|
510
|
+
Object.keys(tempStore).forEach((key) => {
|
|
511
|
+
if (key.startsWith(PKCEConstants_default.Storage.StorageKeys.CODE_VERIFIER)) {
|
|
512
|
+
keys.push(key);
|
|
513
|
+
}
|
|
514
|
+
});
|
|
515
|
+
const lastKey = keys.sort().pop();
|
|
516
|
+
const index = parseInt(lastKey?.split(PKCEConstants_default.Storage.StorageKeys.SEPARATOR)[1] ?? "-1");
|
|
517
|
+
return `${PKCEConstants_default.Storage.StorageKeys.CODE_VERIFIER}${PKCEConstants_default.Storage.StorageKeys.SEPARATOR}${index + 1}`;
|
|
518
|
+
};
|
|
519
|
+
var generatePkceStorageKey_default = generatePkceStorageKey;
|
|
520
|
+
|
|
521
|
+
// src/constants/OIDCRequestConstants.ts
|
|
522
|
+
var OIDCRequestConstants = {
|
|
523
|
+
Params: {
|
|
524
|
+
/**
|
|
525
|
+
* The authorization code returned from the authorization endpoint.
|
|
526
|
+
* Used in the authorization code flow.
|
|
527
|
+
*/
|
|
528
|
+
AUTHORIZATION_CODE: "code",
|
|
529
|
+
/**
|
|
530
|
+
* Session state parameter used for session management between the client and the OP.
|
|
531
|
+
*/
|
|
532
|
+
SESSION_STATE: "session_state",
|
|
533
|
+
/**
|
|
534
|
+
* State parameter used to maintain state between the request and the callback.
|
|
535
|
+
* Helps in preventing CSRF attacks.
|
|
536
|
+
*/
|
|
537
|
+
STATE: "state",
|
|
538
|
+
/**
|
|
539
|
+
* Indicates whether sign-out was successful during the end-session flow.
|
|
540
|
+
* May be returned by the OP after a logout request.
|
|
541
|
+
*/
|
|
542
|
+
SIGN_OUT_SUCCESS: "sign_out_success"
|
|
543
|
+
},
|
|
544
|
+
/**
|
|
545
|
+
* Sign-out related constants for managing the end-session flow in OIDC.
|
|
546
|
+
*/
|
|
547
|
+
SignOut: {
|
|
548
|
+
/**
|
|
549
|
+
* Storage-related constants for managing sign-out state.
|
|
550
|
+
*/
|
|
551
|
+
Storage: {
|
|
552
|
+
/**
|
|
553
|
+
* Collection of storage keys used in sign-out implementation
|
|
554
|
+
*/
|
|
555
|
+
StorageKeys: {
|
|
556
|
+
/**
|
|
557
|
+
* Storage key for the sign-out URL.
|
|
558
|
+
* Used to store the complete URL where the user should be redirected after
|
|
559
|
+
* completing the OIDC logout process.
|
|
560
|
+
*/
|
|
561
|
+
SIGN_OUT_URL: "sign_out_url"
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
};
|
|
566
|
+
var OIDCRequestConstants_default = OIDCRequestConstants;
|
|
567
|
+
|
|
568
|
+
// src/constants/TokenConstants.ts
|
|
569
|
+
var TokenConstants = {
|
|
570
|
+
/**
|
|
571
|
+
* Token signature validation constants.
|
|
572
|
+
* Contains configurations related to token signature verification.
|
|
573
|
+
*/
|
|
574
|
+
SignatureValidation: {
|
|
575
|
+
/**
|
|
576
|
+
* Fallback array of supported signature algorithms for OIDC token validation.
|
|
577
|
+
* These values are used when the supported algorithms cannot be retrieved from
|
|
578
|
+
* the .well-known/openid-configuration endpoint.
|
|
579
|
+
*
|
|
580
|
+
* Supported algorithms:
|
|
581
|
+
* - `RS256` - RSASSA-PKCS1-v1_5 using SHA-256
|
|
582
|
+
* - `RS512` - RSASSA-PKCS1-v1_5 using SHA-512
|
|
583
|
+
* - `RS384` - RSASSA-PKCS1-v1_5 using SHA-384
|
|
584
|
+
* - `PS256` - RSASSA-PSS using SHA-256 and MGF1 with SHA-256
|
|
585
|
+
*/
|
|
586
|
+
SUPPORTED_ALGORITHMS: ["RS256", "RS512", "RS384", "PS256"]
|
|
587
|
+
},
|
|
588
|
+
/**
|
|
589
|
+
* Storage-related constants for OIDC tokens.
|
|
590
|
+
* Contains keys used to store token-related data in browser storage.
|
|
591
|
+
*/
|
|
592
|
+
Storage: {
|
|
593
|
+
/**
|
|
594
|
+
* Collection of storage keys used in token management.
|
|
595
|
+
* These keys are used to store and retrieve token-related
|
|
596
|
+
* information from browser storage.
|
|
597
|
+
*/
|
|
598
|
+
StorageKeys: {
|
|
599
|
+
/**
|
|
600
|
+
* Key used to store the refresh token timer identifier.
|
|
601
|
+
* This timer is used to schedule token refresh operations
|
|
602
|
+
* before the current token expires.
|
|
603
|
+
*/
|
|
604
|
+
REFRESH_TOKEN_TIMER: "refresh_token_timer"
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
};
|
|
608
|
+
var TokenConstants_default = TokenConstants;
|
|
609
|
+
|
|
610
|
+
// src/IsomorphicCrypto.ts
|
|
611
|
+
var IsomorphicCrypto = class {
|
|
612
|
+
constructor(cryptoUtils) {
|
|
613
|
+
__publicField(this, "_cryptoUtils");
|
|
614
|
+
this._cryptoUtils = cryptoUtils;
|
|
615
|
+
}
|
|
616
|
+
/**
|
|
617
|
+
* Generate code verifier.
|
|
618
|
+
*
|
|
619
|
+
* @returns code verifier.
|
|
620
|
+
*/
|
|
621
|
+
getCodeVerifier() {
|
|
622
|
+
return this._cryptoUtils.base64URLEncode(this._cryptoUtils.generateRandomBytes(32));
|
|
623
|
+
}
|
|
624
|
+
/**
|
|
625
|
+
* Derive code challenge from the code verifier.
|
|
626
|
+
*
|
|
627
|
+
* @param verifier - Code verifier.
|
|
628
|
+
*
|
|
629
|
+
* @returns - code challenge.
|
|
630
|
+
*/
|
|
631
|
+
getCodeChallenge(verifier) {
|
|
632
|
+
return this._cryptoUtils.base64URLEncode(this._cryptoUtils.hashSha256(verifier));
|
|
633
|
+
}
|
|
634
|
+
/**
|
|
635
|
+
* Get JWK used for the id_token
|
|
636
|
+
*
|
|
637
|
+
* @param jwtHeader - header of the id_token.
|
|
638
|
+
* @param keys - jwks response.
|
|
639
|
+
*
|
|
640
|
+
* @returns public key.
|
|
641
|
+
*
|
|
642
|
+
* @throws
|
|
643
|
+
*/
|
|
644
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
645
|
+
getJWKForTheIdToken(jwtHeader, keys) {
|
|
646
|
+
const headerJSON = JSON.parse(this._cryptoUtils.base64URLDecode(jwtHeader));
|
|
647
|
+
for (const key of keys) {
|
|
648
|
+
if (headerJSON["kid"] === key.kid) {
|
|
649
|
+
return key;
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
throw new AsgardeoAuthException(
|
|
653
|
+
"JS-CRYPTO_UTIL-GJFTIT-IV01",
|
|
654
|
+
"kid not found.",
|
|
655
|
+
"Failed to find the 'kid' specified in the id_token. 'kid' found in the header : " + headerJSON["kid"] + ", Expected values: " + keys.map((key) => key.kid).join(", ")
|
|
656
|
+
);
|
|
657
|
+
}
|
|
658
|
+
/**
|
|
659
|
+
* Verify id token.
|
|
660
|
+
*
|
|
661
|
+
* @param idToken - id_token received from the IdP.
|
|
662
|
+
* @param jwk - public key used for signing.
|
|
663
|
+
* @param clientID - app identification.
|
|
664
|
+
* @param issuer - id_token issuer.
|
|
665
|
+
* @param username - Username.
|
|
666
|
+
* @param clockTolerance - Allowed leeway for id_tokens (in seconds).
|
|
667
|
+
*
|
|
668
|
+
* @returns whether the id_token is valid.
|
|
669
|
+
*
|
|
670
|
+
* @throws
|
|
671
|
+
*/
|
|
672
|
+
isValidIdToken(idToken, jwk, clientID, issuer, username, clockTolerance, validateJwtIssuer) {
|
|
673
|
+
return this._cryptoUtils.verifyJwt(
|
|
674
|
+
idToken,
|
|
675
|
+
jwk,
|
|
676
|
+
TokenConstants_default.SignatureValidation.SUPPORTED_ALGORITHMS,
|
|
677
|
+
clientID,
|
|
678
|
+
issuer,
|
|
679
|
+
username,
|
|
680
|
+
clockTolerance,
|
|
681
|
+
validateJwtIssuer
|
|
682
|
+
).then((response) => {
|
|
683
|
+
if (response) {
|
|
684
|
+
return Promise.resolve(true);
|
|
685
|
+
}
|
|
686
|
+
return Promise.reject(
|
|
687
|
+
new AsgardeoAuthException(
|
|
688
|
+
"JS-CRYPTO_HELPER-IVIT-IV01",
|
|
689
|
+
"Invalid ID token.",
|
|
690
|
+
"ID token validation returned false"
|
|
691
|
+
)
|
|
692
|
+
);
|
|
693
|
+
});
|
|
694
|
+
}
|
|
695
|
+
/**
|
|
696
|
+
* This function decodes the payload of an id token and returns it.
|
|
697
|
+
*
|
|
698
|
+
* @param idToken - The id token to be decoded.
|
|
699
|
+
*
|
|
700
|
+
* @returns - The decoded payload of the id token.
|
|
701
|
+
*
|
|
702
|
+
* @throws
|
|
703
|
+
*/
|
|
704
|
+
decodeIDToken(idToken) {
|
|
705
|
+
try {
|
|
706
|
+
const utf8String = this._cryptoUtils.base64URLDecode(idToken.split(".")[1]);
|
|
707
|
+
const payload = JSON.parse(utf8String);
|
|
708
|
+
return payload;
|
|
709
|
+
} catch (error) {
|
|
710
|
+
throw new AsgardeoAuthException("JS-CRYPTO_UTIL-DIT-IV01", "Decoding ID token failed.", error);
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
};
|
|
714
|
+
|
|
715
|
+
// src/__legacy__/core/authentication-core.ts
|
|
716
|
+
var AuthenticationCore = class {
|
|
717
|
+
constructor(dataLayer, cryptoUtils) {
|
|
718
|
+
__publicField(this, "_dataLayer");
|
|
719
|
+
__publicField(this, "_config");
|
|
720
|
+
__publicField(this, "_oidcProviderMetaData");
|
|
721
|
+
__publicField(this, "_authenticationHelper");
|
|
722
|
+
__publicField(this, "_cryptoUtils");
|
|
723
|
+
__publicField(this, "_cryptoHelper");
|
|
724
|
+
this._cryptoUtils = cryptoUtils;
|
|
725
|
+
this._cryptoHelper = new IsomorphicCrypto(cryptoUtils);
|
|
726
|
+
this._authenticationHelper = new AuthenticationHelper(dataLayer, this._cryptoHelper);
|
|
727
|
+
this._dataLayer = dataLayer;
|
|
728
|
+
this._config = async () => await this._dataLayer.getConfigData();
|
|
729
|
+
this._oidcProviderMetaData = async () => await this._dataLayer.getOIDCProviderMetaData();
|
|
730
|
+
}
|
|
731
|
+
async getAuthorizationURLParams(config, userID) {
|
|
732
|
+
const configData = await this._config();
|
|
733
|
+
const authorizeRequestParams = /* @__PURE__ */ new Map();
|
|
734
|
+
authorizeRequestParams.set("response_type", "code");
|
|
735
|
+
authorizeRequestParams.set("client_id", configData.clientID);
|
|
736
|
+
let scope = ScopeConstants_default.OPENID;
|
|
737
|
+
if (configData.scope && configData.scope.length > 0) {
|
|
738
|
+
if (!configData.scope.includes(ScopeConstants_default.OPENID)) {
|
|
739
|
+
configData.scope.push(ScopeConstants_default.OPENID);
|
|
740
|
+
}
|
|
741
|
+
scope = configData.scope.join(" ");
|
|
742
|
+
}
|
|
743
|
+
authorizeRequestParams.set("scope", scope);
|
|
744
|
+
authorizeRequestParams.set("redirect_uri", configData.signInRedirectURL);
|
|
745
|
+
if (configData.responseMode) {
|
|
746
|
+
authorizeRequestParams.set("response_mode", configData.responseMode);
|
|
747
|
+
}
|
|
748
|
+
const tempStore = await this._dataLayer.getTemporaryData(userID);
|
|
749
|
+
const pkceKey = await generatePkceStorageKey_default(tempStore);
|
|
750
|
+
if (configData.enablePKCE) {
|
|
751
|
+
const codeVerifier = this._cryptoHelper?.getCodeVerifier();
|
|
752
|
+
const codeChallenge = this._cryptoHelper?.getCodeChallenge(codeVerifier);
|
|
753
|
+
await this._dataLayer.setTemporaryDataParameter(pkceKey, codeVerifier, userID);
|
|
754
|
+
authorizeRequestParams.set("code_challenge_method", "S256");
|
|
755
|
+
authorizeRequestParams.set("code_challenge", codeChallenge);
|
|
756
|
+
}
|
|
757
|
+
if (configData.prompt) {
|
|
758
|
+
authorizeRequestParams.set("prompt", configData.prompt);
|
|
759
|
+
}
|
|
760
|
+
const customParams = config;
|
|
761
|
+
if (customParams) {
|
|
762
|
+
for (const [key, value] of Object.entries(customParams)) {
|
|
763
|
+
if (key != "" && value != "" && key !== OIDCRequestConstants_default.Params.STATE) {
|
|
764
|
+
authorizeRequestParams.set(key, value.toString());
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
authorizeRequestParams.set(
|
|
769
|
+
OIDCRequestConstants_default.Params.STATE,
|
|
770
|
+
generateStateParamForRequestCorrelation_default(
|
|
771
|
+
pkceKey,
|
|
772
|
+
customParams ? customParams[OIDCRequestConstants_default.Params.STATE]?.toString() : ""
|
|
773
|
+
)
|
|
774
|
+
);
|
|
775
|
+
return authorizeRequestParams;
|
|
776
|
+
}
|
|
777
|
+
async getAuthorizationURL(config, userID) {
|
|
778
|
+
const authorizeEndpoint = await this._dataLayer.getOIDCProviderMetaDataParameter(
|
|
779
|
+
OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.AUTHORIZATION
|
|
780
|
+
);
|
|
781
|
+
if (!authorizeEndpoint || authorizeEndpoint.trim().length === 0) {
|
|
782
|
+
throw new AsgardeoAuthException(
|
|
783
|
+
"JS-AUTH_CORE-GAU-NF01",
|
|
784
|
+
"No authorization endpoint found.",
|
|
785
|
+
"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."
|
|
786
|
+
);
|
|
787
|
+
}
|
|
788
|
+
const authorizeRequest = new URL(authorizeEndpoint);
|
|
789
|
+
const authorizeRequestParams = await this.getAuthorizationURLParams(config, userID);
|
|
790
|
+
for (const [key, value] of authorizeRequestParams.entries()) {
|
|
791
|
+
authorizeRequest.searchParams.append(key, value);
|
|
792
|
+
}
|
|
793
|
+
return authorizeRequest.toString();
|
|
794
|
+
}
|
|
795
|
+
async requestAccessToken(authorizationCode, sessionState, state, userID, tokenRequestConfig) {
|
|
796
|
+
const tokenEndpoint = (await this._oidcProviderMetaData()).token_endpoint;
|
|
797
|
+
const configData = await this._config();
|
|
798
|
+
if (!tokenEndpoint || tokenEndpoint.trim().length === 0) {
|
|
799
|
+
throw new AsgardeoAuthException(
|
|
800
|
+
"JS-AUTH_CORE-RAT1-NF01",
|
|
801
|
+
"Token endpoint not found.",
|
|
802
|
+
"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."
|
|
803
|
+
);
|
|
804
|
+
}
|
|
805
|
+
sessionState && await this._dataLayer.setSessionDataParameter(
|
|
806
|
+
OIDCRequestConstants_default.Params.SESSION_STATE,
|
|
807
|
+
sessionState,
|
|
808
|
+
userID
|
|
809
|
+
);
|
|
810
|
+
const body = new URLSearchParams();
|
|
811
|
+
body.set("client_id", configData.clientID);
|
|
812
|
+
if (configData.clientSecret && configData.clientSecret.trim().length > 0) {
|
|
813
|
+
body.set("client_secret", configData.clientSecret);
|
|
814
|
+
}
|
|
815
|
+
const code = authorizationCode;
|
|
816
|
+
body.set("code", code);
|
|
817
|
+
body.set("grant_type", "authorization_code");
|
|
818
|
+
body.set("redirect_uri", configData.signInRedirectURL);
|
|
819
|
+
if (tokenRequestConfig?.params) {
|
|
820
|
+
Object.entries(tokenRequestConfig.params).forEach(([key, value]) => {
|
|
821
|
+
body.append(key, value);
|
|
822
|
+
});
|
|
823
|
+
}
|
|
824
|
+
if (configData.enablePKCE) {
|
|
825
|
+
body.set(
|
|
826
|
+
"code_verifier",
|
|
827
|
+
`${await this._dataLayer.getTemporaryDataParameter(extractPkceStorageKeyFromState_default(state), userID)}`
|
|
828
|
+
);
|
|
829
|
+
await this._dataLayer.removeTemporaryDataParameter(extractPkceStorageKeyFromState_default(state), userID);
|
|
830
|
+
}
|
|
831
|
+
let tokenResponse;
|
|
832
|
+
try {
|
|
833
|
+
tokenResponse = await fetch(tokenEndpoint, {
|
|
834
|
+
body,
|
|
835
|
+
credentials: configData.sendCookiesInRequests ? "include" : "same-origin",
|
|
836
|
+
headers: {
|
|
837
|
+
Accept: "application/json",
|
|
838
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
839
|
+
},
|
|
840
|
+
method: "POST"
|
|
841
|
+
});
|
|
842
|
+
} catch (error) {
|
|
843
|
+
throw new AsgardeoAuthException(
|
|
844
|
+
"JS-AUTH_CORE-RAT1-NE02",
|
|
845
|
+
"Requesting access token failed",
|
|
846
|
+
error ?? "The request to get the access token from the server failed."
|
|
847
|
+
);
|
|
848
|
+
}
|
|
849
|
+
if (!tokenResponse.ok) {
|
|
850
|
+
throw new AsgardeoAuthException(
|
|
851
|
+
"JS-AUTH_CORE-RAT1-HE03",
|
|
852
|
+
`Requesting access token failed with ${tokenResponse.statusText}`,
|
|
853
|
+
await tokenResponse.json()
|
|
854
|
+
);
|
|
855
|
+
}
|
|
856
|
+
return await this._authenticationHelper.handleTokenResponse(tokenResponse, userID);
|
|
857
|
+
}
|
|
858
|
+
async refreshAccessToken(userID) {
|
|
859
|
+
const tokenEndpoint = (await this._oidcProviderMetaData()).token_endpoint;
|
|
860
|
+
const configData = await this._config();
|
|
861
|
+
const sessionData = await this._dataLayer.getSessionData(userID);
|
|
862
|
+
if (!sessionData.refresh_token) {
|
|
863
|
+
throw new AsgardeoAuthException(
|
|
864
|
+
"JS-AUTH_CORE-RAT2-NF01",
|
|
865
|
+
"No refresh token found.",
|
|
866
|
+
"There was no refresh token found. Asgardeo doesn't return a refresh token if the refresh token grant is not enabled."
|
|
867
|
+
);
|
|
868
|
+
}
|
|
869
|
+
if (!tokenEndpoint || tokenEndpoint.trim().length === 0) {
|
|
870
|
+
throw new AsgardeoAuthException(
|
|
871
|
+
"JS-AUTH_CORE-RAT2-NF02",
|
|
872
|
+
"No refresh token endpoint found.",
|
|
873
|
+
"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."
|
|
874
|
+
);
|
|
875
|
+
}
|
|
876
|
+
const body = [];
|
|
877
|
+
body.push(`client_id=${configData.clientID}`);
|
|
878
|
+
body.push(`refresh_token=${sessionData.refresh_token}`);
|
|
879
|
+
body.push("grant_type=refresh_token");
|
|
880
|
+
if (configData.clientSecret && configData.clientSecret.trim().length > 0) {
|
|
881
|
+
body.push(`client_secret=${configData.clientSecret}`);
|
|
882
|
+
}
|
|
883
|
+
let tokenResponse;
|
|
884
|
+
try {
|
|
885
|
+
tokenResponse = await fetch(tokenEndpoint, {
|
|
886
|
+
body: body.join("&"),
|
|
887
|
+
credentials: configData.sendCookiesInRequests ? "include" : "same-origin",
|
|
888
|
+
headers: {
|
|
889
|
+
Accept: "application/json",
|
|
890
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
891
|
+
},
|
|
892
|
+
method: "POST"
|
|
893
|
+
});
|
|
894
|
+
} catch (error) {
|
|
895
|
+
throw new AsgardeoAuthException(
|
|
896
|
+
"JS-AUTH_CORE-RAT2-NR03",
|
|
897
|
+
"Refresh access token request failed.",
|
|
898
|
+
error ?? "The request to refresh the access token failed."
|
|
899
|
+
);
|
|
900
|
+
}
|
|
901
|
+
if (!tokenResponse.ok) {
|
|
902
|
+
throw new AsgardeoAuthException(
|
|
903
|
+
"JS-AUTH_CORE-RAT2-HE04",
|
|
904
|
+
`Refreshing access token failed with ${tokenResponse.statusText}`,
|
|
905
|
+
await tokenResponse.json()
|
|
906
|
+
);
|
|
907
|
+
}
|
|
908
|
+
return this._authenticationHelper.handleTokenResponse(tokenResponse, userID);
|
|
909
|
+
}
|
|
910
|
+
async revokeAccessToken(userID) {
|
|
911
|
+
const revokeTokenEndpoint = (await this._oidcProviderMetaData()).revocation_endpoint;
|
|
912
|
+
const configData = await this._config();
|
|
913
|
+
if (!revokeTokenEndpoint || revokeTokenEndpoint.trim().length === 0) {
|
|
914
|
+
throw new AsgardeoAuthException(
|
|
915
|
+
"JS-AUTH_CORE-RAT3-NF01",
|
|
916
|
+
"No revoke access token endpoint found.",
|
|
917
|
+
"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."
|
|
918
|
+
);
|
|
919
|
+
}
|
|
920
|
+
const body = [];
|
|
921
|
+
body.push(`client_id=${configData.clientID}`);
|
|
922
|
+
body.push(`token=${(await this._dataLayer.getSessionData(userID)).access_token}`);
|
|
923
|
+
body.push("token_type_hint=access_token");
|
|
924
|
+
if (configData.clientSecret && configData.clientSecret.trim().length > 0) {
|
|
925
|
+
body.push(`client_secret=${configData.clientSecret}`);
|
|
926
|
+
}
|
|
927
|
+
let response;
|
|
928
|
+
try {
|
|
929
|
+
response = await fetch(revokeTokenEndpoint, {
|
|
930
|
+
body: body.join("&"),
|
|
931
|
+
credentials: configData.sendCookiesInRequests ? "include" : "same-origin",
|
|
932
|
+
headers: {
|
|
933
|
+
Accept: "application/json",
|
|
934
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
935
|
+
},
|
|
936
|
+
method: "POST"
|
|
937
|
+
});
|
|
938
|
+
} catch (error) {
|
|
939
|
+
throw new AsgardeoAuthException(
|
|
940
|
+
"JS-AUTH_CORE-RAT3-NE02",
|
|
941
|
+
"The request to revoke access token failed.",
|
|
942
|
+
error ?? "The request sent to revoke the access token failed."
|
|
943
|
+
);
|
|
944
|
+
}
|
|
945
|
+
if (response.status !== 200 || !response.ok) {
|
|
946
|
+
throw new AsgardeoAuthException(
|
|
947
|
+
"JS-AUTH_CORE-RAT3-HE03",
|
|
948
|
+
`Invalid response status received for revoke access token request (${response.statusText}).`,
|
|
949
|
+
await response.json()
|
|
950
|
+
);
|
|
951
|
+
}
|
|
952
|
+
this._authenticationHelper.clearUserSessionData(userID);
|
|
953
|
+
return Promise.resolve(response);
|
|
954
|
+
}
|
|
955
|
+
async requestCustomGrant(customGrantParams, userID) {
|
|
956
|
+
const oidcProviderMetadata = await this._oidcProviderMetaData();
|
|
957
|
+
const configData = await this._config();
|
|
958
|
+
let tokenEndpoint;
|
|
959
|
+
if (customGrantParams.tokenEndpoint && customGrantParams.tokenEndpoint.trim().length !== 0) {
|
|
960
|
+
tokenEndpoint = customGrantParams.tokenEndpoint;
|
|
961
|
+
} else {
|
|
962
|
+
tokenEndpoint = oidcProviderMetadata.token_endpoint;
|
|
963
|
+
}
|
|
964
|
+
if (!tokenEndpoint || tokenEndpoint.trim().length === 0) {
|
|
965
|
+
throw new AsgardeoAuthException(
|
|
966
|
+
"JS-AUTH_CORE-RCG-NF01",
|
|
967
|
+
"Token endpoint not found.",
|
|
968
|
+
"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."
|
|
969
|
+
);
|
|
970
|
+
}
|
|
971
|
+
const data = await Promise.all(
|
|
972
|
+
Object.entries(customGrantParams.data).map(async ([key, value]) => {
|
|
973
|
+
const newValue = await this._authenticationHelper.replaceCustomGrantTemplateTags(
|
|
974
|
+
value,
|
|
975
|
+
userID
|
|
976
|
+
);
|
|
977
|
+
return `${key}=${newValue}`;
|
|
978
|
+
})
|
|
979
|
+
);
|
|
980
|
+
let requestHeaders = {
|
|
981
|
+
Accept: "application/json",
|
|
982
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
983
|
+
};
|
|
984
|
+
if (customGrantParams.attachToken) {
|
|
985
|
+
requestHeaders = {
|
|
986
|
+
...requestHeaders,
|
|
987
|
+
Authorization: `Bearer ${(await this._dataLayer.getSessionData(userID)).access_token}`
|
|
988
|
+
};
|
|
989
|
+
}
|
|
990
|
+
const requestConfig = {
|
|
991
|
+
body: data.join("&"),
|
|
992
|
+
credentials: configData.sendCookiesInRequests ? "include" : "same-origin",
|
|
993
|
+
headers: new Headers(requestHeaders),
|
|
994
|
+
method: "POST"
|
|
995
|
+
};
|
|
996
|
+
let response;
|
|
997
|
+
try {
|
|
998
|
+
response = await fetch(tokenEndpoint, requestConfig);
|
|
999
|
+
} catch (error) {
|
|
1000
|
+
throw new AsgardeoAuthException(
|
|
1001
|
+
"JS-AUTH_CORE-RCG-NE02",
|
|
1002
|
+
"The custom grant request failed.",
|
|
1003
|
+
error ?? "The request sent to get the custom grant failed."
|
|
1004
|
+
);
|
|
1005
|
+
}
|
|
1006
|
+
if (response.status !== 200 || !response.ok) {
|
|
1007
|
+
throw new AsgardeoAuthException(
|
|
1008
|
+
"JS-AUTH_CORE-RCG-HE03",
|
|
1009
|
+
`Invalid response status received for the custom grant request. (${response.statusText})`,
|
|
1010
|
+
await response.json()
|
|
1011
|
+
);
|
|
1012
|
+
}
|
|
1013
|
+
if (customGrantParams.returnsSession) {
|
|
1014
|
+
return this._authenticationHelper.handleTokenResponse(response, userID);
|
|
1015
|
+
} else {
|
|
1016
|
+
return Promise.resolve(await response.json());
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
async getBasicUserInfo(userID) {
|
|
1020
|
+
const sessionData = await this._dataLayer.getSessionData(userID);
|
|
1021
|
+
const authenticatedUser = this._authenticationHelper.getAuthenticatedUserInfo(
|
|
1022
|
+
sessionData?.id_token
|
|
1023
|
+
);
|
|
1024
|
+
let basicUserInfo = {
|
|
1025
|
+
allowedScopes: sessionData.scope,
|
|
1026
|
+
sessionState: sessionData.session_state
|
|
1027
|
+
};
|
|
1028
|
+
Object.keys(authenticatedUser).forEach((key) => {
|
|
1029
|
+
if (authenticatedUser[key] === void 0 || authenticatedUser[key] === "" || authenticatedUser[key] === null) {
|
|
1030
|
+
delete authenticatedUser[key];
|
|
1031
|
+
}
|
|
1032
|
+
});
|
|
1033
|
+
basicUserInfo = { ...basicUserInfo, ...authenticatedUser };
|
|
1034
|
+
return basicUserInfo;
|
|
1035
|
+
}
|
|
1036
|
+
async getDecodedIDToken(userID) {
|
|
1037
|
+
const idToken = (await this._dataLayer.getSessionData(userID)).id_token;
|
|
1038
|
+
const payload = this._cryptoHelper.decodeIDToken(idToken);
|
|
1039
|
+
return payload;
|
|
1040
|
+
}
|
|
1041
|
+
async getCryptoHelper() {
|
|
1042
|
+
return this._cryptoHelper;
|
|
1043
|
+
}
|
|
1044
|
+
async getIDToken(userID) {
|
|
1045
|
+
return (await this._dataLayer.getSessionData(userID)).id_token;
|
|
1046
|
+
}
|
|
1047
|
+
async getOIDCProviderMetaData(forceInit) {
|
|
1048
|
+
const configData = await this._config();
|
|
1049
|
+
if (!forceInit && await this._dataLayer.getTemporaryDataParameter(
|
|
1050
|
+
OIDCDiscoveryConstants_default.Storage.StorageKeys.OPENID_PROVIDER_CONFIG_INITIATED
|
|
1051
|
+
)) {
|
|
1052
|
+
return Promise.resolve();
|
|
1053
|
+
}
|
|
1054
|
+
const wellKnownEndpoint = configData.wellKnownEndpoint;
|
|
1055
|
+
if (wellKnownEndpoint) {
|
|
1056
|
+
let response;
|
|
1057
|
+
try {
|
|
1058
|
+
response = await fetch(wellKnownEndpoint);
|
|
1059
|
+
if (response.status !== 200 || !response.ok) {
|
|
1060
|
+
throw new Error();
|
|
1061
|
+
}
|
|
1062
|
+
} catch {
|
|
1063
|
+
throw new AsgardeoAuthException(
|
|
1064
|
+
"JS-AUTH_CORE-GOPMD-HE01",
|
|
1065
|
+
"Invalid well-known response",
|
|
1066
|
+
"The well known endpoint response has been failed with an error."
|
|
1067
|
+
);
|
|
1068
|
+
}
|
|
1069
|
+
await this._dataLayer.setOIDCProviderMetaData(
|
|
1070
|
+
await this._authenticationHelper.resolveEndpoints(await response.json())
|
|
1071
|
+
);
|
|
1072
|
+
await this._dataLayer.setTemporaryDataParameter(
|
|
1073
|
+
OIDCDiscoveryConstants_default.Storage.StorageKeys.OPENID_PROVIDER_CONFIG_INITIATED,
|
|
1074
|
+
true
|
|
1075
|
+
);
|
|
1076
|
+
return Promise.resolve();
|
|
1077
|
+
} else if (configData.baseUrl) {
|
|
1078
|
+
try {
|
|
1079
|
+
await this._dataLayer.setOIDCProviderMetaData(await this._authenticationHelper.resolveEndpointsByBaseURL());
|
|
1080
|
+
} catch (error) {
|
|
1081
|
+
throw new AsgardeoAuthException(
|
|
1082
|
+
"JS-AUTH_CORE-GOPMD-IV02",
|
|
1083
|
+
"Resolving endpoints failed.",
|
|
1084
|
+
error ?? "Resolving endpoints by base url failed."
|
|
1085
|
+
);
|
|
1086
|
+
}
|
|
1087
|
+
await this._dataLayer.setTemporaryDataParameter(
|
|
1088
|
+
OIDCDiscoveryConstants_default.Storage.StorageKeys.OPENID_PROVIDER_CONFIG_INITIATED,
|
|
1089
|
+
true
|
|
1090
|
+
);
|
|
1091
|
+
return Promise.resolve();
|
|
1092
|
+
} else {
|
|
1093
|
+
await this._dataLayer.setOIDCProviderMetaData(await this._authenticationHelper.resolveEndpointsExplicitly());
|
|
1094
|
+
await this._dataLayer.setTemporaryDataParameter(
|
|
1095
|
+
OIDCDiscoveryConstants_default.Storage.StorageKeys.OPENID_PROVIDER_CONFIG_INITIATED,
|
|
1096
|
+
true
|
|
1097
|
+
);
|
|
1098
|
+
return Promise.resolve();
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
// TODO: Remove `Partial<OIDCEndpoints>` once the refactoring is done.
|
|
1102
|
+
async getOIDCServiceEndpoints() {
|
|
1103
|
+
const oidcProviderMetaData = await this._oidcProviderMetaData();
|
|
1104
|
+
return {
|
|
1105
|
+
authorizationEndpoint: oidcProviderMetaData.authorization_endpoint ?? "",
|
|
1106
|
+
checkSessionIframe: oidcProviderMetaData.check_session_iframe ?? "",
|
|
1107
|
+
endSessionEndpoint: oidcProviderMetaData.end_session_endpoint ?? "",
|
|
1108
|
+
introspectionEndpoint: oidcProviderMetaData.introspection_endpoint ?? "",
|
|
1109
|
+
issuer: oidcProviderMetaData.issuer ?? "",
|
|
1110
|
+
jwksUri: oidcProviderMetaData.jwks_uri ?? "",
|
|
1111
|
+
registrationEndpoint: oidcProviderMetaData.registration_endpoint ?? "",
|
|
1112
|
+
revocationEndpoint: oidcProviderMetaData.revocation_endpoint ?? "",
|
|
1113
|
+
tokenEndpoint: oidcProviderMetaData.token_endpoint ?? "",
|
|
1114
|
+
userinfoEndpoint: oidcProviderMetaData.userinfo_endpoint ?? ""
|
|
1115
|
+
};
|
|
1116
|
+
}
|
|
1117
|
+
async getSignOutURL(userID) {
|
|
1118
|
+
const logoutEndpoint = (await this._oidcProviderMetaData())?.end_session_endpoint;
|
|
1119
|
+
const configData = await this._config();
|
|
1120
|
+
if (!logoutEndpoint || logoutEndpoint.trim().length === 0) {
|
|
1121
|
+
throw new AsgardeoAuthException(
|
|
1122
|
+
"JS-AUTH_CORE-GSOU-NF01",
|
|
1123
|
+
"Sign-out endpoint not found.",
|
|
1124
|
+
"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."
|
|
1125
|
+
);
|
|
1126
|
+
}
|
|
1127
|
+
const callbackURL = configData?.signOutRedirectURL ?? configData?.signInRedirectURL;
|
|
1128
|
+
if (!callbackURL || callbackURL.trim().length === 0) {
|
|
1129
|
+
throw new AsgardeoAuthException(
|
|
1130
|
+
"JS-AUTH_CORE-GSOU-NF03",
|
|
1131
|
+
"No sign-out redirect URL found.",
|
|
1132
|
+
"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. "
|
|
1133
|
+
);
|
|
1134
|
+
}
|
|
1135
|
+
const queryParams = new URLSearchParams();
|
|
1136
|
+
queryParams.set("post_logout_redirect_uri", callbackURL);
|
|
1137
|
+
if (configData.sendIdTokenInLogoutRequest) {
|
|
1138
|
+
const idToken = (await this._dataLayer.getSessionData(userID))?.id_token;
|
|
1139
|
+
if (!idToken || idToken.trim().length === 0) {
|
|
1140
|
+
throw new AsgardeoAuthException(
|
|
1141
|
+
"JS-AUTH_CORE-GSOU-NF02",
|
|
1142
|
+
"ID token not found.",
|
|
1143
|
+
"No ID token could be found. Either the session information is lost or you have not signed in."
|
|
1144
|
+
);
|
|
1145
|
+
}
|
|
1146
|
+
queryParams.set("id_token_hint", idToken);
|
|
1147
|
+
} else {
|
|
1148
|
+
queryParams.set("client_id", configData.clientID);
|
|
1149
|
+
}
|
|
1150
|
+
queryParams.set("state", OIDCRequestConstants_default.Params.SIGN_OUT_SUCCESS);
|
|
1151
|
+
return `${logoutEndpoint}?${queryParams.toString()}`;
|
|
1152
|
+
}
|
|
1153
|
+
async clearUserSessionData(userID) {
|
|
1154
|
+
await this._authenticationHelper.clearUserSessionData(userID);
|
|
1155
|
+
}
|
|
1156
|
+
async getAccessToken(userID) {
|
|
1157
|
+
return (await this._dataLayer.getSessionData(userID))?.access_token;
|
|
1158
|
+
}
|
|
1159
|
+
/**
|
|
1160
|
+
* The created timestamp of the token response in milliseconds.
|
|
1161
|
+
*
|
|
1162
|
+
* @param userID - User ID
|
|
1163
|
+
* @returns Created at timestamp of the token response in milliseconds.
|
|
1164
|
+
*/
|
|
1165
|
+
async getCreatedAt(userID) {
|
|
1166
|
+
return (await this._dataLayer.getSessionData(userID))?.created_at;
|
|
1167
|
+
}
|
|
1168
|
+
/**
|
|
1169
|
+
* The expires timestamp of the token response in seconds.
|
|
1170
|
+
*
|
|
1171
|
+
* @param userID - User ID
|
|
1172
|
+
* @returns Expires in timestamp of the token response in seconds.
|
|
1173
|
+
*/
|
|
1174
|
+
async getExpiresIn(userID) {
|
|
1175
|
+
return (await this._dataLayer.getSessionData(userID))?.expires_in;
|
|
1176
|
+
}
|
|
1177
|
+
async isAuthenticated(userID) {
|
|
1178
|
+
const isAccessTokenAvailable = Boolean(await this.getAccessToken(userID));
|
|
1179
|
+
const createdAt = await this.getCreatedAt(userID);
|
|
1180
|
+
const expiresInString = await this.getExpiresIn(userID);
|
|
1181
|
+
if (!expiresInString) {
|
|
1182
|
+
return false;
|
|
1183
|
+
}
|
|
1184
|
+
const expiresIn = parseInt(expiresInString) * 1e3;
|
|
1185
|
+
const currentTime = (/* @__PURE__ */ new Date()).getTime();
|
|
1186
|
+
const isAccessTokenValid = createdAt + expiresIn > currentTime;
|
|
1187
|
+
const isAuthenticated = isAccessTokenAvailable && isAccessTokenValid;
|
|
1188
|
+
return isAuthenticated;
|
|
1189
|
+
}
|
|
1190
|
+
async getPKCECode(state, userID) {
|
|
1191
|
+
return await this._dataLayer.getTemporaryDataParameter(extractPkceStorageKeyFromState_default(state), userID);
|
|
1192
|
+
}
|
|
1193
|
+
async setPKCECode(pkce, state, userID) {
|
|
1194
|
+
return await this._dataLayer.setTemporaryDataParameter(extractPkceStorageKeyFromState_default(state), pkce, userID);
|
|
1195
|
+
}
|
|
1196
|
+
async updateConfig(config) {
|
|
1197
|
+
await this._dataLayer.setConfigData(config);
|
|
1198
|
+
await this.getOIDCProviderMetaData(true);
|
|
1199
|
+
}
|
|
1200
|
+
};
|
|
1201
|
+
|
|
1202
|
+
// src/__legacy__/data/data-layer.ts
|
|
1203
|
+
var ASGARDEO_SESSION_ACTIVE = "asgardeo-session-active";
|
|
1204
|
+
var DataLayer = class {
|
|
1205
|
+
constructor(instanceID, store) {
|
|
1206
|
+
__publicField(this, "_id");
|
|
1207
|
+
__publicField(this, "_store");
|
|
1208
|
+
this._id = instanceID;
|
|
1209
|
+
this._store = store;
|
|
1210
|
+
}
|
|
1211
|
+
async setDataInBulk(key, data) {
|
|
1212
|
+
const existingDataJSON = await this._store.getData(key) ?? null;
|
|
1213
|
+
const existingData = existingDataJSON && JSON.parse(existingDataJSON);
|
|
1214
|
+
const dataToBeSaved = { ...existingData, ...data };
|
|
1215
|
+
const dataToBeSavedJSON = JSON.stringify(dataToBeSaved);
|
|
1216
|
+
await this._store.setData(key, dataToBeSavedJSON);
|
|
1217
|
+
}
|
|
1218
|
+
async setValue(key, attribute, value) {
|
|
1219
|
+
const existingDataJSON = await this._store.getData(key) ?? null;
|
|
1220
|
+
const existingData = existingDataJSON && JSON.parse(existingDataJSON);
|
|
1221
|
+
const dataToBeSaved = { ...existingData, [attribute]: value };
|
|
1222
|
+
const dataToBeSavedJSON = JSON.stringify(dataToBeSaved);
|
|
1223
|
+
await this._store.setData(key, dataToBeSavedJSON);
|
|
1224
|
+
}
|
|
1225
|
+
async removeValue(key, attribute) {
|
|
1226
|
+
const existingDataJSON = await this._store.getData(key) ?? null;
|
|
1227
|
+
const existingData = existingDataJSON && JSON.parse(existingDataJSON);
|
|
1228
|
+
const dataToBeSaved = { ...existingData };
|
|
1229
|
+
delete dataToBeSaved[attribute];
|
|
1230
|
+
const dataToBeSavedJSON = JSON.stringify(dataToBeSaved);
|
|
1231
|
+
await this._store.setData(key, dataToBeSavedJSON);
|
|
1232
|
+
}
|
|
1233
|
+
_resolveKey(store, userID) {
|
|
1234
|
+
return userID ? `${store}-${this._id}-${userID}` : `${store}-${this._id}`;
|
|
1235
|
+
}
|
|
1236
|
+
isLocalStorageAvailable() {
|
|
1237
|
+
try {
|
|
1238
|
+
const testValue = "__ASGARDEO_AUTH_CORE_LOCAL_STORAGE_TEST__";
|
|
1239
|
+
localStorage.setItem(testValue, testValue);
|
|
1240
|
+
localStorage.removeItem(testValue);
|
|
1241
|
+
return true;
|
|
1242
|
+
} catch (error) {
|
|
1243
|
+
return false;
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
async setConfigData(config) {
|
|
1247
|
+
await this.setDataInBulk(this._resolveKey("config_data" /* ConfigData */), config);
|
|
1248
|
+
}
|
|
1249
|
+
async setOIDCProviderMetaData(oidcProviderMetaData) {
|
|
1250
|
+
this.setDataInBulk(this._resolveKey("oidc_provider_meta_data" /* OIDCProviderMetaData */), oidcProviderMetaData);
|
|
1251
|
+
}
|
|
1252
|
+
async setTemporaryData(temporaryData, userID) {
|
|
1253
|
+
this.setDataInBulk(this._resolveKey("temporary_data" /* TemporaryData */, userID), temporaryData);
|
|
1254
|
+
}
|
|
1255
|
+
async setSessionData(sessionData, userID) {
|
|
1256
|
+
this.setDataInBulk(this._resolveKey("session_data" /* SessionData */, userID), sessionData);
|
|
1257
|
+
}
|
|
1258
|
+
async setCustomData(key, customData, userID) {
|
|
1259
|
+
this.setDataInBulk(this._resolveKey(key, userID), customData);
|
|
1260
|
+
}
|
|
1261
|
+
async getConfigData() {
|
|
1262
|
+
return JSON.parse(await this._store.getData(this._resolveKey("config_data" /* ConfigData */)) ?? null);
|
|
1263
|
+
}
|
|
1264
|
+
async getOIDCProviderMetaData() {
|
|
1265
|
+
return JSON.parse(await this._store.getData(this._resolveKey("oidc_provider_meta_data" /* OIDCProviderMetaData */)) ?? null);
|
|
1266
|
+
}
|
|
1267
|
+
async getTemporaryData(userID) {
|
|
1268
|
+
return JSON.parse(await this._store.getData(this._resolveKey("temporary_data" /* TemporaryData */, userID)) ?? null);
|
|
1269
|
+
}
|
|
1270
|
+
async getSessionData(userID) {
|
|
1271
|
+
return JSON.parse(await this._store.getData(this._resolveKey("session_data" /* SessionData */, userID)) ?? null);
|
|
1272
|
+
}
|
|
1273
|
+
async getCustomData(key, userID) {
|
|
1274
|
+
return JSON.parse(await this._store.getData(this._resolveKey(key, userID)) ?? null);
|
|
1275
|
+
}
|
|
1276
|
+
setSessionStatus(status) {
|
|
1277
|
+
this.isLocalStorageAvailable() && localStorage.setItem(`${ASGARDEO_SESSION_ACTIVE}`, status);
|
|
1278
|
+
}
|
|
1279
|
+
getSessionStatus() {
|
|
1280
|
+
return this.isLocalStorageAvailable() ? localStorage.getItem(`${ASGARDEO_SESSION_ACTIVE}`) ?? "" : "";
|
|
1281
|
+
}
|
|
1282
|
+
removeSessionStatus() {
|
|
1283
|
+
this.isLocalStorageAvailable() && localStorage.removeItem(`${ASGARDEO_SESSION_ACTIVE}`);
|
|
1284
|
+
}
|
|
1285
|
+
async removeConfigData() {
|
|
1286
|
+
await this._store.removeData(this._resolveKey("config_data" /* ConfigData */));
|
|
1287
|
+
}
|
|
1288
|
+
async removeOIDCProviderMetaData() {
|
|
1289
|
+
await this._store.removeData(this._resolveKey("oidc_provider_meta_data" /* OIDCProviderMetaData */));
|
|
1290
|
+
}
|
|
1291
|
+
async removeTemporaryData(userID) {
|
|
1292
|
+
await this._store.removeData(this._resolveKey("temporary_data" /* TemporaryData */, userID));
|
|
1293
|
+
}
|
|
1294
|
+
async removeSessionData(userID) {
|
|
1295
|
+
await this._store.removeData(this._resolveKey("session_data" /* SessionData */, userID));
|
|
1296
|
+
}
|
|
1297
|
+
async getConfigDataParameter(key) {
|
|
1298
|
+
const data = await this._store.getData(this._resolveKey("config_data" /* ConfigData */));
|
|
1299
|
+
return data && JSON.parse(data)[key];
|
|
1300
|
+
}
|
|
1301
|
+
async getOIDCProviderMetaDataParameter(key) {
|
|
1302
|
+
const data = await this._store.getData(this._resolveKey("oidc_provider_meta_data" /* OIDCProviderMetaData */));
|
|
1303
|
+
return data && JSON.parse(data)[key];
|
|
1304
|
+
}
|
|
1305
|
+
async getTemporaryDataParameter(key, userID) {
|
|
1306
|
+
const data = await this._store.getData(this._resolveKey("temporary_data" /* TemporaryData */, userID));
|
|
1307
|
+
return data && JSON.parse(data)[key];
|
|
1308
|
+
}
|
|
1309
|
+
async getSessionDataParameter(key, userID) {
|
|
1310
|
+
const data = await this._store.getData(this._resolveKey("session_data" /* SessionData */, userID));
|
|
1311
|
+
return data && JSON.parse(data)[key];
|
|
1312
|
+
}
|
|
1313
|
+
async setConfigDataParameter(key, value) {
|
|
1314
|
+
await this.setValue(this._resolveKey("config_data" /* ConfigData */), key, value);
|
|
1315
|
+
}
|
|
1316
|
+
async setOIDCProviderMetaDataParameter(key, value) {
|
|
1317
|
+
await this.setValue(this._resolveKey("oidc_provider_meta_data" /* OIDCProviderMetaData */), key, value);
|
|
1318
|
+
}
|
|
1319
|
+
async setTemporaryDataParameter(key, value, userID) {
|
|
1320
|
+
await this.setValue(this._resolveKey("temporary_data" /* TemporaryData */, userID), key, value);
|
|
1321
|
+
}
|
|
1322
|
+
async setSessionDataParameter(key, value, userID) {
|
|
1323
|
+
await this.setValue(this._resolveKey("session_data" /* SessionData */, userID), key, value);
|
|
1324
|
+
}
|
|
1325
|
+
async removeConfigDataParameter(key) {
|
|
1326
|
+
await this.removeValue(this._resolveKey("config_data" /* ConfigData */), key);
|
|
1327
|
+
}
|
|
1328
|
+
async removeOIDCProviderMetaDataParameter(key) {
|
|
1329
|
+
await this.removeValue(this._resolveKey("oidc_provider_meta_data" /* OIDCProviderMetaData */), key);
|
|
1330
|
+
}
|
|
1331
|
+
async removeTemporaryDataParameter(key, userID) {
|
|
1332
|
+
await this.removeValue(this._resolveKey("temporary_data" /* TemporaryData */, userID), key);
|
|
1333
|
+
}
|
|
1334
|
+
async removeSessionDataParameter(key, userID) {
|
|
1335
|
+
await this.removeValue(this._resolveKey("session_data" /* SessionData */, userID), key);
|
|
1336
|
+
}
|
|
1337
|
+
};
|
|
1338
|
+
|
|
1339
|
+
// src/models/oauth-response.ts
|
|
1340
|
+
var ResponseMode = /* @__PURE__ */ ((ResponseMode2) => {
|
|
1341
|
+
ResponseMode2["FormPost"] = "form_post";
|
|
1342
|
+
ResponseMode2["Query"] = "query";
|
|
1343
|
+
ResponseMode2["Direct"] = "direct";
|
|
1344
|
+
return ResponseMode2;
|
|
1345
|
+
})(ResponseMode || {});
|
|
1346
|
+
|
|
1347
|
+
// src/__legacy__/client.ts
|
|
1348
|
+
var DefaultConfig = {
|
|
1349
|
+
clockTolerance: 300,
|
|
1350
|
+
enablePKCE: true,
|
|
1351
|
+
responseMode: "query" /* Query */,
|
|
1352
|
+
scope: [ScopeConstants_default.OPENID],
|
|
1353
|
+
sendCookiesInRequests: true,
|
|
1354
|
+
validateIDToken: true,
|
|
1355
|
+
validateIDTokenIssuer: true
|
|
1356
|
+
};
|
|
1357
|
+
var _AsgardeoAuthClient = class _AsgardeoAuthClient {
|
|
1358
|
+
/**
|
|
1359
|
+
* This is the constructor method that returns an instance of the .
|
|
1360
|
+
*
|
|
1361
|
+
* @param store - The store object.
|
|
1362
|
+
*
|
|
1363
|
+
* @example
|
|
1364
|
+
* ```
|
|
1365
|
+
* const _store: Store = new DataStore();
|
|
1366
|
+
* const auth = new AsgardeoAuthClient<CustomClientConfig>(_store);
|
|
1367
|
+
* ```
|
|
1368
|
+
*
|
|
1369
|
+
* {@link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#constructor}
|
|
1370
|
+
*
|
|
1371
|
+
* @preserve
|
|
1372
|
+
*/
|
|
1373
|
+
constructor() {
|
|
1374
|
+
__publicField(this, "_dataLayer");
|
|
1375
|
+
__publicField(this, "_authenticationCore");
|
|
1376
|
+
}
|
|
1377
|
+
/**
|
|
1378
|
+
*
|
|
1379
|
+
* This method initializes the SDK with the config data.
|
|
1380
|
+
*
|
|
1381
|
+
* @param config - The config object to initialize with.
|
|
1382
|
+
*
|
|
1383
|
+
* @example
|
|
1384
|
+
* const config = \{
|
|
1385
|
+
* signInRedirectURL: "http://localhost:3000/sign-in",
|
|
1386
|
+
* clientID: "client ID",
|
|
1387
|
+
* baseUrl: "https://localhost:9443"
|
|
1388
|
+
* \}
|
|
1389
|
+
*
|
|
1390
|
+
* await auth.initialize(config);
|
|
1391
|
+
*
|
|
1392
|
+
* {@link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#initialize}
|
|
1393
|
+
*
|
|
1394
|
+
* @preserve
|
|
1395
|
+
*/
|
|
1396
|
+
async initialize(config, store, cryptoUtils, instanceID) {
|
|
1397
|
+
const clientId = config.clientID;
|
|
1398
|
+
if (!_AsgardeoAuthClient._instanceID) {
|
|
1399
|
+
_AsgardeoAuthClient._instanceID = 0;
|
|
1400
|
+
} else {
|
|
1401
|
+
_AsgardeoAuthClient._instanceID += 1;
|
|
1402
|
+
}
|
|
1403
|
+
if (instanceID) {
|
|
1404
|
+
_AsgardeoAuthClient._instanceID = instanceID;
|
|
1405
|
+
}
|
|
1406
|
+
if (!clientId) {
|
|
1407
|
+
this._dataLayer = new DataLayer(`instance_${_AsgardeoAuthClient._instanceID}`, store);
|
|
1408
|
+
} else {
|
|
1409
|
+
this._dataLayer = new DataLayer(`instance_${_AsgardeoAuthClient._instanceID}-${clientId}`, store);
|
|
1410
|
+
}
|
|
1411
|
+
this._authenticationCore = new AuthenticationCore(this._dataLayer, cryptoUtils);
|
|
1412
|
+
_AsgardeoAuthClient._authenticationCore = new AuthenticationCore(this._dataLayer, cryptoUtils);
|
|
1413
|
+
await this._dataLayer.setConfigData({
|
|
1414
|
+
...DefaultConfig,
|
|
1415
|
+
...config,
|
|
1416
|
+
scope: [
|
|
1417
|
+
...DefaultConfig.scope ?? [],
|
|
1418
|
+
...config.scope?.filter((scope) => !DefaultConfig?.scope?.includes(scope)) ?? []
|
|
1419
|
+
]
|
|
1420
|
+
});
|
|
1421
|
+
}
|
|
1422
|
+
/**
|
|
1423
|
+
* This method returns the `DataLayer` object that allows you to access authentication data.
|
|
1424
|
+
*
|
|
1425
|
+
* @returns - The `DataLayer` object.
|
|
1426
|
+
*
|
|
1427
|
+
* @example
|
|
1428
|
+
* ```
|
|
1429
|
+
* const data = auth.getDataLayer();
|
|
1430
|
+
* ```
|
|
1431
|
+
*
|
|
1432
|
+
* {@link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getDataLayer}
|
|
1433
|
+
*
|
|
1434
|
+
* @preserve
|
|
1435
|
+
*/
|
|
1436
|
+
getDataLayer() {
|
|
1437
|
+
return this._dataLayer;
|
|
1438
|
+
}
|
|
1439
|
+
/**
|
|
1440
|
+
* This method returns the `instanceID` variable of the given instance.
|
|
1441
|
+
*
|
|
1442
|
+
* @returns - The `instanceID` number.
|
|
1443
|
+
*
|
|
1444
|
+
* @example
|
|
1445
|
+
* ```
|
|
1446
|
+
* const instanceId = auth.getInstanceID();
|
|
1447
|
+
* ```
|
|
1448
|
+
*
|
|
1449
|
+
* @preserve
|
|
1450
|
+
*/
|
|
1451
|
+
getInstanceID() {
|
|
1452
|
+
return _AsgardeoAuthClient._instanceID;
|
|
1453
|
+
}
|
|
1454
|
+
/**
|
|
1455
|
+
* This is an async method that returns a Promise that resolves with the authorization URL parameters.
|
|
1456
|
+
*
|
|
1457
|
+
* @param config - (Optional) A config object to force initialization and pass
|
|
1458
|
+
* custom path parameters such as the `fidp` parameter.
|
|
1459
|
+
* @param userID - (Optional) A unique ID of the user to be authenticated. This is useful in multi-user
|
|
1460
|
+
* scenarios where each user should be uniquely identified.
|
|
1461
|
+
*
|
|
1462
|
+
* @returns - A promise that resolves with the authorization URL parameters.
|
|
1463
|
+
*
|
|
1464
|
+
* @example
|
|
1465
|
+
* ```
|
|
1466
|
+
* auth.getAuthorizationURLParams().then((params)=>{
|
|
1467
|
+
* // console.log(params);
|
|
1468
|
+
* }).catch((error)=>{
|
|
1469
|
+
* // console.error(error);
|
|
1470
|
+
* });
|
|
1471
|
+
* ```
|
|
1472
|
+
*
|
|
1473
|
+
* {@link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getAuthorizationURLParams}
|
|
1474
|
+
*
|
|
1475
|
+
* @preserve
|
|
1476
|
+
*/
|
|
1477
|
+
async getAuthorizationURLParams(config, userID) {
|
|
1478
|
+
const authRequestConfig = { ...config };
|
|
1479
|
+
delete authRequestConfig?.forceInit;
|
|
1480
|
+
if (await this._dataLayer.getTemporaryDataParameter(
|
|
1481
|
+
OIDCDiscoveryConstants_default.Storage.StorageKeys.OPENID_PROVIDER_CONFIG_INITIATED
|
|
1482
|
+
)) {
|
|
1483
|
+
return this._authenticationCore.getAuthorizationURLParams(authRequestConfig, userID);
|
|
1484
|
+
}
|
|
1485
|
+
return this._authenticationCore.getOIDCProviderMetaData(config?.forceInit).then(() => {
|
|
1486
|
+
return this._authenticationCore.getAuthorizationURLParams(authRequestConfig, userID);
|
|
1487
|
+
});
|
|
1488
|
+
}
|
|
1489
|
+
/**
|
|
1490
|
+
* This is an async method that returns a Promise that resolves with the authorization URL.
|
|
1491
|
+
*
|
|
1492
|
+
* @param config - (Optional) A config object to force initialization and pass
|
|
1493
|
+
* custom path parameters such as the fidp parameter.
|
|
1494
|
+
* @param userID - (Optional) A unique ID of the user to be authenticated. This is useful in multi-user
|
|
1495
|
+
* scenarios where each user should be uniquely identified.
|
|
1496
|
+
*
|
|
1497
|
+
* @returns - A promise that resolves with the authorization URL.
|
|
1498
|
+
*
|
|
1499
|
+
* @example
|
|
1500
|
+
* ```
|
|
1501
|
+
* auth.getAuthorizationURL().then((url)=>{
|
|
1502
|
+
* // console.log(url);
|
|
1503
|
+
* }).catch((error)=>{
|
|
1504
|
+
* // console.error(error);
|
|
1505
|
+
* });
|
|
1506
|
+
* ```
|
|
1507
|
+
*
|
|
1508
|
+
* {@link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getAuthorizationURL}
|
|
1509
|
+
*
|
|
1510
|
+
* @preserve
|
|
1511
|
+
*/
|
|
1512
|
+
async getAuthorizationURL(config, userID) {
|
|
1513
|
+
const authRequestConfig = { ...config };
|
|
1514
|
+
delete authRequestConfig?.forceInit;
|
|
1515
|
+
if (await this._dataLayer.getTemporaryDataParameter(
|
|
1516
|
+
OIDCDiscoveryConstants_default.Storage.StorageKeys.OPENID_PROVIDER_CONFIG_INITIATED
|
|
1517
|
+
)) {
|
|
1518
|
+
return this._authenticationCore.getAuthorizationURL(authRequestConfig, userID);
|
|
1519
|
+
}
|
|
1520
|
+
return this._authenticationCore.getOIDCProviderMetaData(config?.forceInit).then(() => {
|
|
1521
|
+
return this._authenticationCore.getAuthorizationURL(authRequestConfig, userID);
|
|
1522
|
+
});
|
|
1523
|
+
}
|
|
1524
|
+
/**
|
|
1525
|
+
* This is an async method that sends a request to obtain the access token and returns a Promise
|
|
1526
|
+
* that resolves with the token and other relevant data.
|
|
1527
|
+
*
|
|
1528
|
+
* @param authorizationCode - The authorization code.
|
|
1529
|
+
* @param sessionState - The session state.
|
|
1530
|
+
* @param userID - (Optional) A unique ID of the user to be authenticated. This is useful in multi-user
|
|
1531
|
+
* scenarios where each user should be uniquely identified.
|
|
1532
|
+
*
|
|
1533
|
+
* @returns - A Promise that resolves with the token response.
|
|
1534
|
+
*
|
|
1535
|
+
* @example
|
|
1536
|
+
* ```
|
|
1537
|
+
* auth.requestAccessToken(authCode, sessionState).then((token)=>{
|
|
1538
|
+
* // console.log(token);
|
|
1539
|
+
* }).catch((error)=>{
|
|
1540
|
+
* // console.error(error);
|
|
1541
|
+
* });
|
|
1542
|
+
* ```
|
|
1543
|
+
*
|
|
1544
|
+
* {@link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#requestAccessToken}
|
|
1545
|
+
*
|
|
1546
|
+
*
|
|
1547
|
+
* @preserve
|
|
1548
|
+
*/
|
|
1549
|
+
async requestAccessToken(authorizationCode, sessionState, state, userID, tokenRequestConfig) {
|
|
1550
|
+
if (await this._dataLayer.getTemporaryDataParameter(
|
|
1551
|
+
OIDCDiscoveryConstants_default.Storage.StorageKeys.OPENID_PROVIDER_CONFIG_INITIATED
|
|
1552
|
+
)) {
|
|
1553
|
+
return this._authenticationCore.requestAccessToken(
|
|
1554
|
+
authorizationCode,
|
|
1555
|
+
sessionState,
|
|
1556
|
+
state,
|
|
1557
|
+
userID,
|
|
1558
|
+
tokenRequestConfig
|
|
1559
|
+
);
|
|
1560
|
+
}
|
|
1561
|
+
return this._authenticationCore.getOIDCProviderMetaData(false).then(() => {
|
|
1562
|
+
return this._authenticationCore.requestAccessToken(
|
|
1563
|
+
authorizationCode,
|
|
1564
|
+
sessionState,
|
|
1565
|
+
state,
|
|
1566
|
+
userID,
|
|
1567
|
+
tokenRequestConfig
|
|
1568
|
+
);
|
|
1569
|
+
});
|
|
1570
|
+
}
|
|
1571
|
+
/**
|
|
1572
|
+
* This method returns the sign-out URL.
|
|
1573
|
+
*
|
|
1574
|
+
* @param userID - (Optional) A unique ID of the user to be authenticated. This is useful in multi-user
|
|
1575
|
+
* scenarios where each user should be uniquely identified.
|
|
1576
|
+
*
|
|
1577
|
+
* **This doesn't clear the authentication data.**
|
|
1578
|
+
*
|
|
1579
|
+
* @returns - A Promise that resolves with the sign-out URL.
|
|
1580
|
+
*
|
|
1581
|
+
* @example
|
|
1582
|
+
* ```
|
|
1583
|
+
* const signOutUrl = await auth.getSignOutURL();
|
|
1584
|
+
* ```
|
|
1585
|
+
*
|
|
1586
|
+
* {@link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getSignOutURL}
|
|
1587
|
+
*
|
|
1588
|
+
* @preserve
|
|
1589
|
+
*/
|
|
1590
|
+
async getSignOutURL(userID) {
|
|
1591
|
+
return this._authenticationCore.getSignOutURL(userID);
|
|
1592
|
+
}
|
|
1593
|
+
/**
|
|
1594
|
+
* This method returns OIDC service endpoints that are fetched from the `.well-known` endpoint.
|
|
1595
|
+
*
|
|
1596
|
+
* @returns - A Promise that resolves with an object containing the OIDC service endpoints.
|
|
1597
|
+
*
|
|
1598
|
+
* @example
|
|
1599
|
+
* ```
|
|
1600
|
+
* const endpoints = await auth.getOIDCServiceEndpoints();
|
|
1601
|
+
* ```
|
|
1602
|
+
*
|
|
1603
|
+
* {@link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getOIDCServiceEndpoints}
|
|
1604
|
+
*
|
|
1605
|
+
* @preserve
|
|
1606
|
+
*/
|
|
1607
|
+
async getOIDCServiceEndpoints() {
|
|
1608
|
+
return this._authenticationCore.getOIDCServiceEndpoints();
|
|
1609
|
+
}
|
|
1610
|
+
/**
|
|
1611
|
+
* This method decodes the payload of the ID token and returns it.
|
|
1612
|
+
*
|
|
1613
|
+
* @param userID - (Optional) A unique ID of the user to be authenticated. This is useful in multi-user
|
|
1614
|
+
* scenarios where each user should be uniquely identified.
|
|
1615
|
+
*
|
|
1616
|
+
* @returns - A Promise that resolves with the decoded ID token payload.
|
|
1617
|
+
*
|
|
1618
|
+
* @example
|
|
1619
|
+
* ```
|
|
1620
|
+
* const decodedIdToken = await auth.getDecodedIDToken();
|
|
1621
|
+
* ```
|
|
1622
|
+
*
|
|
1623
|
+
* {@link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getDecodedIDToken}
|
|
1624
|
+
*
|
|
1625
|
+
* @preserve
|
|
1626
|
+
*/
|
|
1627
|
+
async getDecodedIDToken(userID) {
|
|
1628
|
+
return this._authenticationCore.getDecodedIDToken(userID);
|
|
1629
|
+
}
|
|
1630
|
+
/**
|
|
1631
|
+
* This method returns the ID token.
|
|
1632
|
+
*
|
|
1633
|
+
* @param userID - (Optional) A unique ID of the user to be authenticated. This is useful in multi-user
|
|
1634
|
+
* scenarios where each user should be uniquely identified.
|
|
1635
|
+
*
|
|
1636
|
+
* @returns - A Promise that resolves with the ID token.
|
|
1637
|
+
*
|
|
1638
|
+
* @example
|
|
1639
|
+
* ```
|
|
1640
|
+
* const idToken = await auth.getIDToken();
|
|
1641
|
+
* ```
|
|
1642
|
+
*
|
|
1643
|
+
* {@link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getIDToken}
|
|
1644
|
+
*
|
|
1645
|
+
* @preserve
|
|
1646
|
+
*/
|
|
1647
|
+
async getIDToken(userID) {
|
|
1648
|
+
return this._authenticationCore.getIDToken(userID);
|
|
1649
|
+
}
|
|
1650
|
+
/**
|
|
1651
|
+
* This method returns the basic user information obtained from the ID token.
|
|
1652
|
+
*
|
|
1653
|
+
* @param userID - (Optional) A unique ID of the user to be authenticated. This is useful in multi-user
|
|
1654
|
+
* scenarios where each user should be uniquely identified.
|
|
1655
|
+
*
|
|
1656
|
+
* @returns - A Promise that resolves with an object containing the basic user information.
|
|
1657
|
+
*
|
|
1658
|
+
* @example
|
|
1659
|
+
* ```
|
|
1660
|
+
* const userInfo = await auth.getBasicUserInfo();
|
|
1661
|
+
* ```
|
|
1662
|
+
*
|
|
1663
|
+
* {@link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getBasicUserInfo}
|
|
1664
|
+
*
|
|
1665
|
+
* @preserve
|
|
1666
|
+
*/
|
|
1667
|
+
async getBasicUserInfo(userID) {
|
|
1668
|
+
return this._authenticationCore.getBasicUserInfo(userID);
|
|
1669
|
+
}
|
|
1670
|
+
/**
|
|
1671
|
+
* This method returns the crypto helper object.
|
|
1672
|
+
*
|
|
1673
|
+
* @returns - A Promise that resolves with a IsomorphicCrypto object.
|
|
1674
|
+
*
|
|
1675
|
+
* @example
|
|
1676
|
+
* ```
|
|
1677
|
+
* const cryptoHelper = await auth.IsomorphicCrypto();
|
|
1678
|
+
* ```
|
|
1679
|
+
*
|
|
1680
|
+
* {@link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getCryptoHelper}
|
|
1681
|
+
*
|
|
1682
|
+
* @preserve
|
|
1683
|
+
*/
|
|
1684
|
+
async getCryptoHelper() {
|
|
1685
|
+
return this._authenticationCore.getCryptoHelper();
|
|
1686
|
+
}
|
|
1687
|
+
/**
|
|
1688
|
+
* This method revokes the access token.
|
|
1689
|
+
*
|
|
1690
|
+
* @param userID - (Optional) A unique ID of the user to be authenticated. This is useful in multi-user
|
|
1691
|
+
* scenarios where each user should be uniquely identified.
|
|
1692
|
+
*
|
|
1693
|
+
* **This method also clears the authentication data.**
|
|
1694
|
+
*
|
|
1695
|
+
* @returns - A Promise that returns the response of the revoke-access-token request.
|
|
1696
|
+
*
|
|
1697
|
+
* @example
|
|
1698
|
+
* ```
|
|
1699
|
+
* auth.revokeAccessToken().then((response)=>{
|
|
1700
|
+
* // console.log(response);
|
|
1701
|
+
* }).catch((error)=>{
|
|
1702
|
+
* // console.error(error);
|
|
1703
|
+
* });
|
|
1704
|
+
* ```
|
|
1705
|
+
*
|
|
1706
|
+
* {@link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#revokeAccessToken}
|
|
1707
|
+
*
|
|
1708
|
+
* @preserve
|
|
1709
|
+
*/
|
|
1710
|
+
revokeAccessToken(userID) {
|
|
1711
|
+
return this._authenticationCore.revokeAccessToken(userID);
|
|
1712
|
+
}
|
|
1713
|
+
/**
|
|
1714
|
+
* This method refreshes the access token and returns a Promise that resolves with the new access
|
|
1715
|
+
* token and other relevant data.
|
|
1716
|
+
*
|
|
1717
|
+
* @param userID - (Optional) A unique ID of the user to be authenticated. This is useful in multi-user
|
|
1718
|
+
* scenarios where each user should be uniquely identified.
|
|
1719
|
+
*
|
|
1720
|
+
* @returns - A Promise that resolves with the token response.
|
|
1721
|
+
*
|
|
1722
|
+
* @example
|
|
1723
|
+
* ```
|
|
1724
|
+
* auth.refreshAccessToken().then((response)=>{
|
|
1725
|
+
* // console.log(response);
|
|
1726
|
+
* }).catch((error)=>{
|
|
1727
|
+
* // console.error(error);
|
|
1728
|
+
* });
|
|
1729
|
+
* ```
|
|
1730
|
+
*
|
|
1731
|
+
* {@link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#refreshAccessToken}
|
|
1732
|
+
*
|
|
1733
|
+
* @preserve
|
|
1734
|
+
*/
|
|
1735
|
+
refreshAccessToken(userID) {
|
|
1736
|
+
return this._authenticationCore.refreshAccessToken(userID);
|
|
1737
|
+
}
|
|
1738
|
+
/**
|
|
1739
|
+
* This method returns the access token.
|
|
1740
|
+
*
|
|
1741
|
+
* @param userID - (Optional) A unique ID of the user to be authenticated. This is useful in multi-user
|
|
1742
|
+
* scenarios where each user should be uniquely identified.
|
|
1743
|
+
*
|
|
1744
|
+
* @returns - A Promise that resolves with the access token.
|
|
1745
|
+
*
|
|
1746
|
+
* @example
|
|
1747
|
+
* ```
|
|
1748
|
+
* const accessToken = await auth.getAccessToken();
|
|
1749
|
+
* ```
|
|
1750
|
+
*
|
|
1751
|
+
* {@link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getAccessToken}
|
|
1752
|
+
*
|
|
1753
|
+
* @preserve
|
|
1754
|
+
*/
|
|
1755
|
+
async getAccessToken(userID) {
|
|
1756
|
+
return this._authenticationCore.getAccessToken(userID);
|
|
1757
|
+
}
|
|
1758
|
+
/**
|
|
1759
|
+
* This method sends a custom-grant request and returns a Promise that resolves with the response
|
|
1760
|
+
* depending on the config passed.
|
|
1761
|
+
*
|
|
1762
|
+
* @param config - A config object containing the custom grant configurations.
|
|
1763
|
+
* @param userID - (Optional) A unique ID of the user to be authenticated. This is useful in multi-user
|
|
1764
|
+
* scenarios where each user should be uniquely identified.
|
|
1765
|
+
*
|
|
1766
|
+
* @returns - A Promise that resolves with the response depending
|
|
1767
|
+
* on your configurations.
|
|
1768
|
+
*
|
|
1769
|
+
* @example
|
|
1770
|
+
* ```
|
|
1771
|
+
* const config = {
|
|
1772
|
+
* attachToken: false,
|
|
1773
|
+
* data: {
|
|
1774
|
+
* client_id: "{{clientID}}",
|
|
1775
|
+
* grant_type: "account_switch",
|
|
1776
|
+
* scope: "{{scope}}",
|
|
1777
|
+
* token: "{{token}}",
|
|
1778
|
+
* },
|
|
1779
|
+
* id: "account-switch",
|
|
1780
|
+
* returnResponse: true,
|
|
1781
|
+
* returnsSession: true,
|
|
1782
|
+
* signInRequired: true
|
|
1783
|
+
* }
|
|
1784
|
+
*
|
|
1785
|
+
* auth.requestCustomGrant(config).then((response)=>{
|
|
1786
|
+
* // console.log(response);
|
|
1787
|
+
* }).catch((error)=>{
|
|
1788
|
+
* // console.error(error);
|
|
1789
|
+
* });
|
|
1790
|
+
* ```
|
|
1791
|
+
*
|
|
1792
|
+
* {@link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#requestCustomGrant}
|
|
1793
|
+
*
|
|
1794
|
+
* @preserve
|
|
1795
|
+
*/
|
|
1796
|
+
requestCustomGrant(config, userID) {
|
|
1797
|
+
return this._authenticationCore.requestCustomGrant(config, userID);
|
|
1798
|
+
}
|
|
1799
|
+
/**
|
|
1800
|
+
* This method returns if the user is authenticated or not.
|
|
1801
|
+
*
|
|
1802
|
+
* @param userID - (Optional) A unique ID of the user to be authenticated. This is useful in multi-user
|
|
1803
|
+
* scenarios where each user should be uniquely identified.
|
|
1804
|
+
*
|
|
1805
|
+
* @returns - A Promise that resolves with `true` if the user is authenticated, `false` otherwise.
|
|
1806
|
+
*
|
|
1807
|
+
* @example
|
|
1808
|
+
* ```
|
|
1809
|
+
* await auth.isAuthenticated();
|
|
1810
|
+
* ```
|
|
1811
|
+
*
|
|
1812
|
+
* {@link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#isAuthenticated}
|
|
1813
|
+
*
|
|
1814
|
+
* @preserve
|
|
1815
|
+
*/
|
|
1816
|
+
async isAuthenticated(userID) {
|
|
1817
|
+
return this._authenticationCore.isAuthenticated(userID);
|
|
1818
|
+
}
|
|
1819
|
+
/**
|
|
1820
|
+
* This method returns the PKCE code generated during the generation of the authentication URL.
|
|
1821
|
+
*
|
|
1822
|
+
* @param userID - (Optional) A unique ID of the user to be authenticated. This is useful in multi-user
|
|
1823
|
+
* scenarios where each user should be uniquely identified.
|
|
1824
|
+
* @param state - The state parameter that was passed in the authentication URL.
|
|
1825
|
+
*
|
|
1826
|
+
* @returns - A Promise that resolves with the PKCE code.
|
|
1827
|
+
*
|
|
1828
|
+
* @example
|
|
1829
|
+
* ```
|
|
1830
|
+
* const pkce = await getPKCECode();
|
|
1831
|
+
* ```
|
|
1832
|
+
*
|
|
1833
|
+
* {@link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getPKCECode}
|
|
1834
|
+
*
|
|
1835
|
+
* @preserve
|
|
1836
|
+
*/
|
|
1837
|
+
async getPKCECode(state, userID) {
|
|
1838
|
+
return this._authenticationCore.getPKCECode(state, userID);
|
|
1839
|
+
}
|
|
1840
|
+
/**
|
|
1841
|
+
* This method sets the PKCE code to the data store.
|
|
1842
|
+
*
|
|
1843
|
+
* @param pkce - The PKCE code.
|
|
1844
|
+
* @param state - The state parameter that was passed in the authentication URL.
|
|
1845
|
+
* @param userID - (Optional) A unique ID of the user to be authenticated. This is useful in multi-user
|
|
1846
|
+
* scenarios where each user should be uniquely identified.
|
|
1847
|
+
*
|
|
1848
|
+
* @example
|
|
1849
|
+
* ```
|
|
1850
|
+
* await auth.setPKCECode("pkce_code")
|
|
1851
|
+
* ```
|
|
1852
|
+
*
|
|
1853
|
+
* {@link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#setPKCECode}
|
|
1854
|
+
*
|
|
1855
|
+
* @preserve
|
|
1856
|
+
*/
|
|
1857
|
+
async setPKCECode(pkce, state, userID) {
|
|
1858
|
+
await this._authenticationCore.setPKCECode(pkce, state, userID);
|
|
1859
|
+
}
|
|
1860
|
+
/**
|
|
1861
|
+
* This method returns if the sign-out is successful or not.
|
|
1862
|
+
*
|
|
1863
|
+
* @param signOutRedirectUrl - The URL to which the user has been redirected to after signing-out.
|
|
1864
|
+
*
|
|
1865
|
+
* **The server appends path parameters to the `signOutRedirectURL` and these path parameters
|
|
1866
|
+
* are required for this method to function.**
|
|
1867
|
+
*
|
|
1868
|
+
* @returns - `true` if successful, `false` otherwise.
|
|
1869
|
+
*
|
|
1870
|
+
* {@link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#isSignOutSuccessful}
|
|
1871
|
+
*
|
|
1872
|
+
* @preserve
|
|
1873
|
+
*/
|
|
1874
|
+
static isSignOutSuccessful(signOutRedirectURL) {
|
|
1875
|
+
const url = new URL(signOutRedirectURL);
|
|
1876
|
+
const stateParam = url.searchParams.get(OIDCRequestConstants_default.Params.STATE);
|
|
1877
|
+
const error = Boolean(url.searchParams.get("error"));
|
|
1878
|
+
return stateParam ? stateParam === OIDCRequestConstants_default.Params.SIGN_OUT_SUCCESS && !error : false;
|
|
1879
|
+
}
|
|
1880
|
+
/**
|
|
1881
|
+
* This method returns if the sign-out has failed or not.
|
|
1882
|
+
*
|
|
1883
|
+
* @param signOutRedirectUrl - The URL to which the user has been redirected to after signing-out.
|
|
1884
|
+
*
|
|
1885
|
+
* **The server appends path parameters to the `signOutRedirectURL` and these path parameters
|
|
1886
|
+
* are required for this method to function.**
|
|
1887
|
+
*
|
|
1888
|
+
* @returns - `true` if successful, `false` otherwise.
|
|
1889
|
+
*
|
|
1890
|
+
* {@link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#didSignOutFail}
|
|
1891
|
+
*
|
|
1892
|
+
* @preserve
|
|
1893
|
+
*/
|
|
1894
|
+
static didSignOutFail(signOutRedirectURL) {
|
|
1895
|
+
const url = new URL(signOutRedirectURL);
|
|
1896
|
+
const stateParam = url.searchParams.get(OIDCRequestConstants_default.Params.STATE);
|
|
1897
|
+
const error = Boolean(url.searchParams.get("error"));
|
|
1898
|
+
return stateParam ? stateParam === OIDCRequestConstants_default.Params.SIGN_OUT_SUCCESS && error : false;
|
|
1899
|
+
}
|
|
1900
|
+
/**
|
|
1901
|
+
* This method updates the configuration that was passed into the constructor when instantiating this class.
|
|
1902
|
+
*
|
|
1903
|
+
* @param config - A config object to update the SDK configurations with.
|
|
1904
|
+
*
|
|
1905
|
+
* @example
|
|
1906
|
+
* ```
|
|
1907
|
+
* const config = {
|
|
1908
|
+
* signInRedirectURL: "http://localhost:3000/sign-in",
|
|
1909
|
+
* clientID: "client ID",
|
|
1910
|
+
* baseUrl: "https://localhost:9443"
|
|
1911
|
+
* }
|
|
1912
|
+
*
|
|
1913
|
+
* await auth.updateConfig(config);
|
|
1914
|
+
* ```
|
|
1915
|
+
* {@link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#updateConfig}
|
|
1916
|
+
*
|
|
1917
|
+
* @preserve
|
|
1918
|
+
*/
|
|
1919
|
+
async updateConfig(config) {
|
|
1920
|
+
await this._authenticationCore.updateConfig(config);
|
|
1921
|
+
}
|
|
1922
|
+
static async clearUserSessionData(userID) {
|
|
1923
|
+
await this._authenticationCore.clearUserSessionData(userID);
|
|
1924
|
+
}
|
|
1925
|
+
};
|
|
1926
|
+
__publicField(_AsgardeoAuthClient, "_instanceID");
|
|
1927
|
+
__publicField(_AsgardeoAuthClient, "_authenticationCore");
|
|
1928
|
+
var AsgardeoAuthClient = _AsgardeoAuthClient;
|
|
1929
|
+
|
|
1930
|
+
// src/errors/AsgardeoError.ts
|
|
1931
|
+
var AsgardeoError = class _AsgardeoError extends Error {
|
|
1932
|
+
constructor(message, code, origin) {
|
|
1933
|
+
const _origin = _AsgardeoError.resolveOrigin(origin);
|
|
1934
|
+
const prefix = `\u{1F6E1}\uFE0F Asgardeo - ${_origin}:`;
|
|
1935
|
+
const regex = new RegExp(`\u{1F6E1}\uFE0F\\s*Asgardeo\\s*-\\s*${_origin}:`, "i");
|
|
1936
|
+
const sanitized = message.replace(regex, "");
|
|
1937
|
+
const _message = `${prefix} ${sanitized.trim()}
|
|
1938
|
+
|
|
1939
|
+
(code="${code}")
|
|
1940
|
+
`;
|
|
1941
|
+
super(_message);
|
|
1942
|
+
__publicField(this, "code");
|
|
1943
|
+
__publicField(this, "origin");
|
|
1944
|
+
this.name = new.target.name;
|
|
1945
|
+
this.code = code;
|
|
1946
|
+
this.origin = _origin;
|
|
1947
|
+
if (Error.captureStackTrace) {
|
|
1948
|
+
Error.captureStackTrace(this, new.target);
|
|
1949
|
+
}
|
|
1950
|
+
}
|
|
1951
|
+
static resolveOrigin(origin) {
|
|
1952
|
+
if (!origin) {
|
|
1953
|
+
return "@asgardeo/javascript";
|
|
1954
|
+
}
|
|
1955
|
+
return `@asgardeo/${origin}`;
|
|
1956
|
+
}
|
|
1957
|
+
toString() {
|
|
1958
|
+
return `[${this.name}]
|
|
1959
|
+
Message: ${this.message}`;
|
|
1960
|
+
}
|
|
1961
|
+
};
|
|
1962
|
+
|
|
1963
|
+
// src/errors/AsgardeoAPIError.ts
|
|
1964
|
+
var AsgardeoAPIError = class extends AsgardeoError {
|
|
1965
|
+
/**
|
|
1966
|
+
* Creates an instance of AsgardeoAPIError.
|
|
1967
|
+
*
|
|
1968
|
+
* @param message - Human-readable description of the error
|
|
1969
|
+
* @param code - A unique error code that identifies the error type
|
|
1970
|
+
* @param statusCode - HTTP status code of the failed request
|
|
1971
|
+
* @param statusText - HTTP status text of the failed request
|
|
1972
|
+
* @param origin - Optional. The SDK origin (e.g. 'react', 'vue'). Defaults to generic 'Asgardeo'
|
|
1973
|
+
* @constructor
|
|
1974
|
+
*/
|
|
1975
|
+
constructor(message, code, origin, statusCode, statusText) {
|
|
1976
|
+
super(message, code, origin);
|
|
1977
|
+
this.statusCode = statusCode;
|
|
1978
|
+
this.statusText = statusText;
|
|
1979
|
+
Object.defineProperty(this, "name", {
|
|
1980
|
+
value: "AsgardeoAPIError",
|
|
1981
|
+
configurable: true,
|
|
1982
|
+
writable: true
|
|
1983
|
+
});
|
|
1984
|
+
}
|
|
1985
|
+
/**
|
|
1986
|
+
* Returns a string representation of the API error
|
|
1987
|
+
* @returns Formatted error string with name, code, status, and message
|
|
1988
|
+
*/
|
|
1989
|
+
toString() {
|
|
1990
|
+
const status = this.statusCode ? ` (HTTP ${this.statusCode} - ${this.statusText})` : "";
|
|
1991
|
+
return `[${this.name}] (code="${this.code}")${status}
|
|
1992
|
+
Message: ${this.message}`;
|
|
1993
|
+
}
|
|
1994
|
+
};
|
|
1995
|
+
|
|
1996
|
+
// src/api/oidc/getUserInfo.ts
|
|
1997
|
+
var getUserInfo = async ({ url, ...requestConfig }) => {
|
|
1998
|
+
try {
|
|
1999
|
+
new URL(url);
|
|
2000
|
+
} catch (error) {
|
|
2001
|
+
throw new AsgardeoAPIError(
|
|
2002
|
+
"Invalid endpoint URL provided",
|
|
2003
|
+
"getUserInfo-ValidationError-001",
|
|
2004
|
+
"javascript",
|
|
2005
|
+
400,
|
|
2006
|
+
"Invalid Request"
|
|
2007
|
+
);
|
|
2008
|
+
}
|
|
2009
|
+
const response = await fetch(url, {
|
|
2010
|
+
method: "GET",
|
|
2011
|
+
headers: {
|
|
2012
|
+
"Content-Type": "application/json",
|
|
2013
|
+
Accept: "application/json"
|
|
2014
|
+
},
|
|
2015
|
+
...requestConfig
|
|
2016
|
+
});
|
|
2017
|
+
if (!response.ok) {
|
|
2018
|
+
const errorText = await response.text();
|
|
2019
|
+
throw new AsgardeoAPIError(
|
|
2020
|
+
`Failed to fetch user info: ${errorText}`,
|
|
2021
|
+
"getUserInfo-ResponseError-001",
|
|
2022
|
+
"javascript",
|
|
2023
|
+
response.status,
|
|
2024
|
+
response.statusText
|
|
2025
|
+
);
|
|
2026
|
+
}
|
|
2027
|
+
return await response.json();
|
|
2028
|
+
};
|
|
2029
|
+
var getUserInfo_default = getUserInfo;
|
|
2030
|
+
|
|
2031
|
+
// src/errors/AsgardeoRuntimeError.ts
|
|
2032
|
+
var AsgardeoRuntimeError = class extends AsgardeoError {
|
|
2033
|
+
/**
|
|
2034
|
+
* Creates an instance of AsgardeoRuntimeError.
|
|
2035
|
+
*
|
|
2036
|
+
* @param message - Human-readable description of the error
|
|
2037
|
+
* @param code - A unique error code that identifies the error type
|
|
2038
|
+
* @param details - Additional details about the error that might be helpful for debugging
|
|
2039
|
+
* @param origin - Optional. The SDK origin (e.g. 'react', 'vue'). Defaults to generic 'Asgardeo'
|
|
2040
|
+
* @constructor
|
|
2041
|
+
*/
|
|
2042
|
+
constructor(message, code, origin, details) {
|
|
2043
|
+
super(message, code, origin);
|
|
2044
|
+
this.details = details;
|
|
2045
|
+
Object.defineProperty(this, "name", {
|
|
2046
|
+
value: "AsgardeoRuntimeError",
|
|
2047
|
+
configurable: true,
|
|
2048
|
+
writable: true
|
|
2049
|
+
});
|
|
2050
|
+
}
|
|
2051
|
+
/**
|
|
2052
|
+
* Returns a string representation of the runtime error
|
|
2053
|
+
* @returns Formatted error string with name, code, details, and message
|
|
2054
|
+
*/
|
|
2055
|
+
toString() {
|
|
2056
|
+
const details = this.details ? `
|
|
2057
|
+
Details: ${JSON.stringify(this.details, null, 2)}` : "";
|
|
2058
|
+
return `[${this.name}] (code="${this.code}")${details}
|
|
2059
|
+
Message: ${this.message}`;
|
|
2060
|
+
}
|
|
2061
|
+
};
|
|
2062
|
+
|
|
2063
|
+
// src/models/scim2-schema.ts
|
|
2064
|
+
var WellKnownSchemaIds = /* @__PURE__ */ ((WellKnownSchemaIds2) => {
|
|
2065
|
+
WellKnownSchemaIds2["Core"] = "urn:ietf:params:scim:schemas:core:2.0";
|
|
2066
|
+
WellKnownSchemaIds2["User"] = "urn:ietf:params:scim:schemas:core:2.0:User";
|
|
2067
|
+
WellKnownSchemaIds2["EnterpriseUser"] = "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User";
|
|
2068
|
+
WellKnownSchemaIds2["SystemUser"] = "urn:scim:wso2:schema";
|
|
2069
|
+
WellKnownSchemaIds2["CustomUser"] = "urn:scim:schemas:extension:custom:User";
|
|
2070
|
+
return WellKnownSchemaIds2;
|
|
2071
|
+
})(WellKnownSchemaIds || {});
|
|
2072
|
+
|
|
2073
|
+
// src/AsgardeoJavaScriptClient.ts
|
|
2074
|
+
var AsgardeoJavaScriptClient = class {
|
|
2075
|
+
};
|
|
2076
|
+
var AsgardeoJavaScriptClient_default = AsgardeoJavaScriptClient;
|
|
2077
|
+
|
|
2078
|
+
// src/theme/createTheme.ts
|
|
2079
|
+
var lightTheme = {
|
|
2080
|
+
colors: {
|
|
2081
|
+
primary: {
|
|
2082
|
+
main: "#1a73e8",
|
|
2083
|
+
contrastText: "#ffffff"
|
|
2084
|
+
},
|
|
2085
|
+
secondary: {
|
|
2086
|
+
main: "#424242",
|
|
2087
|
+
contrastText: "#ffffff"
|
|
2088
|
+
},
|
|
2089
|
+
background: {
|
|
2090
|
+
surface: "#f5f5f5",
|
|
2091
|
+
disabled: "#f0f0f0",
|
|
2092
|
+
body: {
|
|
2093
|
+
main: "#1a1a1a"
|
|
2094
|
+
}
|
|
2095
|
+
},
|
|
2096
|
+
error: {
|
|
2097
|
+
main: "#d32f2f",
|
|
2098
|
+
contrastText: "#ffffff"
|
|
2099
|
+
},
|
|
2100
|
+
surface: "#f5f5f5",
|
|
2101
|
+
text: {
|
|
2102
|
+
primary: "#1a1a1a",
|
|
2103
|
+
secondary: "#666666"
|
|
2104
|
+
},
|
|
2105
|
+
border: "#e0e0e0"
|
|
2106
|
+
},
|
|
2107
|
+
spacing: {
|
|
2108
|
+
unit: 8
|
|
2109
|
+
},
|
|
2110
|
+
borderRadius: {
|
|
2111
|
+
small: "4px",
|
|
2112
|
+
medium: "8px",
|
|
2113
|
+
large: "16px"
|
|
2114
|
+
}
|
|
2115
|
+
};
|
|
2116
|
+
var darkTheme = {
|
|
2117
|
+
colors: {
|
|
2118
|
+
primary: {
|
|
2119
|
+
main: "#1a73e8",
|
|
2120
|
+
contrastText: "#ffffff"
|
|
2121
|
+
},
|
|
2122
|
+
secondary: {
|
|
2123
|
+
main: "#424242",
|
|
2124
|
+
contrastText: "#ffffff"
|
|
2125
|
+
},
|
|
2126
|
+
background: {
|
|
2127
|
+
surface: "#121212",
|
|
2128
|
+
disabled: "#1f1f1f",
|
|
2129
|
+
body: {
|
|
2130
|
+
main: "#ffffff"
|
|
2131
|
+
}
|
|
2132
|
+
},
|
|
2133
|
+
error: {
|
|
2134
|
+
main: "#d32f2f",
|
|
2135
|
+
contrastText: "#ffffff"
|
|
2136
|
+
},
|
|
2137
|
+
surface: "#2d2d2d",
|
|
2138
|
+
text: {
|
|
2139
|
+
primary: "#ffffff",
|
|
2140
|
+
secondary: "#b3b3b3"
|
|
2141
|
+
},
|
|
2142
|
+
border: "#404040"
|
|
2143
|
+
},
|
|
2144
|
+
spacing: {
|
|
2145
|
+
unit: 8
|
|
2146
|
+
},
|
|
2147
|
+
borderRadius: {
|
|
2148
|
+
small: "4px",
|
|
2149
|
+
medium: "8px",
|
|
2150
|
+
large: "16px"
|
|
2151
|
+
}
|
|
2152
|
+
};
|
|
2153
|
+
var toCssVariables = (theme) => {
|
|
2154
|
+
const cssVars = {};
|
|
2155
|
+
cssVars["--asgardeo-color-primary-main"] = theme.colors.primary.main;
|
|
2156
|
+
cssVars["--asgardeo-color-primary-contrastText"] = theme.colors.primary.contrastText;
|
|
2157
|
+
cssVars["--asgardeo-color-secondary-main"] = theme.colors.secondary.main;
|
|
2158
|
+
cssVars["--asgardeo-color-secondary-contrastText"] = theme.colors.secondary.contrastText;
|
|
2159
|
+
cssVars["--asgardeo-color-background-surface"] = theme.colors.background.surface;
|
|
2160
|
+
cssVars["--asgardeo-color-background-disabled"] = theme.colors.background.disabled;
|
|
2161
|
+
cssVars["--asgardeo-color-background-body-main"] = theme.colors.background.body.main;
|
|
2162
|
+
cssVars["--asgardeo-color-error-main"] = theme.colors.error.main;
|
|
2163
|
+
cssVars["--asgardeo-color-error-contrastText"] = theme.colors.error.contrastText;
|
|
2164
|
+
cssVars["--asgardeo-color-surface"] = theme.colors.surface;
|
|
2165
|
+
cssVars["--asgardeo-color-text-primary"] = theme.colors.text.primary;
|
|
2166
|
+
cssVars["--asgardeo-color-text-secondary"] = theme.colors.text.secondary;
|
|
2167
|
+
cssVars["--asgardeo-color-border"] = theme.colors.border;
|
|
2168
|
+
cssVars["--asgardeo-spacing-unit"] = `${theme.spacing.unit}px`;
|
|
2169
|
+
cssVars["--asgardeo-border-radius-small"] = theme.borderRadius.small;
|
|
2170
|
+
cssVars["--asgardeo-border-radius-medium"] = theme.borderRadius.medium;
|
|
2171
|
+
cssVars["--asgardeo-border-radius-large"] = theme.borderRadius.large;
|
|
2172
|
+
return cssVars;
|
|
2173
|
+
};
|
|
2174
|
+
var createTheme = (config = {}, isDark = false) => {
|
|
2175
|
+
const baseTheme = isDark ? darkTheme : lightTheme;
|
|
2176
|
+
const mergedConfig = {
|
|
2177
|
+
...baseTheme,
|
|
2178
|
+
...config,
|
|
2179
|
+
colors: {
|
|
2180
|
+
...baseTheme.colors,
|
|
2181
|
+
...config.colors,
|
|
2182
|
+
secondary: {
|
|
2183
|
+
...baseTheme.colors.secondary,
|
|
2184
|
+
...config.colors?.secondary || {}
|
|
2185
|
+
}
|
|
2186
|
+
},
|
|
2187
|
+
spacing: {
|
|
2188
|
+
...baseTheme.spacing,
|
|
2189
|
+
...config.spacing
|
|
2190
|
+
},
|
|
2191
|
+
borderRadius: {
|
|
2192
|
+
...baseTheme.borderRadius,
|
|
2193
|
+
...config.borderRadius
|
|
2194
|
+
}
|
|
2195
|
+
};
|
|
2196
|
+
return {
|
|
2197
|
+
...mergedConfig,
|
|
2198
|
+
cssVariables: toCssVariables(mergedConfig)
|
|
2199
|
+
};
|
|
2200
|
+
};
|
|
2201
|
+
var createTheme_default = createTheme;
|
|
2202
|
+
|
|
2203
|
+
// src/utils/removeTrailingSlash.ts
|
|
2204
|
+
var removeTrailingSlash = (path) => path.endsWith("/") ? path.slice(0, -1) : path;
|
|
2205
|
+
var removeTrailingSlash_default = removeTrailingSlash;
|
|
2206
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
2207
|
+
0 && (module.exports = {
|
|
2208
|
+
ASGARDEO_SESSION_ACTIVE,
|
|
2209
|
+
AsgardeoAPIError,
|
|
2210
|
+
AsgardeoAuthClient,
|
|
2211
|
+
AsgardeoAuthException,
|
|
2212
|
+
AsgardeoError,
|
|
2213
|
+
AsgardeoJavaScriptClient,
|
|
2214
|
+
AsgardeoRuntimeError,
|
|
2215
|
+
DataLayer,
|
|
2216
|
+
IsomorphicCrypto,
|
|
2217
|
+
OIDCRequestConstants,
|
|
2218
|
+
ResponseMode,
|
|
2219
|
+
TokenConstants,
|
|
2220
|
+
WellKnownSchemaIds,
|
|
2221
|
+
createTheme,
|
|
2222
|
+
extractPkceStorageKeyFromState,
|
|
2223
|
+
extractUserClaimsFromIdToken,
|
|
2224
|
+
getUserInfo,
|
|
2225
|
+
removeTrailingSlash
|
|
2226
|
+
});
|
|
2227
|
+
//# sourceMappingURL=index.js.map
|