@asgardeo/javascript 0.4.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/AsgardeoJavaScriptClient.d.ts +2 -0
- package/dist/IsomorphicCrypto.d.ts +1 -11
- package/dist/__legacy__/client.d.ts +12 -0
- package/dist/cjs/index.js +20 -15
- package/dist/cjs/index.js.map +2 -2
- package/dist/index.js +20 -15
- package/dist/index.js.map +2 -2
- package/dist/models/client.d.ts +12 -0
- package/dist/models/embedded-flow.d.ts +1 -0
- package/dist/models/v2/embedded-flow-v2.d.ts +5 -0
- package/package.json +2 -2
|
@@ -54,5 +54,7 @@ declare abstract class AsgardeoJavaScriptClient<T = Config> implements AsgardeoC
|
|
|
54
54
|
abstract signUp(payload?: unknown): Promise<void> | Promise<EmbeddedFlowExecuteResponse>;
|
|
55
55
|
abstract getAccessToken(sessionId?: string): Promise<string>;
|
|
56
56
|
abstract clearSession(sessionId?: string): void;
|
|
57
|
+
abstract setSession(sessionData: Record<string, unknown>, sessionId?: string): Promise<void>;
|
|
58
|
+
abstract decodeJwtToken<T = Record<string, unknown>>(token: string): Promise<T>;
|
|
57
59
|
}
|
|
58
60
|
export default AsgardeoJavaScriptClient;
|
|
@@ -16,7 +16,6 @@
|
|
|
16
16
|
* under the License.
|
|
17
17
|
*/
|
|
18
18
|
import { Crypto, JWKInterface } from './models/crypto';
|
|
19
|
-
import { IdToken } from './models/token';
|
|
20
19
|
export declare class IsomorphicCrypto<T = any> {
|
|
21
20
|
private _cryptoUtils;
|
|
22
21
|
constructor(cryptoUtils: Crypto<T>);
|
|
@@ -60,14 +59,5 @@ export declare class IsomorphicCrypto<T = any> {
|
|
|
60
59
|
* @throws
|
|
61
60
|
*/
|
|
62
61
|
isValidIdToken(idToken: string, jwk: JWKInterface, clientId: string, issuer: string, username: string, clockTolerance: number | undefined, validateJwtIssuer: boolean | undefined): Promise<boolean>;
|
|
63
|
-
|
|
64
|
-
* This function decodes the payload of an id token and returns it.
|
|
65
|
-
*
|
|
66
|
-
* @param idToken - The id token to be decoded.
|
|
67
|
-
*
|
|
68
|
-
* @returns - The decoded payload of the id token.
|
|
69
|
-
*
|
|
70
|
-
* @throws
|
|
71
|
-
*/
|
|
72
|
-
decodeIdToken(idToken: string): IdToken;
|
|
62
|
+
decodeJwtToken<T = Record<string, unknown>>(token: string): T;
|
|
73
63
|
}
|
|
@@ -189,6 +189,18 @@ export declare class AsgardeoAuthClient<T> {
|
|
|
189
189
|
* @preserve
|
|
190
190
|
*/
|
|
191
191
|
getOpenIDProviderEndpoints(): Promise<Partial<OIDCEndpoints>>;
|
|
192
|
+
/**
|
|
193
|
+
* This method decodes a given JWT token and returns the payload.
|
|
194
|
+
*
|
|
195
|
+
* @param token - The token to be decoded.
|
|
196
|
+
* @returns - A Promise that resolves with the decoded token payload.
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```
|
|
200
|
+
* const decodedToken = await auth.decodeJwtToken(token);
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
203
|
+
decodeJwtToken<T = Record<string, unknown>>(token: string): Promise<T>;
|
|
192
204
|
/**
|
|
193
205
|
* This method decodes the payload of the ID token and returns it.
|
|
194
206
|
*
|
package/dist/cjs/index.js
CHANGED
|
@@ -595,22 +595,13 @@ var IsomorphicCrypto = class {
|
|
|
595
595
|
return Promise.reject(error2);
|
|
596
596
|
});
|
|
597
597
|
}
|
|
598
|
-
|
|
599
|
-
* This function decodes the payload of an id token and returns it.
|
|
600
|
-
*
|
|
601
|
-
* @param idToken - The id token to be decoded.
|
|
602
|
-
*
|
|
603
|
-
* @returns - The decoded payload of the id token.
|
|
604
|
-
*
|
|
605
|
-
* @throws
|
|
606
|
-
*/
|
|
607
|
-
decodeIdToken(idToken) {
|
|
598
|
+
decodeJwtToken(token) {
|
|
608
599
|
try {
|
|
609
|
-
const utf8String = this._cryptoUtils.base64URLDecode(
|
|
600
|
+
const utf8String = this._cryptoUtils.base64URLDecode(token?.split(".")[1]);
|
|
610
601
|
const payload = JSON.parse(utf8String);
|
|
611
602
|
return payload;
|
|
612
603
|
} catch (error2) {
|
|
613
|
-
throw new AsgardeoAuthException("JS-CRYPTO_UTIL-DIT-
|
|
604
|
+
throw new AsgardeoAuthException("JS-CRYPTO_UTIL-DIT-IV02", "Decoding token failed.", error2);
|
|
614
605
|
}
|
|
615
606
|
}
|
|
616
607
|
};
|
|
@@ -920,13 +911,13 @@ var AuthenticationHelper = class {
|
|
|
920
911
|
jwk,
|
|
921
912
|
(await this._config()).clientId,
|
|
922
913
|
issuer ?? "",
|
|
923
|
-
this._cryptoHelper.
|
|
914
|
+
this._cryptoHelper.decodeJwtToken(idToken).sub,
|
|
924
915
|
(await this._config()).tokenValidation?.idToken?.clockTolerance,
|
|
925
916
|
(await this._config()).tokenValidation?.idToken?.validateIssuer ?? true
|
|
926
917
|
);
|
|
927
918
|
}
|
|
928
919
|
getAuthenticatedUserInfo(idToken) {
|
|
929
|
-
const payload = this._cryptoHelper.
|
|
920
|
+
const payload = this._cryptoHelper.decodeJwtToken(idToken);
|
|
930
921
|
const username = payload?.["username"] ?? "";
|
|
931
922
|
const givenName = payload?.["given_name"] ?? "";
|
|
932
923
|
const familyName = payload?.["family_name"] ?? "";
|
|
@@ -1492,6 +1483,20 @@ var _AsgardeoAuthClient = class _AsgardeoAuthClient {
|
|
|
1492
1483
|
userinfoEndpoint: oidcProviderMetaData.userinfo_endpoint ?? ""
|
|
1493
1484
|
};
|
|
1494
1485
|
}
|
|
1486
|
+
/**
|
|
1487
|
+
* This method decodes a given JWT token and returns the payload.
|
|
1488
|
+
*
|
|
1489
|
+
* @param token - The token to be decoded.
|
|
1490
|
+
* @returns - A Promise that resolves with the decoded token payload.
|
|
1491
|
+
*
|
|
1492
|
+
* @example
|
|
1493
|
+
* ```
|
|
1494
|
+
* const decodedToken = await auth.decodeJwtToken(token);
|
|
1495
|
+
* ```
|
|
1496
|
+
*/
|
|
1497
|
+
async decodeJwtToken(token) {
|
|
1498
|
+
return this._cryptoHelper.decodeJwtToken(token);
|
|
1499
|
+
}
|
|
1495
1500
|
/**
|
|
1496
1501
|
* This method decodes the payload of the ID token and returns it.
|
|
1497
1502
|
*
|
|
@@ -1511,7 +1516,7 @@ var _AsgardeoAuthClient = class _AsgardeoAuthClient {
|
|
|
1511
1516
|
*/
|
|
1512
1517
|
async getDecodedIdToken(userId, idToken) {
|
|
1513
1518
|
const _idToken = (await this._storageManager.getSessionData(userId)).id_token;
|
|
1514
|
-
const payload = this._cryptoHelper.
|
|
1519
|
+
const payload = this._cryptoHelper.decodeJwtToken(_idToken ?? idToken);
|
|
1515
1520
|
return payload;
|
|
1516
1521
|
}
|
|
1517
1522
|
/**
|