@authly/sdk 1.0.1 → 1.0.2

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.
@@ -0,0 +1,2 @@
1
+ export declare const DEFAULT_JWKS_PATH = "/.well-known/jwks.json";
2
+ export declare const DEFAULT_ALGORITHMS: string[];
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Base exception for all Authly errors.
3
+ */
4
+ export declare class AuthlyError extends Error {
5
+ constructor(message: string);
6
+ }
7
+ /**
8
+ * Base exception for all token errors.
9
+ */
10
+ export declare class TokenError extends AuthlyError {
11
+ constructor(message: string);
12
+ }
13
+ /**
14
+ * Exception raised when a token is invalid:
15
+ * - bad signature
16
+ * - bad format
17
+ * - bad iss / aud
18
+ */
19
+ export declare class TokenInvalidError extends TokenError {
20
+ constructor(message: string);
21
+ }
22
+ /**
23
+ * Exception raised when a token is expired.
24
+ */
25
+ export declare class TokenExpiredError extends TokenError {
26
+ constructor(message: string);
27
+ }
@@ -0,0 +1,50 @@
1
+ import type { Claims } from "../../models/Claims";
2
+ /**
3
+ * Options for initializing the AuthlyClient.
4
+ */
5
+ export interface AuthlyClientOptions {
6
+ /**
7
+ * The base URL of the identity provider (e.g., "https://auth.example.com").
8
+ */
9
+ issuer: string;
10
+ /**
11
+ * The expected audience claim (aud) in the token.
12
+ */
13
+ audience: string;
14
+ /**
15
+ * The ID of the service in Authly.
16
+ */
17
+ serviceId: string;
18
+ /**
19
+ * The path to the JWKS endpoint relative to the issuer. Defaults to "/.well-known/jwks.json".
20
+ */
21
+ jwksPath?: string;
22
+ /**
23
+ * A list of allowed signing algorithms. If omitted, defaults to ["RS256"].
24
+ */
25
+ algorithms?: string[];
26
+ }
27
+ /**
28
+ * A client for verifying Authly JWT tokens.
29
+ *
30
+ * This client handles the validation of tokens against a specific issuer and audience,
31
+ * fetching the public keys (JWKS) automatically.
32
+ */
33
+ export declare class AuthlyClient {
34
+ private readonly verifier;
35
+ private readonly serviceId;
36
+ private readonly issuer;
37
+ constructor(options: AuthlyClientOptions);
38
+ /**
39
+ * Verify a JWT token and return its decoded claims.
40
+ *
41
+ * This method verifies the token's signature using the provider's JWKS,
42
+ * and validates standard claims like expiration, issuer, and audience.
43
+ *
44
+ * @param token - The encoded JWT token string.
45
+ * @returns A promise that resolves to the token claims (e.g., sub, iss, aud).
46
+ * @throws {TokenExpiredError} If the token has expired.
47
+ * @throws {TokenInvalidError} If the token is invalid (e.g., bad signature, invalid audience).
48
+ */
49
+ verify(token: string): Promise<Claims>;
50
+ }
@@ -0,0 +1,50 @@
1
+ import type { IRequestResponseClient } from "../../models/globals/clients/interfaces/IRequestResponseClient";
2
+ /**
3
+ * A class that provides a static method for making HTTP requests.
4
+ */
5
+ declare class HttpClient {
6
+ private constructor();
7
+ /**
8
+ * Makes an HTTP request to the specified URL.
9
+ * @param url - The URL to make the request to.
10
+ * @param options - The options for the request.
11
+ * @returns A promise that resolves to the response data.
12
+ */
13
+ private static request;
14
+ /**
15
+ * Makes a GET request to the specified URL.
16
+ * @param url - The URL to make the request to.
17
+ * @param options - The options for the request.
18
+ * @returns A promise that resolves to the response data.
19
+ */
20
+ static get<D>(url: string, options?: Omit<RequestInit, "method">): Promise<IRequestResponseClient<D>>;
21
+ /**
22
+ * Makes a POST request to the specified URL.
23
+ * @param url - The URL to make the request to.
24
+ * @param options - The options for the request.
25
+ * @returns A promise that resolves to the response data.
26
+ */
27
+ static post<D>(url: string, options?: Omit<RequestInit, "method">): Promise<IRequestResponseClient<D>>;
28
+ /**
29
+ * Makes a PUT request to the specified URL.
30
+ * @param url - The URL to make the request to.
31
+ * @param options - The options for the request.
32
+ * @returns A promise that resolves to the response data.
33
+ */
34
+ static put<D>(url: string, options?: Omit<RequestInit, "method">): Promise<IRequestResponseClient<D>>;
35
+ /**
36
+ * Makes a PATCH request to the specified URL.
37
+ * @param url - The URL to make the request to.
38
+ * @param options - The options for the request.
39
+ * @returns A promise that resolves to the response data.
40
+ */
41
+ static patch<D>(url: string, options?: Omit<RequestInit, "method">): Promise<IRequestResponseClient<D>>;
42
+ /**
43
+ * Makes a DELETE request to the specified URL.
44
+ * @param url - The URL to make the request to.
45
+ * @param options - The options for the request.
46
+ * @returns A promise that resolves to the response data.
47
+ */
48
+ static delete<D>(url: string, options?: Omit<RequestInit, "method">): Promise<IRequestResponseClient<D>>;
49
+ }
50
+ export { HttpClient };
@@ -0,0 +1,26 @@
1
+ import type { JWTVerifyGetKey } from "jose";
2
+ import type { Claims } from "../../../models/Claims";
3
+ /**
4
+ * Internal class for verifying JWT tokens using jose.
5
+ */
6
+ export declare class JWTVerifier {
7
+ private readonly issuer;
8
+ private readonly audience;
9
+ private readonly algorithms;
10
+ private readonly JWKS;
11
+ constructor(params: {
12
+ issuer: string;
13
+ audience: string;
14
+ jwksUrl: string;
15
+ algorithms?: string[];
16
+ jwks?: JWTVerifyGetKey;
17
+ });
18
+ /**
19
+ * Verify the JWT token and return its claims.
20
+ * @param token - The encoded JWT token string.
21
+ * @returns The decoded claims from the token.
22
+ * @throws {TokenExpiredError} If the token's exp claim is in the past.
23
+ * @throws {TokenInvalidError} If the token is otherwise invalid.
24
+ */
25
+ verify(token: string): Promise<Claims>;
26
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./models/Claims";
2
+ export * from "./exceptions";
3
+ export * from "./globals/clients/AuthlyClient";
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Decoded JWT claims found in an Authly token.
3
+ *
4
+ * This interface contains both standard OIDC claims and Authly-specific claims
5
+ * like session ID (sid) and permissions.
6
+ */
7
+ export interface Claims {
8
+ /**
9
+ * Subject identifier - the unique ID of the user.
10
+ */
11
+ sub: string;
12
+ /**
13
+ * Issuer identifier - the URL of the identity provider.
14
+ */
15
+ iss: string;
16
+ /**
17
+ * Audience(s) for which the token is intended.
18
+ */
19
+ aud: string | string[];
20
+ /**
21
+ * Expiration time (Unix timestamp).
22
+ */
23
+ exp: number;
24
+ /**
25
+ * Issued at time (Unix timestamp).
26
+ */
27
+ iat: number;
28
+ /**
29
+ * Session ID identifier.
30
+ */
31
+ sid: string;
32
+ /**
33
+ * Dictionary of permissions granted to the user, where keys are resource names and values are permission levels.
34
+ */
35
+ permissions: Record<string, number>;
36
+ /**
37
+ * Permission version.
38
+ */
39
+ pver?: number;
40
+ /**
41
+ * Space-separated list of scopes.
42
+ */
43
+ scope?: string;
44
+ /**
45
+ * Allow additional claims.
46
+ */
47
+ [key: string]: unknown;
48
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Represents the error structure from the backend.
3
+ */
4
+ interface APIError {
5
+ /**
6
+ * The error code.
7
+ */
8
+ readonly code: string;
9
+ /**
10
+ * The error message.
11
+ */
12
+ readonly message: string;
13
+ /**
14
+ * Optional error details.
15
+ */
16
+ readonly details?: unknown;
17
+ }
18
+ /**
19
+ * Represents the response from a request.
20
+ * @template D - The type of the data returned from the request.
21
+ */
22
+ type IRequestResponseClient<D> = {
23
+ /**
24
+ * Whether the request was successful.
25
+ */
26
+ readonly success: true;
27
+ /**
28
+ * The data returned from the request.
29
+ */
30
+ readonly data: D;
31
+ /**
32
+ * The message returned from the request.
33
+ */
34
+ readonly message: string;
35
+ } | {
36
+ /**
37
+ * Whether the request was successful.
38
+ */
39
+ readonly success: false;
40
+ /**
41
+ * The error returned from the request.
42
+ */
43
+ readonly error: APIError;
44
+ };
45
+ export type { IRequestResponseClient, APIError };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@authly/sdk",
3
3
  "description": "A library for building authentication systems using Authly.",
4
- "version": "1.0.1",
4
+ "version": "1.0.2",
5
5
  "author": {
6
6
  "name": "Anvoria",
7
7
  "url": "https://github.com/Anvoria"