@authly/sdk 1.1.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/globals/clients/AuthlyClient.d.ts +91 -58
- package/dist/globals/clients/AuthlyClient.js +255 -17
- package/dist/globals/configuration/AuthlyConfiguration.d.ts +40 -0
- package/dist/globals/configuration/AuthlyConfiguration.js +43 -0
- package/dist/globals/{clients → internal}/HttpClient.d.ts +7 -7
- package/dist/globals/{clients → internal}/HttpClient.js +7 -7
- package/dist/globals/internal/JWTVerifier.d.ts +37 -0
- package/dist/globals/internal/JWTVerifier.js +71 -0
- package/dist/globals/internal/PKCEUtils.d.ts +23 -0
- package/dist/globals/internal/PKCEUtils.js +59 -0
- package/dist/index.d.ts +25 -2
- package/dist/index.js +25 -2
- package/dist/models/builders/process-errors/base/AuthlyError.d.ts +11 -0
- package/dist/models/builders/process-errors/base/AuthlyError.js +18 -0
- package/dist/models/builders/process-errors/base/AuthlyTokenError.d.ts +12 -0
- package/dist/models/builders/process-errors/base/AuthlyTokenError.js +19 -0
- package/dist/models/builders/process-errors/tokens/AuthlyTokenExpiredError.d.ts +13 -0
- package/dist/models/builders/process-errors/tokens/AuthlyTokenExpiredError.js +20 -0
- package/dist/models/builders/process-errors/tokens/AuthlyTokenInvalidError.d.ts +16 -0
- package/dist/models/builders/process-errors/tokens/AuthlyTokenInvalidError.js +23 -0
- package/dist/models/globals/clients/interfaces/IAuthlyClientOptions.d.ts +62 -0
- package/dist/models/globals/clients/interfaces/IAuthlyStorage.d.ts +22 -0
- package/dist/models/globals/clients/interfaces/IAuthlyStorage.js +2 -0
- package/dist/models/globals/clients/interfaces/IAuthorizeUrlOptions.d.ts +36 -0
- package/dist/models/globals/clients/interfaces/IAuthorizeUrlOptions.js +2 -0
- package/dist/models/globals/clients/interfaces/IDecodedTokenClaim.d.ts +68 -0
- package/dist/models/globals/clients/interfaces/IDecodedTokenClaim.js +2 -0
- package/dist/models/globals/clients/interfaces/ITokenResponse.d.ts +29 -0
- package/dist/models/globals/clients/interfaces/ITokenResponse.js +2 -0
- package/dist/models/globals/clients/interfaces/IUserProfile.d.ts +42 -0
- package/dist/models/globals/clients/interfaces/IUserProfile.js +2 -0
- package/dist/models/globals/clients/internal/interfaces/IJWTVerifierOptions.d.ts +33 -0
- package/dist/models/globals/clients/internal/interfaces/IJWTVerifierOptions.js +2 -0
- package/dist/react/AuthlyCallback.d.ts +20 -0
- package/dist/react/AuthlyCallback.js +45 -0
- package/dist/react/AuthlyContext.d.ts +16 -0
- package/dist/react/AuthlyContext.js +14 -0
- package/dist/react/AuthlyProvider.d.ts +8 -0
- package/dist/react/AuthlyProvider.js +54 -0
- package/dist/react/index.d.ts +3 -0
- package/dist/react/index.js +19 -0
- package/package.json +27 -4
- package/dist/config.d.ts +0 -3
- package/dist/config.js +0 -6
- package/dist/exceptions/index.d.ts +0 -27
- package/dist/exceptions/index.js +0 -46
- package/dist/globals/clients/internal/JWTVerifier.d.ts +0 -26
- package/dist/globals/clients/internal/JWTVerifier.js +0 -55
- package/dist/models/Claims.d.ts +0 -48
- /package/dist/models/{Claims.js → globals/clients/interfaces/IAuthlyClientOptions.js} +0 -0
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.HttpClient = void 0;
|
|
4
4
|
/**
|
|
5
|
-
* A class that provides a static method for making HTTP requests.
|
|
5
|
+
* @summary A class that provides a static method for making HTTP requests.
|
|
6
6
|
*/
|
|
7
7
|
class HttpClient {
|
|
8
8
|
constructor() { }
|
|
9
9
|
/**
|
|
10
|
-
* Makes an HTTP request to the specified URL.
|
|
10
|
+
* @summary Makes an HTTP request to the specified URL.
|
|
11
11
|
* @param url - The URL to make the request to.
|
|
12
12
|
* @param options - The options for the request.
|
|
13
13
|
* @returns A promise that resolves to the response data.
|
|
@@ -35,7 +35,7 @@ class HttpClient {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
38
|
-
* Makes a GET request to the specified URL.
|
|
38
|
+
* @summary Makes a GET request to the specified URL.
|
|
39
39
|
* @param url - The URL to make the request to.
|
|
40
40
|
* @param options - The options for the request.
|
|
41
41
|
* @returns A promise that resolves to the response data.
|
|
@@ -47,7 +47,7 @@ class HttpClient {
|
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
/**
|
|
50
|
-
* Makes a POST request to the specified URL.
|
|
50
|
+
* @summary Makes a POST request to the specified URL.
|
|
51
51
|
* @param url - The URL to make the request to.
|
|
52
52
|
* @param options - The options for the request.
|
|
53
53
|
* @returns A promise that resolves to the response data.
|
|
@@ -59,7 +59,7 @@ class HttpClient {
|
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
62
|
-
* Makes a PUT request to the specified URL.
|
|
62
|
+
* @summary Makes a PUT request to the specified URL.
|
|
63
63
|
* @param url - The URL to make the request to.
|
|
64
64
|
* @param options - The options for the request.
|
|
65
65
|
* @returns A promise that resolves to the response data.
|
|
@@ -71,7 +71,7 @@ class HttpClient {
|
|
|
71
71
|
});
|
|
72
72
|
}
|
|
73
73
|
/**
|
|
74
|
-
* Makes a PATCH request to the specified URL.
|
|
74
|
+
* @summary Makes a PATCH request to the specified URL.
|
|
75
75
|
* @param url - The URL to make the request to.
|
|
76
76
|
* @param options - The options for the request.
|
|
77
77
|
* @returns A promise that resolves to the response data.
|
|
@@ -83,7 +83,7 @@ class HttpClient {
|
|
|
83
83
|
});
|
|
84
84
|
}
|
|
85
85
|
/**
|
|
86
|
-
* Makes a DELETE request to the specified URL.
|
|
86
|
+
* @summary Makes a DELETE request to the specified URL.
|
|
87
87
|
* @param url - The URL to make the request to.
|
|
88
88
|
* @param options - The options for the request.
|
|
89
89
|
* @returns A promise that resolves to the response data.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { IDecodedTokenClaim } from "../../models/globals/clients/interfaces/IDecodedTokenClaim";
|
|
2
|
+
import type { IJWTVerifierOptions } from "../../models/globals/clients/internal/interfaces/IJWTVerifierOptions";
|
|
3
|
+
/**
|
|
4
|
+
* @summary Internal class for verifying JWT tokens using jose.
|
|
5
|
+
*/
|
|
6
|
+
declare class JWTVerifier {
|
|
7
|
+
/**
|
|
8
|
+
* @summary The issuer of the token.
|
|
9
|
+
*/
|
|
10
|
+
private readonly issuer;
|
|
11
|
+
/**
|
|
12
|
+
* @summary The audience of the token.
|
|
13
|
+
*/
|
|
14
|
+
private readonly audience;
|
|
15
|
+
/**
|
|
16
|
+
* @summary The algorithms to use for the token.
|
|
17
|
+
*/
|
|
18
|
+
private readonly algorithms;
|
|
19
|
+
/**
|
|
20
|
+
* @summary The JWKS to use for the token.
|
|
21
|
+
*/
|
|
22
|
+
private readonly JWKS;
|
|
23
|
+
/**
|
|
24
|
+
* @summary Constructs a new JWTVerifier.
|
|
25
|
+
* @param params - The options for the JWTVerifier.
|
|
26
|
+
*/
|
|
27
|
+
constructor(params: IJWTVerifierOptions);
|
|
28
|
+
/**
|
|
29
|
+
* @summary Verify the JWT token and return its claims.
|
|
30
|
+
* @param token - The encoded JWT token string.
|
|
31
|
+
* @returns The decoded claims from the token.
|
|
32
|
+
* @throws {AuthlyTokenExpiredError} If the token's exp claim is in the past.
|
|
33
|
+
* @throws {AuthlyTokenInvalidError} If the token is otherwise invalid.
|
|
34
|
+
*/
|
|
35
|
+
verify(token: string): Promise<IDecodedTokenClaim>;
|
|
36
|
+
}
|
|
37
|
+
export { JWTVerifier };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JWTVerifier = void 0;
|
|
4
|
+
const jose_1 = require("jose");
|
|
5
|
+
const AuthlyTokenExpiredError_1 = require("../../models/builders/process-errors/tokens/AuthlyTokenExpiredError");
|
|
6
|
+
const AuthlyTokenInvalidError_1 = require("../../models/builders/process-errors/tokens/AuthlyTokenInvalidError");
|
|
7
|
+
const AuthlyConfiguration_1 = require("../configuration/AuthlyConfiguration");
|
|
8
|
+
/**
|
|
9
|
+
* @summary Internal class for verifying JWT tokens using jose.
|
|
10
|
+
*/
|
|
11
|
+
class JWTVerifier {
|
|
12
|
+
/**
|
|
13
|
+
* @summary The issuer of the token.
|
|
14
|
+
*/
|
|
15
|
+
issuer;
|
|
16
|
+
/**
|
|
17
|
+
* @summary The audience of the token.
|
|
18
|
+
*/
|
|
19
|
+
audience;
|
|
20
|
+
/**
|
|
21
|
+
* @summary The algorithms to use for the token.
|
|
22
|
+
*/
|
|
23
|
+
algorithms;
|
|
24
|
+
/**
|
|
25
|
+
* @summary The JWKS to use for the token.
|
|
26
|
+
*/
|
|
27
|
+
JWKS;
|
|
28
|
+
/**
|
|
29
|
+
* @summary Constructs a new JWTVerifier.
|
|
30
|
+
* @param params - The options for the JWTVerifier.
|
|
31
|
+
*/
|
|
32
|
+
constructor(params) {
|
|
33
|
+
this.issuer = params.issuer;
|
|
34
|
+
this.audience = params.audience;
|
|
35
|
+
this.algorithms = params.algorithms || AuthlyConfiguration_1.AuthlyConfiguration.DEFAULT_ALGORITHMS;
|
|
36
|
+
this.JWKS = params.jwks || (0, jose_1.createRemoteJWKSet)(new URL(params.jwksUrl));
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* @summary Verify the JWT token and return its claims.
|
|
40
|
+
* @param token - The encoded JWT token string.
|
|
41
|
+
* @returns The decoded claims from the token.
|
|
42
|
+
* @throws {AuthlyTokenExpiredError} If the token's exp claim is in the past.
|
|
43
|
+
* @throws {AuthlyTokenInvalidError} If the token is otherwise invalid.
|
|
44
|
+
*/
|
|
45
|
+
async verify(token) {
|
|
46
|
+
try {
|
|
47
|
+
const { payload } = await (0, jose_1.jwtVerify)(token, this.JWKS, {
|
|
48
|
+
issuer: this.issuer,
|
|
49
|
+
audience: this.audience,
|
|
50
|
+
algorithms: this.algorithms,
|
|
51
|
+
});
|
|
52
|
+
return payload;
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
if (error instanceof Error) {
|
|
56
|
+
const code = error.code;
|
|
57
|
+
if (code === "ERR_JWT_EXPIRED") {
|
|
58
|
+
throw new AuthlyTokenExpiredError_1.AuthlyTokenExpiredError("Token has expired");
|
|
59
|
+
}
|
|
60
|
+
if (code === "ERR_JWT_CLAIM_VALIDATION_FAILED" ||
|
|
61
|
+
code === "ERR_JWS_SIGNATURE_VERIFICATION_FAILED" ||
|
|
62
|
+
code === "ERR_JWS_INVALID" ||
|
|
63
|
+
code === "ERR_JWT_INVALID") {
|
|
64
|
+
throw new AuthlyTokenInvalidError_1.AuthlyTokenInvalidError(error.message ?? "Token validation failed");
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
throw new AuthlyTokenInvalidError_1.AuthlyTokenInvalidError("Invalid token");
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.JWTVerifier = JWTVerifier;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @summary Utilities for PKCE (Proof Key for Code Exchange).
|
|
3
|
+
*/
|
|
4
|
+
export declare class PKCEUtils {
|
|
5
|
+
/**
|
|
6
|
+
* @summary Generate a random string for state or code verifier.
|
|
7
|
+
* @param length - The length of the string.
|
|
8
|
+
* @returns The generated string.
|
|
9
|
+
*/
|
|
10
|
+
static generateRandomString(length?: number): string;
|
|
11
|
+
/**
|
|
12
|
+
* @summary Generate the code challenge from the code verifier.
|
|
13
|
+
* @param codeVerifier - The code verifier.
|
|
14
|
+
* @returns A promise that resolves to the code challenge.
|
|
15
|
+
*/
|
|
16
|
+
static generateCodeChallenge(codeVerifier: string): Promise<string>;
|
|
17
|
+
/**
|
|
18
|
+
* @summary Base64 URL encode a buffer.
|
|
19
|
+
* @param buffer - The buffer to encode.
|
|
20
|
+
* @returns The base64 URL encoded string.
|
|
21
|
+
*/
|
|
22
|
+
private static base64URLEncode;
|
|
23
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PKCEUtils = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @summary Utilities for PKCE (Proof Key for Code Exchange).
|
|
6
|
+
*/
|
|
7
|
+
class PKCEUtils {
|
|
8
|
+
/**
|
|
9
|
+
* @summary Generate a random string for state or code verifier.
|
|
10
|
+
* @param length - The length of the string.
|
|
11
|
+
* @returns The generated string.
|
|
12
|
+
*/
|
|
13
|
+
static generateRandomString(length = 43) {
|
|
14
|
+
const charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~";
|
|
15
|
+
let result = "";
|
|
16
|
+
const randomValues = new Uint8Array(length);
|
|
17
|
+
if (typeof window !== "undefined" && window.crypto) {
|
|
18
|
+
window.crypto.getRandomValues(randomValues);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
for (let i = 0; i < length; i++) {
|
|
22
|
+
randomValues[i] = Math.floor(Math.random() * 256);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
for (let i = 0; i < length; i++) {
|
|
26
|
+
result += charset[randomValues[i] % charset.length];
|
|
27
|
+
}
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* @summary Generate the code challenge from the code verifier.
|
|
32
|
+
* @param codeVerifier - The code verifier.
|
|
33
|
+
* @returns A promise that resolves to the code challenge.
|
|
34
|
+
*/
|
|
35
|
+
static async generateCodeChallenge(codeVerifier) {
|
|
36
|
+
const encoder = new TextEncoder();
|
|
37
|
+
const data = encoder.encode(codeVerifier);
|
|
38
|
+
if (typeof window !== "undefined" && window.crypto && window.crypto.subtle) {
|
|
39
|
+
const hashBuffer = await window.crypto.subtle.digest("SHA-256", data);
|
|
40
|
+
return this.base64URLEncode(hashBuffer);
|
|
41
|
+
}
|
|
42
|
+
// TODO: Add a fallback for non-browser environments. (crypto module)
|
|
43
|
+
throw new Error("Crypto API is not available in this environment.");
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* @summary Base64 URL encode a buffer.
|
|
47
|
+
* @param buffer - The buffer to encode.
|
|
48
|
+
* @returns The base64 URL encoded string.
|
|
49
|
+
*/
|
|
50
|
+
static base64URLEncode(buffer) {
|
|
51
|
+
const bytes = new Uint8Array(buffer);
|
|
52
|
+
let binary = "";
|
|
53
|
+
for (let i = 0; i < bytes.byteLength; i++) {
|
|
54
|
+
binary += String.fromCharCode(bytes[i]);
|
|
55
|
+
}
|
|
56
|
+
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.PKCEUtils = PKCEUtils;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @authly/sdk
|
|
3
|
+
*
|
|
4
|
+
* A library for building authentication systems using Authly.
|
|
5
|
+
*
|
|
6
|
+
* @author Anvoria
|
|
7
|
+
* @license MIT
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Clients.
|
|
11
|
+
*/
|
|
3
12
|
export * from "./globals/clients/AuthlyClient";
|
|
13
|
+
export * from "./globals/configuration/AuthlyConfiguration";
|
|
14
|
+
/**
|
|
15
|
+
* Models.
|
|
16
|
+
*/
|
|
17
|
+
export * from "./models/builders/process-errors/base/AuthlyError";
|
|
18
|
+
export * from "./models/builders/process-errors/base/AuthlyTokenError";
|
|
19
|
+
export * from "./models/builders/process-errors/tokens/AuthlyTokenExpiredError";
|
|
20
|
+
export * from "./models/builders/process-errors/tokens/AuthlyTokenInvalidError";
|
|
21
|
+
export * from "./models/globals/clients/interfaces/IAuthlyClientOptions";
|
|
22
|
+
export * from "./models/globals/clients/interfaces/IAuthorizeUrlOptions";
|
|
23
|
+
export * from "./models/globals/clients/interfaces/IDecodedTokenClaim";
|
|
24
|
+
export * from "./models/globals/clients/interfaces/ITokenResponse";
|
|
25
|
+
export * from "./models/globals/clients/interfaces/IAuthlyStorage";
|
|
26
|
+
export * from "./models/globals/clients/interfaces/IUserProfile";
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @authly/sdk
|
|
4
|
+
*
|
|
5
|
+
* A library for building authentication systems using Authly.
|
|
6
|
+
*
|
|
7
|
+
* @author Anvoria
|
|
8
|
+
* @license MIT
|
|
9
|
+
*/
|
|
2
10
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
11
|
if (k2 === undefined) k2 = k;
|
|
4
12
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -14,6 +22,21 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
22
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
23
|
};
|
|
16
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
|
|
18
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Clients.
|
|
27
|
+
*/
|
|
19
28
|
__exportStar(require("./globals/clients/AuthlyClient"), exports);
|
|
29
|
+
__exportStar(require("./globals/configuration/AuthlyConfiguration"), exports);
|
|
30
|
+
/**
|
|
31
|
+
* Models.
|
|
32
|
+
*/
|
|
33
|
+
__exportStar(require("./models/builders/process-errors/base/AuthlyError"), exports);
|
|
34
|
+
__exportStar(require("./models/builders/process-errors/base/AuthlyTokenError"), exports);
|
|
35
|
+
__exportStar(require("./models/builders/process-errors/tokens/AuthlyTokenExpiredError"), exports);
|
|
36
|
+
__exportStar(require("./models/builders/process-errors/tokens/AuthlyTokenInvalidError"), exports);
|
|
37
|
+
__exportStar(require("./models/globals/clients/interfaces/IAuthlyClientOptions"), exports);
|
|
38
|
+
__exportStar(require("./models/globals/clients/interfaces/IAuthorizeUrlOptions"), exports);
|
|
39
|
+
__exportStar(require("./models/globals/clients/interfaces/IDecodedTokenClaim"), exports);
|
|
40
|
+
__exportStar(require("./models/globals/clients/interfaces/ITokenResponse"), exports);
|
|
41
|
+
__exportStar(require("./models/globals/clients/interfaces/IAuthlyStorage"), exports);
|
|
42
|
+
__exportStar(require("./models/globals/clients/interfaces/IUserProfile"), exports);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @summary Base exception for all Authly errors.
|
|
3
|
+
*/
|
|
4
|
+
declare abstract class AuthlyError extends Error {
|
|
5
|
+
/**
|
|
6
|
+
* @summary Constructs a new AuthlyError.
|
|
7
|
+
* @param message - The error message.
|
|
8
|
+
*/
|
|
9
|
+
constructor(message: string);
|
|
10
|
+
}
|
|
11
|
+
export { AuthlyError };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthlyError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @summary Base exception for all Authly errors.
|
|
6
|
+
*/
|
|
7
|
+
class AuthlyError extends Error {
|
|
8
|
+
/**
|
|
9
|
+
* @summary Constructs a new AuthlyError.
|
|
10
|
+
* @param message - The error message.
|
|
11
|
+
*/
|
|
12
|
+
constructor(message) {
|
|
13
|
+
super(message);
|
|
14
|
+
this.name = "AuthlyError";
|
|
15
|
+
Object.setPrototypeOf(this, AuthlyError.prototype);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.AuthlyError = AuthlyError;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AuthlyError } from "./AuthlyError";
|
|
2
|
+
/**
|
|
3
|
+
* @summary Base exception for all Authly token errors.
|
|
4
|
+
*/
|
|
5
|
+
declare abstract class AuthlyTokenError extends AuthlyError {
|
|
6
|
+
/**
|
|
7
|
+
* @summary Constructs a new AuthlyTokenError.
|
|
8
|
+
* @param message - The error message.
|
|
9
|
+
*/
|
|
10
|
+
constructor(message: string);
|
|
11
|
+
}
|
|
12
|
+
export { AuthlyTokenError };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthlyTokenError = void 0;
|
|
4
|
+
const AuthlyError_1 = require("./AuthlyError");
|
|
5
|
+
/**
|
|
6
|
+
* @summary Base exception for all Authly token errors.
|
|
7
|
+
*/
|
|
8
|
+
class AuthlyTokenError extends AuthlyError_1.AuthlyError {
|
|
9
|
+
/**
|
|
10
|
+
* @summary Constructs a new AuthlyTokenError.
|
|
11
|
+
* @param message - The error message.
|
|
12
|
+
*/
|
|
13
|
+
constructor(message) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.name = "AuthlyTokenError";
|
|
16
|
+
Object.setPrototypeOf(this, AuthlyTokenError.prototype);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.AuthlyTokenError = AuthlyTokenError;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AuthlyTokenError } from "../base/AuthlyTokenError";
|
|
2
|
+
/**
|
|
3
|
+
* @summary Exception raised when a token is expired.
|
|
4
|
+
* @throws This error is thrown when the token's expiration time is in the past.
|
|
5
|
+
*/
|
|
6
|
+
declare class AuthlyTokenExpiredError extends AuthlyTokenError {
|
|
7
|
+
/**
|
|
8
|
+
* @summary Constructs a new AuthlyTokenExpiredError.
|
|
9
|
+
* @param message - The error message.
|
|
10
|
+
*/
|
|
11
|
+
constructor(message: string);
|
|
12
|
+
}
|
|
13
|
+
export { AuthlyTokenExpiredError };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthlyTokenExpiredError = void 0;
|
|
4
|
+
const AuthlyTokenError_1 = require("../base/AuthlyTokenError");
|
|
5
|
+
/**
|
|
6
|
+
* @summary Exception raised when a token is expired.
|
|
7
|
+
* @throws This error is thrown when the token's expiration time is in the past.
|
|
8
|
+
*/
|
|
9
|
+
class AuthlyTokenExpiredError extends AuthlyTokenError_1.AuthlyTokenError {
|
|
10
|
+
/**
|
|
11
|
+
* @summary Constructs a new AuthlyTokenExpiredError.
|
|
12
|
+
* @param message - The error message.
|
|
13
|
+
*/
|
|
14
|
+
constructor(message) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.name = "AuthlyTokenExpiredError";
|
|
17
|
+
Object.setPrototypeOf(this, AuthlyTokenExpiredError.prototype);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.AuthlyTokenExpiredError = AuthlyTokenExpiredError;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AuthlyTokenError } from "../base/AuthlyTokenError";
|
|
2
|
+
/**
|
|
3
|
+
* @summary Exception raised when a token is invalid.
|
|
4
|
+
* @throws This error is thrown when:
|
|
5
|
+
* - The token has an invalid signature.
|
|
6
|
+
* - The token has an invalid format.
|
|
7
|
+
* - The token has an invalid issuer or audience.
|
|
8
|
+
*/
|
|
9
|
+
declare class AuthlyTokenInvalidError extends AuthlyTokenError {
|
|
10
|
+
/**
|
|
11
|
+
* @summary Constructs a new AuthlyTokenInvalidError.
|
|
12
|
+
* @param message - The error message.
|
|
13
|
+
*/
|
|
14
|
+
constructor(message: string);
|
|
15
|
+
}
|
|
16
|
+
export { AuthlyTokenInvalidError };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthlyTokenInvalidError = void 0;
|
|
4
|
+
const AuthlyTokenError_1 = require("../base/AuthlyTokenError");
|
|
5
|
+
/**
|
|
6
|
+
* @summary Exception raised when a token is invalid.
|
|
7
|
+
* @throws This error is thrown when:
|
|
8
|
+
* - The token has an invalid signature.
|
|
9
|
+
* - The token has an invalid format.
|
|
10
|
+
* - The token has an invalid issuer or audience.
|
|
11
|
+
*/
|
|
12
|
+
class AuthlyTokenInvalidError extends AuthlyTokenError_1.AuthlyTokenError {
|
|
13
|
+
/**
|
|
14
|
+
* @summary Constructs a new AuthlyTokenInvalidError.
|
|
15
|
+
* @param message - The error message.
|
|
16
|
+
*/
|
|
17
|
+
constructor(message) {
|
|
18
|
+
super(message);
|
|
19
|
+
this.name = "AuthlyTokenInvalidError";
|
|
20
|
+
Object.setPrototypeOf(this, AuthlyTokenInvalidError.prototype);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.AuthlyTokenInvalidError = AuthlyTokenInvalidError;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { IAuthlyStorage } from "./IAuthlyStorage";
|
|
2
|
+
/**
|
|
3
|
+
* @summary Options for initializing the AuthlyClient.
|
|
4
|
+
*/
|
|
5
|
+
interface IAuthlyClientOptions {
|
|
6
|
+
/**
|
|
7
|
+
* @summary The base URL of the identity provider.
|
|
8
|
+
* @example "https://auth.example.com"
|
|
9
|
+
*/
|
|
10
|
+
readonly issuer: string;
|
|
11
|
+
/**
|
|
12
|
+
* @summary The expected audience claim (aud) in the token.
|
|
13
|
+
* @example "https://app.example.com"
|
|
14
|
+
*/
|
|
15
|
+
readonly audience: string;
|
|
16
|
+
/**
|
|
17
|
+
* @summary The ID of the service in Authly.
|
|
18
|
+
* @example "1234567890"
|
|
19
|
+
*/
|
|
20
|
+
readonly serviceId: string;
|
|
21
|
+
/**
|
|
22
|
+
* @summary The redirect URI to use for the authorization flow.
|
|
23
|
+
* @example "https://app.example.com/api/auth/callback"
|
|
24
|
+
*/
|
|
25
|
+
readonly redirectUri?: string;
|
|
26
|
+
/**
|
|
27
|
+
* @summary The storage implementation to use for PKCE state and verifier.
|
|
28
|
+
* @default localStorage (in browser)
|
|
29
|
+
*/
|
|
30
|
+
readonly storage?: IAuthlyStorage;
|
|
31
|
+
/**
|
|
32
|
+
* @summary The path to the JWKS endpoint relative to the issuer.
|
|
33
|
+
* @example "/.well-known/jwks.json"
|
|
34
|
+
* @default "/.well-known/jwks.json"
|
|
35
|
+
*/
|
|
36
|
+
readonly jwksPath?: string;
|
|
37
|
+
/**
|
|
38
|
+
* @summary The path to the authorize endpoint relative to the issuer.
|
|
39
|
+
* @example "/v1/oauth/authorize"
|
|
40
|
+
* @default "/authorize"
|
|
41
|
+
*/
|
|
42
|
+
readonly authorizePath?: string;
|
|
43
|
+
/**
|
|
44
|
+
* @summary The path to the token endpoint relative to the issuer.
|
|
45
|
+
* @example "/v1/oauth/token"
|
|
46
|
+
* @default "/oauth/token"
|
|
47
|
+
*/
|
|
48
|
+
readonly tokenPath?: string;
|
|
49
|
+
/**
|
|
50
|
+
* @summary The path to the user info endpoint relative to the issuer.
|
|
51
|
+
* @example "/v1/oauth/userinfo"
|
|
52
|
+
* @default "/v1/oauth/userinfo"
|
|
53
|
+
*/
|
|
54
|
+
readonly userInfoPath?: string;
|
|
55
|
+
/**
|
|
56
|
+
* @summary A list of allowed signing algorithms.
|
|
57
|
+
* @example ["RS256"]
|
|
58
|
+
* @default ["RS256"]
|
|
59
|
+
*/
|
|
60
|
+
readonly algorithms?: string[];
|
|
61
|
+
}
|
|
62
|
+
export type { IAuthlyClientOptions };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @summary Interface for storage used by AuthlyClient.
|
|
3
|
+
*/
|
|
4
|
+
export interface IAuthlyStorage {
|
|
5
|
+
/**
|
|
6
|
+
* @summary Retrieve an item from storage.
|
|
7
|
+
* @param _key - The key of the item to retrieve.
|
|
8
|
+
* @returns The value of the item, or null if not found.
|
|
9
|
+
*/
|
|
10
|
+
getItem(_key: string): string | null | Promise<string | null>;
|
|
11
|
+
/**
|
|
12
|
+
* @summary Add key and value to storage.
|
|
13
|
+
* @param _key - The key of the item to add.
|
|
14
|
+
* @param _value - The value of the item to add.
|
|
15
|
+
*/
|
|
16
|
+
setItem(_key: string, _value: string): void | Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* @summary Remove an item from storage.
|
|
19
|
+
* @param _key - The key of the item to remove.
|
|
20
|
+
*/
|
|
21
|
+
removeItem(_key: string): void | Promise<void>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @summary Options for generating an authorization URL.
|
|
3
|
+
*/
|
|
4
|
+
interface IAuthorizeUrlOptions {
|
|
5
|
+
/**
|
|
6
|
+
* @summary The URI to redirect back to after authentication.
|
|
7
|
+
* @example "https://app.example.com/callback"
|
|
8
|
+
*/
|
|
9
|
+
readonly redirectUri: string;
|
|
10
|
+
/**
|
|
11
|
+
* @summary A unique state string to prevent CSRF.
|
|
12
|
+
* @example "1234567890"
|
|
13
|
+
*/
|
|
14
|
+
readonly state: string;
|
|
15
|
+
/**
|
|
16
|
+
* @summary The PKCE code challenge.
|
|
17
|
+
* @example "1234567890"
|
|
18
|
+
*/
|
|
19
|
+
readonly codeChallenge: string;
|
|
20
|
+
/**
|
|
21
|
+
* @summary The PKCE code challenge method.
|
|
22
|
+
* @example "S256"
|
|
23
|
+
*/
|
|
24
|
+
readonly codeChallengeMethod?: "S256" | "plain";
|
|
25
|
+
/**
|
|
26
|
+
* @summary The requested scopes.
|
|
27
|
+
* @example "openid profile email"
|
|
28
|
+
*/
|
|
29
|
+
readonly scope?: string;
|
|
30
|
+
/**
|
|
31
|
+
* @summary The OAuth2 response type.
|
|
32
|
+
* @example "code"
|
|
33
|
+
*/
|
|
34
|
+
readonly responseType?: string;
|
|
35
|
+
}
|
|
36
|
+
export type { IAuthorizeUrlOptions };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @summary Interface for decoded token claims.
|
|
3
|
+
*/
|
|
4
|
+
interface IDecodedTokenClaim {
|
|
5
|
+
/**
|
|
6
|
+
* @summary Subject identifier - the unique ID of the user.
|
|
7
|
+
* @example "1234567890"
|
|
8
|
+
*/
|
|
9
|
+
readonly sub: string;
|
|
10
|
+
/**
|
|
11
|
+
* @summary Issuer identifier - the URL of the identity provider.
|
|
12
|
+
* @example "https://auth.example.com"
|
|
13
|
+
*/
|
|
14
|
+
readonly iss: string;
|
|
15
|
+
/**
|
|
16
|
+
* @summary Audience(s) for which the token is intended.
|
|
17
|
+
* @example "https://app.example.com"
|
|
18
|
+
* @example ["https://app.example.com", "https://app.example.com/api"]
|
|
19
|
+
*/
|
|
20
|
+
readonly aud: string | string[];
|
|
21
|
+
/**
|
|
22
|
+
* @summary Expiration time (Unix timestamp).
|
|
23
|
+
* @example 1715145600
|
|
24
|
+
*/
|
|
25
|
+
readonly exp: number;
|
|
26
|
+
/**
|
|
27
|
+
* @summary Issued at time (Unix timestamp).
|
|
28
|
+
* @example 1715145600
|
|
29
|
+
*/
|
|
30
|
+
readonly iat: number;
|
|
31
|
+
/**
|
|
32
|
+
* @summary Session ID identifier.
|
|
33
|
+
* @example "1234567890"
|
|
34
|
+
*/
|
|
35
|
+
readonly sid: string;
|
|
36
|
+
/**
|
|
37
|
+
* @summary Dictionary of permissions granted to the user, where keys are resource names and values are permission levels.
|
|
38
|
+
* @example
|
|
39
|
+
* ```json
|
|
40
|
+
* {
|
|
41
|
+
* "read": 1,
|
|
42
|
+
* "write": 0
|
|
43
|
+
* }
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
readonly permissions: Record<string, number>;
|
|
47
|
+
/**
|
|
48
|
+
* @summary Permission version.
|
|
49
|
+
* @example 1
|
|
50
|
+
*/
|
|
51
|
+
readonly pver?: number;
|
|
52
|
+
/**
|
|
53
|
+
* @summary Space-separated list of scopes.
|
|
54
|
+
* @example "openid profile email"
|
|
55
|
+
*/
|
|
56
|
+
readonly scope?: string;
|
|
57
|
+
/**
|
|
58
|
+
* @summary Allow additional claims.
|
|
59
|
+
* @example
|
|
60
|
+
* ```json
|
|
61
|
+
* {
|
|
62
|
+
* "custom": "custom-value"
|
|
63
|
+
* }
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
readonly [key: string]: unknown;
|
|
67
|
+
}
|
|
68
|
+
export type { IDecodedTokenClaim };
|