@strivacity/sdk-core 3.0.2 → 4.0.0-beta.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/CHANGELOG.md +11 -0
- package/README.md +1873 -340
- package/dist/assets/oidc.cjs +2 -0
- package/dist/assets/oidc.cjs.map +1 -0
- package/dist/assets/oidc.mjs +2 -0
- package/dist/assets/oidc.mjs.map +1 -0
- package/dist/assets/server.cjs +2 -0
- package/dist/assets/server.cjs.map +1 -0
- package/dist/assets/server.mjs +2 -0
- package/dist/assets/server.mjs.map +1 -0
- package/dist/flows/base.cjs +2 -0
- package/dist/flows/base.cjs.map +1 -0
- package/dist/flows/base.d.ts +26 -0
- package/dist/flows/base.mjs +2 -0
- package/dist/flows/base.mjs.map +1 -0
- package/dist/flows/embedded.cjs +2 -0
- package/dist/flows/embedded.cjs.map +1 -0
- package/dist/flows/embedded.d.ts +9 -0
- package/dist/flows/embedded.mjs +2 -0
- package/dist/flows/embedded.mjs.map +1 -0
- package/dist/flows/index.cjs +1 -0
- package/dist/flows/index.d.ts +5 -0
- package/dist/flows/index.mjs +1 -0
- package/dist/flows/native.cjs +2 -0
- package/dist/flows/native.cjs.map +1 -0
- package/dist/flows/native.d.ts +9 -0
- package/dist/flows/native.mjs +2 -0
- package/dist/flows/native.mjs.map +1 -0
- package/dist/flows/popup.cjs +2 -0
- package/dist/flows/popup.cjs.map +1 -0
- package/dist/flows/popup.d.ts +9 -0
- package/dist/flows/popup.mjs +2 -0
- package/dist/flows/popup.mjs.map +1 -0
- package/dist/flows/redirect.cjs +2 -0
- package/dist/flows/redirect.cjs.map +1 -0
- package/dist/flows/redirect.d.ts +9 -0
- package/dist/flows/redirect.mjs +2 -0
- package/dist/flows/redirect.mjs.map +1 -0
- package/dist/handlers/embedded.cjs +2 -0
- package/dist/handlers/embedded.cjs.map +1 -0
- package/dist/handlers/embedded.d.ts +37 -0
- package/dist/handlers/embedded.mjs +2 -0
- package/dist/handlers/embedded.mjs.map +1 -0
- package/dist/handlers/index.cjs +1 -0
- package/dist/handlers/index.d.ts +2 -0
- package/dist/handlers/index.mjs +1 -0
- package/dist/handlers/native.cjs +2 -0
- package/dist/handlers/native.cjs.map +1 -0
- package/dist/handlers/native.d.ts +56 -0
- package/dist/handlers/native.mjs +2 -0
- package/dist/handlers/native.mjs.map +1 -0
- package/dist/handlers/popup.cjs +2 -0
- package/dist/handlers/popup.cjs.map +1 -0
- package/dist/handlers/popup.d.ts +21 -0
- package/dist/handlers/popup.mjs +2 -0
- package/dist/handlers/popup.mjs.map +1 -0
- package/dist/handlers/redirect.cjs +2 -0
- package/dist/handlers/redirect.cjs.map +1 -0
- package/dist/handlers/redirect.d.ts +18 -0
- package/dist/handlers/redirect.mjs +2 -0
- package/dist/handlers/redirect.mjs.map +1 -0
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +16 -21
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/dist/server/base.cjs +2 -0
- package/dist/server/base.cjs.map +1 -0
- package/dist/server/base.d.ts +15 -0
- package/dist/server/base.mjs +2 -0
- package/dist/server/base.mjs.map +1 -0
- package/dist/server/index.cjs +1 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.mjs +1 -0
- package/dist/storages/cache.cjs +2 -0
- package/dist/storages/cache.cjs.map +1 -0
- package/dist/storages/cache.d.ts +11 -0
- package/dist/storages/cache.mjs +2 -0
- package/dist/storages/cache.mjs.map +1 -0
- package/dist/storages/index.cjs +1 -0
- package/dist/storages/index.d.ts +7 -0
- package/dist/storages/index.mjs +1 -0
- package/dist/storages/indexeddb.cjs +2 -0
- package/dist/storages/indexeddb.cjs.map +1 -0
- package/dist/storages/indexeddb.d.ts +10 -0
- package/dist/storages/indexeddb.mjs +2 -0
- package/dist/storages/indexeddb.mjs.map +1 -0
- package/dist/storages/local.cjs +2 -0
- package/dist/storages/local.cjs.map +1 -0
- package/dist/storages/local.d.ts +7 -0
- package/dist/storages/local.mjs +2 -0
- package/dist/storages/local.mjs.map +1 -0
- package/dist/storages/memory.cjs +2 -0
- package/dist/storages/memory.cjs.map +1 -0
- package/dist/storages/memory.d.ts +8 -0
- package/dist/storages/memory.mjs +2 -0
- package/dist/storages/memory.mjs.map +1 -0
- package/dist/storages/server.cjs +1 -0
- package/dist/storages/server.d.ts +39 -0
- package/dist/storages/server.mjs +1 -0
- package/dist/storages/session.cjs +2 -0
- package/dist/storages/session.cjs.map +1 -0
- package/dist/storages/session.d.ts +7 -0
- package/dist/storages/session.mjs +2 -0
- package/dist/storages/session.mjs.map +1 -0
- package/dist/storages/worker.cjs +2 -0
- package/dist/storages/worker.cjs.map +1 -0
- package/dist/storages/worker.d.ts +46 -0
- package/dist/storages/worker.mjs +2 -0
- package/dist/storages/worker.mjs.map +1 -0
- package/dist/types/common.cjs +0 -0
- package/dist/types/common.d.ts +145 -0
- package/dist/types/common.mjs +0 -0
- package/dist/types/embedded.cjs +0 -0
- package/dist/types/embedded.d.ts +103 -0
- package/dist/types/embedded.mjs +0 -0
- package/dist/types/index.cjs +1 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.mjs +1 -0
- package/dist/types/native.cjs +0 -0
- package/dist/types/native.d.ts +385 -0
- package/dist/types/native.mjs +0 -0
- package/dist/types/oidc.cjs +2 -0
- package/dist/types/oidc.cjs.map +1 -0
- package/dist/types/oidc.d.ts +768 -0
- package/dist/types/oidc.mjs +2 -0
- package/dist/types/oidc.mjs.map +1 -0
- package/dist/types/popup.cjs +0 -0
- package/dist/types/popup.d.ts +69 -0
- package/dist/types/popup.mjs +0 -0
- package/dist/types/redirect.cjs +0 -0
- package/dist/types/redirect.d.ts +21 -0
- package/dist/types/redirect.mjs +0 -0
- package/dist/types/server.cjs +0 -0
- package/dist/types/server.d.ts +200 -0
- package/dist/types/server.mjs +0 -0
- package/dist/utils/base64url.cjs +2 -0
- package/dist/utils/base64url.cjs.map +1 -0
- package/dist/utils/base64url.d.ts +14 -0
- package/dist/utils/base64url.mjs +2 -0
- package/dist/utils/base64url.mjs.map +1 -0
- package/dist/utils/common.cjs +2 -0
- package/dist/utils/common.cjs.map +1 -0
- package/dist/utils/common.d.ts +23 -0
- package/dist/utils/common.mjs +2 -0
- package/dist/utils/common.mjs.map +1 -0
- package/dist/utils/credentials.cjs +2 -2
- package/dist/utils/credentials.cjs.map +1 -1
- package/dist/utils/credentials.d.ts +19 -3
- package/dist/utils/credentials.mjs +2 -2
- package/dist/utils/credentials.mjs.map +1 -1
- package/dist/utils/crypto.cjs +2 -2
- package/dist/utils/crypto.cjs.map +1 -1
- package/dist/utils/crypto.d.ts +16 -26
- package/dist/utils/crypto.mjs +2 -2
- package/dist/utils/crypto.mjs.map +1 -1
- package/dist/utils/dom.cjs +2 -0
- package/dist/utils/dom.cjs.map +1 -0
- package/dist/utils/dom.d.ts +7 -0
- package/dist/utils/dom.mjs +2 -0
- package/dist/utils/dom.mjs.map +1 -0
- package/dist/utils/errors.cjs +2 -2
- package/dist/utils/errors.cjs.map +1 -1
- package/dist/utils/errors.d.ts +62 -1
- package/dist/utils/errors.mjs +2 -2
- package/dist/utils/errors.mjs.map +1 -1
- package/dist/utils/httpClient.cjs +2 -0
- package/dist/utils/httpClient.cjs.map +1 -0
- package/dist/utils/httpClient.d.ts +2 -0
- package/dist/utils/httpClient.mjs +2 -0
- package/dist/utils/httpClient.mjs.map +1 -0
- package/dist/utils/index.cjs +1 -0
- package/dist/utils/index.d.ts +12 -0
- package/dist/utils/index.mjs +1 -0
- package/dist/utils/logging.cjs +2 -0
- package/dist/utils/logging.cjs.map +1 -0
- package/dist/utils/logging.d.ts +2 -0
- package/dist/utils/logging.mjs +2 -0
- package/dist/utils/logging.mjs.map +1 -0
- package/dist/utils/oidc.cjs +1 -0
- package/dist/utils/oidc.d.ts +264 -0
- package/dist/utils/oidc.mjs +1 -0
- package/dist/utils/server.cjs +1 -0
- package/dist/utils/server.d.ts +72 -0
- package/dist/utils/server.mjs +1 -0
- package/dist/utils/session.cjs +2 -0
- package/dist/utils/session.cjs.map +1 -0
- package/dist/utils/session.d.ts +29 -0
- package/dist/utils/session.mjs +2 -0
- package/dist/utils/session.mjs.map +1 -0
- package/dist/utils/state.cjs +1 -0
- package/dist/utils/state.d.ts +23 -0
- package/dist/utils/state.mjs +1 -0
- package/package.json +53 -1
- package/testing/tests/flows/base.spec.ts +1030 -0
- package/testing/tests/flows/embedded.spec.ts +443 -0
- package/testing/tests/flows/index.spec.ts +8 -0
- package/testing/tests/flows/native.spec.ts +487 -0
- package/testing/tests/flows/popup.spec.ts +400 -0
- package/testing/tests/flows/redirect.spec.ts +369 -0
- package/testing/tests/handlers/embedded.spec.ts +199 -0
- package/testing/tests/handlers/index.spec.ts +8 -0
- package/testing/tests/handlers/native.spec.ts +283 -0
- package/testing/tests/handlers/popup.spec.ts +206 -0
- package/testing/tests/handlers/redirect.spec.ts +70 -0
- package/testing/tests/index.spec.ts +78 -0
- package/testing/tests/server/base.spec.ts +846 -0
- package/testing/tests/server/index.spec.ts +15 -0
- package/testing/tests/storages/cache.spec.ts +107 -0
- package/testing/tests/storages/index.spec.ts +22 -0
- package/testing/tests/storages/indexeddb.spec.ts +113 -0
- package/testing/tests/storages/local.spec.ts +46 -0
- package/testing/tests/storages/memory.spec.ts +51 -0
- package/testing/tests/storages/server.spec.ts +435 -0
- package/testing/tests/storages/session.spec.ts +46 -0
- package/testing/tests/storages/worker.spec.ts +106 -0
- package/testing/tests/utils/common.spec.ts +77 -0
- package/testing/tests/utils/credentials.spec.ts +195 -0
- package/testing/tests/utils/dom.spec.ts +37 -0
- package/testing/tests/utils/index.spec.ts +71 -0
- package/testing/tests/utils/logging.spec.ts +82 -0
- package/testing/tests/utils/oidc.spec.ts +744 -0
- package/testing/tests/utils/server.spec.ts +235 -0
- package/dist/flows/BaseFlow.cjs +0 -2
- package/dist/flows/BaseFlow.cjs.map +0 -1
- package/dist/flows/BaseFlow.d.ts +0 -191
- package/dist/flows/BaseFlow.mjs +0 -2
- package/dist/flows/BaseFlow.mjs.map +0 -1
- package/dist/flows/EmbeddedFlow.cjs +0 -2
- package/dist/flows/EmbeddedFlow.cjs.map +0 -1
- package/dist/flows/EmbeddedFlow.d.ts +0 -26
- package/dist/flows/EmbeddedFlow.mjs +0 -2
- package/dist/flows/EmbeddedFlow.mjs.map +0 -1
- package/dist/flows/NativeFlow.cjs +0 -2
- package/dist/flows/NativeFlow.cjs.map +0 -1
- package/dist/flows/NativeFlow.d.ts +0 -34
- package/dist/flows/NativeFlow.mjs +0 -2
- package/dist/flows/NativeFlow.mjs.map +0 -1
- package/dist/flows/PopupFlow.cjs +0 -2
- package/dist/flows/PopupFlow.cjs.map +0 -1
- package/dist/flows/PopupFlow.d.ts +0 -36
- package/dist/flows/PopupFlow.mjs +0 -2
- package/dist/flows/PopupFlow.mjs.map +0 -1
- package/dist/flows/RedirectFlow.cjs +0 -2
- package/dist/flows/RedirectFlow.cjs.map +0 -1
- package/dist/flows/RedirectFlow.d.ts +0 -38
- package/dist/flows/RedirectFlow.mjs +0 -2
- package/dist/flows/RedirectFlow.mjs.map +0 -1
- package/dist/handlers/BaseFlowHandler.cjs +0 -2
- package/dist/handlers/BaseFlowHandler.cjs.map +0 -1
- package/dist/handlers/BaseFlowHandler.d.ts +0 -61
- package/dist/handlers/BaseFlowHandler.mjs +0 -2
- package/dist/handlers/BaseFlowHandler.mjs.map +0 -1
- package/dist/handlers/EmbeddedFlowHandler.cjs +0 -2
- package/dist/handlers/EmbeddedFlowHandler.cjs.map +0 -1
- package/dist/handlers/EmbeddedFlowHandler.d.ts +0 -28
- package/dist/handlers/EmbeddedFlowHandler.mjs +0 -2
- package/dist/handlers/EmbeddedFlowHandler.mjs.map +0 -1
- package/dist/handlers/NativeFlowHandler.cjs +0 -2
- package/dist/handlers/NativeFlowHandler.cjs.map +0 -1
- package/dist/handlers/NativeFlowHandler.d.ts +0 -31
- package/dist/handlers/NativeFlowHandler.mjs +0 -2
- package/dist/handlers/NativeFlowHandler.mjs.map +0 -1
- package/dist/storages/LocalStorage.cjs +0 -2
- package/dist/storages/LocalStorage.cjs.map +0 -1
- package/dist/storages/LocalStorage.d.ts +0 -23
- package/dist/storages/LocalStorage.mjs +0 -2
- package/dist/storages/LocalStorage.mjs.map +0 -1
- package/dist/storages/SessionStorage.cjs +0 -2
- package/dist/storages/SessionStorage.cjs.map +0 -1
- package/dist/storages/SessionStorage.d.ts +0 -23
- package/dist/storages/SessionStorage.mjs +0 -2
- package/dist/storages/SessionStorage.mjs.map +0 -1
- package/dist/types.cjs +0 -2
- package/dist/types.cjs.map +0 -1
- package/dist/types.d.ts +0 -1263
- package/dist/types.mjs +0 -2
- package/dist/types.mjs.map +0 -1
- package/dist/utils/HttpClient.cjs +0 -2
- package/dist/utils/HttpClient.cjs.map +0 -1
- package/dist/utils/HttpClient.d.ts +0 -4
- package/dist/utils/HttpClient.mjs +0 -2
- package/dist/utils/HttpClient.mjs.map +0 -1
- package/dist/utils/Logging.cjs +0 -2
- package/dist/utils/Logging.cjs.map +0 -1
- package/dist/utils/Logging.d.ts +0 -8
- package/dist/utils/Logging.mjs +0 -2
- package/dist/utils/Logging.mjs.map +0 -1
- package/dist/utils/Metadata.cjs +0 -2
- package/dist/utils/Metadata.cjs.map +0 -1
- package/dist/utils/Metadata.d.ts +0 -98
- package/dist/utils/Metadata.mjs +0 -2
- package/dist/utils/Metadata.mjs.map +0 -1
- package/dist/utils/Session.cjs +0 -2
- package/dist/utils/Session.cjs.map +0 -1
- package/dist/utils/Session.d.ts +0 -82
- package/dist/utils/Session.mjs +0 -2
- package/dist/utils/Session.mjs.map +0 -1
- package/dist/utils/State.cjs +0 -2
- package/dist/utils/State.cjs.map +0 -1
- package/dist/utils/State.d.ts +0 -43
- package/dist/utils/State.mjs +0 -2
- package/dist/utils/State.mjs.map +0 -1
- package/dist/utils/base64Url.cjs +0 -2
- package/dist/utils/base64Url.cjs.map +0 -1
- package/dist/utils/base64Url.d.ts +0 -27
- package/dist/utils/base64Url.mjs +0 -2
- package/dist/utils/base64Url.mjs.map +0 -1
- package/dist/utils/date.cjs +0 -2
- package/dist/utils/date.cjs.map +0 -1
- package/dist/utils/date.d.ts +0 -6
- package/dist/utils/date.mjs +0 -2
- package/dist/utils/date.mjs.map +0 -1
- package/dist/utils/handlers.cjs +0 -2
- package/dist/utils/handlers.cjs.map +0 -1
- package/dist/utils/handlers.d.ts +0 -35
- package/dist/utils/handlers.mjs +0 -2
- package/dist/utils/handlers.mjs.map +0 -1
- package/dist/utils/jwt.cjs +0 -2
- package/dist/utils/jwt.cjs.map +0 -1
- package/dist/utils/jwt.d.ts +0 -34
- package/dist/utils/jwt.mjs +0 -2
- package/dist/utils/jwt.mjs.map +0 -1
- package/dist/utils/object.cjs +0 -2
- package/dist/utils/object.cjs.map +0 -1
- package/dist/utils/object.d.ts +0 -1
- package/dist/utils/object.mjs +0 -2
- package/dist/utils/object.mjs.map +0 -1
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import { ExtraRequestArgs, IdTokenClaims, DiscoveryDocument, SDKOptions, SessionData, EntryResponse, FlowState } from '../types/oidc';
|
|
2
|
+
import { NativeFlowState } from '../types/native';
|
|
3
|
+
/**
|
|
4
|
+
* Returns the default flow state for the SDK.
|
|
5
|
+
*
|
|
6
|
+
* @returns {FlowState} The default flow state object.
|
|
7
|
+
*/
|
|
8
|
+
export declare function getDefaultFlowState(): FlowState;
|
|
9
|
+
/**
|
|
10
|
+
* Returns the default SDK options for the SDK.
|
|
11
|
+
*/
|
|
12
|
+
export declare const defaultOptions: Partial<SDKOptions>;
|
|
13
|
+
/**
|
|
14
|
+
* Fetches the OpenID configuration discovery document from the authorization server.
|
|
15
|
+
* Caches the document for a specified duration to avoid unnecessary network requests.
|
|
16
|
+
*
|
|
17
|
+
* @param {SDKOptions} options - The SDK options containing the issuer URL and other configurations.
|
|
18
|
+
* @returns {Promise<DiscoveryDocument>} A promise that resolves to the fetched discovery document.
|
|
19
|
+
* @throws {ServerError} If the discovery document fetch fails with a server error (HTTP 429 or 5xx).
|
|
20
|
+
* @throws {ProtocolError} If the discovery document is missing required fields or has an issuer mismatch.
|
|
21
|
+
*/
|
|
22
|
+
export declare function getDiscoveryDocument(options: SDKOptions): Promise<DiscoveryDocument>;
|
|
23
|
+
/**
|
|
24
|
+
* Returns with the SDK options merged with the provided options.
|
|
25
|
+
*
|
|
26
|
+
* @param {SDKInitConfig} options - The SDK initialization configuration.
|
|
27
|
+
* @template InitOptions - The type of the SDK initialization configuration.
|
|
28
|
+
* @template Options - The type of the SDK options.
|
|
29
|
+
* @returns {Options} The merged SDK options.
|
|
30
|
+
*/
|
|
31
|
+
export declare function getSDKOptions<Options extends SDKOptions = SDKOptions>(options: any): Options;
|
|
32
|
+
/**
|
|
33
|
+
* Generates a code verifier for PKCE (Proof Key for Code Exchange).
|
|
34
|
+
*
|
|
35
|
+
* @returns {string} A randomly generated code verifier string.
|
|
36
|
+
*/
|
|
37
|
+
export declare function generateCodeVerifier(): string;
|
|
38
|
+
/**
|
|
39
|
+
* Generates a code challenge from a code verifier using SHA-256 hashing.
|
|
40
|
+
*
|
|
41
|
+
* @param {string} codeVerifier The code verifier string.
|
|
42
|
+
* @returns {Promise<string>} A promise that resolves to the generated code challenge.
|
|
43
|
+
*/
|
|
44
|
+
export declare function generateCodeChallenge(codeVerifier: string): Promise<string>;
|
|
45
|
+
/**
|
|
46
|
+
* Generates a random hexadecimal string of the specified byte length.
|
|
47
|
+
*
|
|
48
|
+
* @param {number} [byteLength=16] - The number of random bytes to generate (default is 16).
|
|
49
|
+
* @returns {string} A randomly generated hexadecimal string.
|
|
50
|
+
*/
|
|
51
|
+
export declare function generateRandomHex(byteLength?: number): string;
|
|
52
|
+
/**
|
|
53
|
+
* Decodes a JWT token and returns the payload as an object.
|
|
54
|
+
*
|
|
55
|
+
* @template T The expected structure of the JWT payload.
|
|
56
|
+
* @param {string} token - The JWT token to decode.
|
|
57
|
+
* @returns {T} The decoded payload of the JWT token.
|
|
58
|
+
* @throws {ProtocolError} If the token is invalid or has the wrong format.
|
|
59
|
+
*/
|
|
60
|
+
export declare function decodeJwt<T = Record<string, unknown>>(token: string): T;
|
|
61
|
+
/**
|
|
62
|
+
* Verifies a JWT token's signature against a JWKS endpoint.
|
|
63
|
+
* Only RS256 is supported.
|
|
64
|
+
*
|
|
65
|
+
* @param {Object} options - The options for verifying the JWT.
|
|
66
|
+
* @param {string} options.token - The JWT token to verify.
|
|
67
|
+
* @param {string} options.jwksUri - The URL of the JWKS endpoint.
|
|
68
|
+
* @param {SDKOptions} options.options - The SDK options containing client ID, storage, and other options.
|
|
69
|
+
* @template T - The expected structure of the JWT payload.
|
|
70
|
+
* @returns {Promise<T>} The verified payload.
|
|
71
|
+
* @throws {ProtocolError} If the token is invalid, the key is not found, or verification fails.
|
|
72
|
+
*/
|
|
73
|
+
export declare function verifyJwt<T = Record<string, unknown>>({ token, jwksUri, options }: {
|
|
74
|
+
token: string;
|
|
75
|
+
jwksUri: string;
|
|
76
|
+
options: SDKOptions;
|
|
77
|
+
}): Promise<T>;
|
|
78
|
+
/**
|
|
79
|
+
* Generates a signed JWT token using the provided header, payload, and private key.
|
|
80
|
+
*
|
|
81
|
+
* @param {object} header - The JWT header.
|
|
82
|
+
* @param {object} payload - The JWT payload.
|
|
83
|
+
* @param {CryptoKey} [privateKey] - The private key to sign the JWT. If not provided, an unsigned token will be generated.
|
|
84
|
+
* @returns {Promise<string>} A promise that resolves to the signed JWT token.
|
|
85
|
+
*/
|
|
86
|
+
export declare function generateJwt(header: object, payload: object, privateKey?: CryptoKey): Promise<string>;
|
|
87
|
+
/**
|
|
88
|
+
* Verifies and validates an ID token's claims.
|
|
89
|
+
*
|
|
90
|
+
* @param {Object} options - The options for verifying the ID token
|
|
91
|
+
* @param {string} options.idToken - The ID token to verify
|
|
92
|
+
* @param {SDKOptions} options.options - The SDK options containing client ID, storage, and other options
|
|
93
|
+
* @param {string} [options.expectedSub] - Optional expected subject (`sub`) claim to validate against the ID token
|
|
94
|
+
* @param {string} [options.expectedNonce] - Optional expected nonce claim to validate against the ID token
|
|
95
|
+
* @returns {Promise<IdTokenClaims>} The verified, validated claims.
|
|
96
|
+
* @throws {ProtocolError} If the signature, `iss`, `aud`, `exp`, or `sub` fail validation.
|
|
97
|
+
*/
|
|
98
|
+
export declare function verifyIdToken({ idToken, options, verifySignature, expectedSub, expectedNonce, }: {
|
|
99
|
+
idToken: string;
|
|
100
|
+
options: SDKOptions;
|
|
101
|
+
verifySignature?: boolean;
|
|
102
|
+
expectedSub?: string;
|
|
103
|
+
expectedNonce?: string;
|
|
104
|
+
}): Promise<IdTokenClaims>;
|
|
105
|
+
/**
|
|
106
|
+
* Builds the authorization URL with the provided parameters and configuration.
|
|
107
|
+
*
|
|
108
|
+
* @param {Object} options - The options for building the login URL and starting the session
|
|
109
|
+
* @param {ExtraRequestArgs} options.params - The parameters for the authorization request, including optional prompts and hints
|
|
110
|
+
* @param {SDKOptions} options.options - The SDK options containing client ID, redirect URI, storage, and other options
|
|
111
|
+
* @returns {Promise<URL>} A promise that resolves to the constructed authorization URL
|
|
112
|
+
* @throws {Error} If fetching OIDC metadata fails or writing the PKCE state to storage fails.
|
|
113
|
+
*/
|
|
114
|
+
export declare function buildAuthorizationUrl<URLHandlerParams extends ExtraRequestArgs = ExtraRequestArgs>({ url, includeOAuthParams, persistState, params, options, }: {
|
|
115
|
+
url?: string | null | URL;
|
|
116
|
+
includeOAuthParams?: boolean;
|
|
117
|
+
persistState?: boolean;
|
|
118
|
+
params: URLHandlerParams;
|
|
119
|
+
options: SDKOptions;
|
|
120
|
+
}): Promise<URL>;
|
|
121
|
+
/**
|
|
122
|
+
* Builds the end session (logout) URL with optional parameters for ID token hint and post-logout redirect URI.
|
|
123
|
+
*
|
|
124
|
+
* @param {Object} options - The options for building the end session URL
|
|
125
|
+
* @param {string | URL} options.url - The base URL for the end session endpoint
|
|
126
|
+
* @param {string} options.idToken - The ID token to include as a hint for the end session request
|
|
127
|
+
* @param {string} [options.postLogoutRedirectUri] - Optional URI to redirect to after logout
|
|
128
|
+
* @returns {URL} A promise that resolves to the constructed end session URL
|
|
129
|
+
* @throws {Error} If fetching metadata fails or the end session endpoint is not available
|
|
130
|
+
*/
|
|
131
|
+
export declare function buildEndSessionUrl({ url, idToken, postLogoutRedirectUri }: {
|
|
132
|
+
url: string | URL;
|
|
133
|
+
idToken: string;
|
|
134
|
+
postLogoutRedirectUri?: string;
|
|
135
|
+
}): URL;
|
|
136
|
+
/**
|
|
137
|
+
* Exchanges an authorization code for tokens by sending a request to the token endpoint.
|
|
138
|
+
* Validates the PKCE state and ID token claims, and returns the session data.
|
|
139
|
+
*
|
|
140
|
+
* @param {Object} options - The options for exchanging the authorization code
|
|
141
|
+
* @param {string | URL} [options.url] - The token endpoint URL (optional, will be fetched from metadata if not provided)
|
|
142
|
+
* @param {Record<string, string>} options.params - The parameters received from the authorization server, including the authorization code and state
|
|
143
|
+
* @param {SDKOptions} options.options - The SDK options containing client ID, redirect URI, storage, and other options
|
|
144
|
+
* @returns {Promise<SessionData>} A promise that resolves to the session data containing tokens and claims
|
|
145
|
+
* @throws {OidcError} If the token endpoint returns an OIDC error response
|
|
146
|
+
* @throws {ServerError} If the token endpoint request fails with a server error (HTTP 429 or 5xx)
|
|
147
|
+
* @throws {NetworkError} If the token endpoint request fails due to network issues
|
|
148
|
+
* @throws {ProtocolError} If the authorization code or state is invalid, or if the token endpoint returns an error
|
|
149
|
+
* @throws {ProtocolError} If the authorization code or state is invalid, or if the token endpoint returns an error
|
|
150
|
+
*/
|
|
151
|
+
export declare function exchangeCode({ url, params, options, }: {
|
|
152
|
+
url?: string | URL;
|
|
153
|
+
params: Record<string, string>;
|
|
154
|
+
options: SDKOptions;
|
|
155
|
+
}): Promise<SessionData>;
|
|
156
|
+
/**
|
|
157
|
+
* Refreshes the access token using the stored refresh token and persists the updated session.
|
|
158
|
+
*
|
|
159
|
+
* @param {Object} options - The options for refreshing the access token
|
|
160
|
+
* @param {string} options.url - The token endpoint URL
|
|
161
|
+
* @param {string} options.refreshToken - The refresh token to use for refreshing the access token
|
|
162
|
+
* @param {SDKOptions} options.options - The SDK options containing client ID, storage, and other options
|
|
163
|
+
* @param {string} [options.grantType='refresh_token'] - The grant type to use for the token refresh request (default is 'refresh_token')
|
|
164
|
+
* @param {string} [options.clientId] - Optional client ID to override the default client ID in the SDK options
|
|
165
|
+
* @param {string} [options.audience] - Optional audience to include in the token refresh request
|
|
166
|
+
* @param {string} [options.scope] - Optional scope to include in the token refresh request
|
|
167
|
+
* @returns {Promise<SessionData>} A promise that resolves to the updated session data with refreshed tokens
|
|
168
|
+
* @throws {ServerError} If the token refresh request fails with a server error (HTTP 429 or 5xx)
|
|
169
|
+
* @throws {NetworkError} If the token refresh request fails due to network issues
|
|
170
|
+
* @throws {OidcError} If the token refresh request returns an OIDC error response
|
|
171
|
+
* @throws {ProtocolError} If the token refresh request returns an error or the ID token claims are invalid
|
|
172
|
+
*/
|
|
173
|
+
export declare function refreshToken({ url, refreshToken, options, grantType, clientId, audience, scope, expectedSub, }: {
|
|
174
|
+
url?: string | URL;
|
|
175
|
+
refreshToken: string;
|
|
176
|
+
options: SDKOptions;
|
|
177
|
+
grantType?: string;
|
|
178
|
+
clientId?: string;
|
|
179
|
+
audience?: string;
|
|
180
|
+
scope?: string;
|
|
181
|
+
expectedSub?: string;
|
|
182
|
+
}): Promise<SessionData>;
|
|
183
|
+
/**
|
|
184
|
+
* Revokes the best available token (refresh token preferred, then access token) and removes the session from storage.
|
|
185
|
+
*
|
|
186
|
+
* @param {Object} options - The options for revoking the token
|
|
187
|
+
* @param {string | URL} options.url - The revocation endpoint URL
|
|
188
|
+
* @param {string} options.tokenTypeHint - The type of token to revoke ('refresh_token' or 'access_token')
|
|
189
|
+
* @param {string} options.token - The token to revoke
|
|
190
|
+
* @param {SDKOptions} options.options - The SDK options containing client ID, storage, and other options
|
|
191
|
+
* @param {string} [options.clientId] - Optional client ID to override the default client ID in the SDK options
|
|
192
|
+
* @returns {Promise<void>} A promise that resolves when the token is revoked and the session is cleared from storage
|
|
193
|
+
* @throws {ServerError} If the token revocation request fails with a server error (HTTP 429 or 5xx)
|
|
194
|
+
* @throws {ProtocolError} If the token revocation request returns an error or the ID token claims are invalid
|
|
195
|
+
*/
|
|
196
|
+
export declare function revokeToken({ url, tokenTypeHint, token, options, clientId, }: {
|
|
197
|
+
url?: string | URL;
|
|
198
|
+
tokenTypeHint: string;
|
|
199
|
+
token: string;
|
|
200
|
+
options: SDKOptions;
|
|
201
|
+
clientId?: string;
|
|
202
|
+
}): Promise<void>;
|
|
203
|
+
/**
|
|
204
|
+
* Fetches the entry flow from the specified URL with the provided parameters and SDK options.
|
|
205
|
+
*
|
|
206
|
+
* @param {Object} options
|
|
207
|
+
* @param {string | URL} options.url - The URL to request the entry flow from
|
|
208
|
+
* @param {URLSearchParams} options.params - The parameters to include in the entry request
|
|
209
|
+
* @param {SDKOptions} options.options - The SDK options containing client ID, redirect URI, storage, and other options
|
|
210
|
+
* @param {string} [options.clientId] - Optional client ID to override the default client ID in the SDK options
|
|
211
|
+
* @param {string} [options.redirectUri] - Optional redirect URI to override the default redirect URI in the SDK options
|
|
212
|
+
* @param {string} [options.sdkMode='web'] - Optional SDK mode to include in the entry request (default is 'web')
|
|
213
|
+
* @returns {Promise<EntryResponse>} A promise resolving to the entry result.
|
|
214
|
+
* @throws {OidcError} If the entry request returns an OIDC error response.
|
|
215
|
+
* @throws {ServerError} If the entry request fails with a server error (HTTP 429 or 5xx).
|
|
216
|
+
* @throws {ProtocolError} If the entry request fails with a protocol error or missing required fields.
|
|
217
|
+
*/
|
|
218
|
+
export declare function fetchFlowEntry({ url, params, options, clientId, redirectUri, sdkMode, }: {
|
|
219
|
+
url: string | URL;
|
|
220
|
+
params: URLSearchParams;
|
|
221
|
+
options: SDKOptions;
|
|
222
|
+
clientId?: string;
|
|
223
|
+
redirectUri?: string;
|
|
224
|
+
sdkMode?: string;
|
|
225
|
+
}): Promise<EntryResponse>;
|
|
226
|
+
/**
|
|
227
|
+
* Finalizes the login session using the provided url.
|
|
228
|
+
*
|
|
229
|
+
* @param {Object} options - The options for finalizing the session
|
|
230
|
+
* @param {string | URL} options.url - The URL to finalize the session.
|
|
231
|
+
* @param {string} options.sessionId - The session ID to finalize the session with.
|
|
232
|
+
* @param {string} options.language - The language to use for the session.
|
|
233
|
+
* @param {SDKOptions} options.options - The SDK options containing client ID, redirect URI, storage, and other options.
|
|
234
|
+
* @returns {Promise<URL>} A promise that resolves to the redirect URL after finalizing the session.
|
|
235
|
+
* @throws {ServerError} If the request to finalize the session fails with a server error (HTTP 429 or 5xx).
|
|
236
|
+
* @throws {ProtocolError} If the response from the server is invalid or does not contain a valid redirect URI.
|
|
237
|
+
*/
|
|
238
|
+
export declare function finalizeLoginSession({ url, sessionId, language, options, }: {
|
|
239
|
+
url: string | URL;
|
|
240
|
+
sessionId: string;
|
|
241
|
+
language: string;
|
|
242
|
+
options: SDKOptions;
|
|
243
|
+
}): Promise<URL>;
|
|
244
|
+
/**
|
|
245
|
+
* Submits a login form to the authentication server.
|
|
246
|
+
*
|
|
247
|
+
* @param {Object} options - The options for submitting the form.
|
|
248
|
+
* @param {string} [options.formId] - The ID of the form to submit. If not provided, the init endpoint is used.
|
|
249
|
+
* @param {Record<string, unknown>} [options.body] - The form data to include in the request body.
|
|
250
|
+
* @param {string} options.sessionId - The session ID for the current authentication session.
|
|
251
|
+
* @param {string} options.language - The language preference sent in the `Accept-language` header.
|
|
252
|
+
* @param {SDKOptions} options.options - The SDK options.
|
|
253
|
+
* @returns {Promise<NativeFlowState>} A promise that resolves to the current login flow state.
|
|
254
|
+
* @throws {ServerError} If the server returns a non-recoverable HTTP error.
|
|
255
|
+
* @throws {FallbackError} If the server indicates the flow should fall back to the hosted UI.
|
|
256
|
+
* @throws {SessionExpiredError} If the session has expired (HTTP 403).
|
|
257
|
+
*/
|
|
258
|
+
export declare function submitLoginForm({ formId, body, sessionId, language, options, }: {
|
|
259
|
+
formId?: string;
|
|
260
|
+
body?: Record<string, unknown>;
|
|
261
|
+
sessionId: string;
|
|
262
|
+
language: string;
|
|
263
|
+
options: SDKOptions;
|
|
264
|
+
}): Promise<NativeFlowState>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{_ as e,a as t,c as n,d as r,f as i,g as a,h as o,i as s,l as c,m as l,n as u,o as d,p as f,r as p,s as m,t as h,u as g,v as _,y as v}from"../assets/oidc.mjs";export{h as buildAuthorizationUrl,u as buildEndSessionUrl,p as decodeJwt,s as defaultOptions,t as exchangeCode,d as fetchFlowEntry,m as finalizeLoginSession,n as generateCodeChallenge,c as generateCodeVerifier,g as generateJwt,r as generateRandomHex,i as getDefaultFlowState,f as getDiscoveryDocument,l as getSDKOptions,o as refreshToken,a as revokeToken,e as submitLoginForm,_ as verifyIdToken,v as verifyJwt};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../assets/server.cjs");exports.BACKCHANNEL_LOGOUT_EVENT=e.t,exports.DEFAULT_COOKIE_MAX_AGE=e.n,exports.DISALLOWED_PROXY_HEADERS=e.r,exports.RETURN_TO_COOKIE=e.i,exports.flushSetCookies=e.a,exports.getServerSDKOptions=e.o,exports.parseCookieHeader=e.s,exports.proxyResponse=e.c,exports.pushSetCookie=e.l,exports.serializeCookie=e.u,exports.toSafeRedirect=e.d;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { HttpClientResponse, SDKStorage, ServerCookieOptions, ServerAdapter, ServerSDKOptions, ServerStorage } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Disallowed headers that should not be proxied from the SDK to the client, as they may interfere with the response handling.
|
|
4
|
+
*/
|
|
5
|
+
export declare const DISALLOWED_PROXY_HEADERS: Set<string>;
|
|
6
|
+
/**
|
|
7
|
+
* Returns with the returnTo cookie name used for storing the returnTo URL in the server SDK.
|
|
8
|
+
*/
|
|
9
|
+
export declare const RETURN_TO_COOKIE = "sty.returnTo";
|
|
10
|
+
/**
|
|
11
|
+
* Backchannel logout event name used for identifying backchannel logout requests in the server SDK.
|
|
12
|
+
*/
|
|
13
|
+
export declare const BACKCHANNEL_LOGOUT_EVENT = "http://schemas.openid.net/event/backchannel-logout";
|
|
14
|
+
/**
|
|
15
|
+
* Default cookie max age in seconds (30 days).
|
|
16
|
+
*/
|
|
17
|
+
export declare const DEFAULT_COOKIE_MAX_AGE: number;
|
|
18
|
+
/**
|
|
19
|
+
* Returns with the server SDK options merged with the provided options.
|
|
20
|
+
*
|
|
21
|
+
* @param {SDKInitConfig} options - The SDK initialization configuration.
|
|
22
|
+
* @template InitOptions - The type of the SDK initialization configuration.
|
|
23
|
+
* @template Options - The type of the SDK options.
|
|
24
|
+
* @returns {Options} The merged SDK options.
|
|
25
|
+
*/
|
|
26
|
+
export declare function getServerSDKOptions<TEvent = unknown, Storage extends ServerStorage<TEvent> = ServerStorage<TEvent>, StateStorage extends SDKStorage = SDKStorage>(adapter: ServerAdapter<TEvent>, options: any): ServerSDKOptions<TEvent, Storage, StateStorage>;
|
|
27
|
+
/**
|
|
28
|
+
* Parses a `Cookie` request header into a plain name/value map.
|
|
29
|
+
*
|
|
30
|
+
* @param {string | null | undefined} header - The raw `Cookie` header value.
|
|
31
|
+
* @returns {Record<string, string>} The parsed cookies.
|
|
32
|
+
*/
|
|
33
|
+
export declare function parseCookieHeader(header: string | null | undefined): Record<string, string>;
|
|
34
|
+
/**
|
|
35
|
+
* Serializes a name/value pair into a `Set-Cookie` header value.
|
|
36
|
+
*
|
|
37
|
+
* @param {string} name - The cookie name.
|
|
38
|
+
* @param {string} value - The cookie value.
|
|
39
|
+
* @param {ServerCookieOptions} [options] - The cookie attributes.
|
|
40
|
+
* @returns {string} The serialized `Set-Cookie` header value.
|
|
41
|
+
*/
|
|
42
|
+
export declare function serializeCookie(name: string, value: string, options?: ServerCookieOptions): string;
|
|
43
|
+
/**
|
|
44
|
+
* Pushes a `Set-Cookie` header value into the cookie jar for the given event.
|
|
45
|
+
*
|
|
46
|
+
* @param {unknown} event - The framework-native request event.
|
|
47
|
+
* @param {string} header - The `Set-Cookie` header value to push.
|
|
48
|
+
*/
|
|
49
|
+
export declare function pushSetCookie(event: unknown, header: string): void;
|
|
50
|
+
/**
|
|
51
|
+
* Flushes the accumulated `Set-Cookie` headers from the cookie jar into the provided `Response`.
|
|
52
|
+
*
|
|
53
|
+
* @param {unknown} event - The framework-native request event.
|
|
54
|
+
* @param {Response} response - The `Response` object to append the `Set-Cookie` headers to.
|
|
55
|
+
* @returns {Response} The modified `Response` with the appended `Set-Cookie` headers.
|
|
56
|
+
*/
|
|
57
|
+
export declare function flushSetCookies(event: unknown, response: Response): Response;
|
|
58
|
+
/**
|
|
59
|
+
* Proxies an `HttpClientResponse` to a Web `Response`, preserving headers and status code.
|
|
60
|
+
*
|
|
61
|
+
* @param {HttpClientResponse<T>} response - The `HttpClientResponse` to proxy.
|
|
62
|
+
* @returns {Response} A `Response` object representing the proxied response.
|
|
63
|
+
*/
|
|
64
|
+
export declare function proxyResponse<T = unknown>(response: HttpClientResponse<T>): Response;
|
|
65
|
+
/**
|
|
66
|
+
* Returns a safe absolute redirect URL only if it shares the same origin as `safeBaseUrl`, preventing open redirects.
|
|
67
|
+
*
|
|
68
|
+
* @param {string | undefined | null} dangerousRedirect - The untrusted redirect path or URL.
|
|
69
|
+
* @param {string} safeBaseUrl - The trusted base URL whose origin is used as the allowed origin.
|
|
70
|
+
* @returns {string | null} The resolved URL string if safe, or `null`.
|
|
71
|
+
*/
|
|
72
|
+
export declare function toSafeRedirect(dangerousRedirect: string | undefined | null, safeBaseUrl: string): string | null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e,c as t,d as n,i as r,l as i,n as a,o,r as s,s as c,t as l,u}from"../assets/server.mjs";export{l as BACKCHANNEL_LOGOUT_EVENT,a as DEFAULT_COOKIE_MAX_AGE,s as DISALLOWED_PROXY_HEADERS,r as RETURN_TO_COOKIE,e as flushSetCookies,o as getServerSDKOptions,c as parseCookieHeader,t as proxyResponse,i as pushSetCookie,u as serializeCookie,n as toSafeRedirect};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./errors.cjs"),t=require("./common.cjs");function n(n={}){let r={state:null,code:null,error:null,error_description:null,id_token:null,access_token:null,refresh_token:null,token_type:`bearer`,scope:null,expires_in:null,expires_at:null,claims:null};if(typeof n.expires_in==`number`&&!isNaN(n.expires_in)&&(r.expires_at=Math.floor(n.expires_in)+t.timestamp()),Object.assign(r,n),r.access_token&&r.token_type?.toLowerCase()!==`bearer`)throw new e.ProtocolError(`Unsupported token_type: ${r.token_type}`);return r}function r(e){if(!e)return null;let t=n();try{Object.assign(t,JSON.parse(e))}catch{t=null}return t}function i(e){return JSON.stringify(e)}function a(e){return!e?.access_token||!e.expires_at||e.expires_at<=t.timestamp()}exports.createSession=n,exports.isSessionExpired=a,exports.loadSession=r,exports.serializeSession=i;
|
|
2
|
+
//# sourceMappingURL=session.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.cjs","names":[],"sources":["../../src/utils/session.ts"],"sourcesContent":["import type { SessionData } from '../types/oidc';\nimport { ProtocolError } from './errors';\nimport { timestamp } from './common';\n\n/**\n * Creates a new session object with default values and merges it with provided parameters.\n *\n * @param {Record<string, unknown>} params - Optional parameters to merge into the new session object.\n * @returns {SessionData} The newly created session object.\n */\nexport function createSession(params: Record<string, unknown> = {}): SessionData {\n\tconst session: SessionData = {\n\t\tstate: null,\n\t\tcode: null,\n\t\terror: null,\n\t\terror_description: null,\n\t\tid_token: null,\n\t\taccess_token: null,\n\t\trefresh_token: null,\n\t\ttoken_type: 'bearer',\n\t\tscope: null,\n\t\texpires_in: null,\n\t\texpires_at: null,\n\t\tclaims: null,\n\t};\n\n\tif (typeof params.expires_in === 'number' && !isNaN(params.expires_in)) {\n\t\tsession.expires_at = Math.floor(params.expires_in) + timestamp();\n\t}\n\n\tObject.assign(session, params);\n\n\tif (session.access_token && session.token_type?.toLowerCase() !== 'bearer') {\n\t\tthrow new ProtocolError(`Unsupported token_type: ${session.token_type}`);\n\t}\n\n\treturn session;\n}\n\n/**\n * Loads a serialized session from a JSON string.\n *\n * @param {string | null} serialized - The serialized session string to parse.\n * @returns {SessionData | null} The parsed session object, or null if parsing fails.\n */\nexport function loadSession(serialized: string | null): SessionData | null {\n\tif (!serialized) {\n\t\treturn null;\n\t}\n\n\tlet session: SessionData | null = createSession();\n\n\ttry {\n\t\tObject.assign(session, JSON.parse(serialized));\n\t} catch {\n\t\tsession = null;\n\t}\n\n\treturn session;\n}\n\n/**\n * Serializes a session object into a JSON string.\n *\n * @param {SessionData} session - The session object to serialize.\n * @returns {string} The serialized session string.\n */\nexport function serializeSession(session: SessionData): string {\n\treturn JSON.stringify(session);\n}\n\n/**\n * Checks if a session is expired based on its access token and expiration timestamp.\n *\n * @param {Partial<SessionData> | null} session - The session object to check for expiration.\n * @returns {boolean} True if the session is expired or invalid, false otherwise.\n */\nexport function isSessionExpired(session?: Partial<SessionData> | null): boolean {\n\treturn !session?.access_token || !session.expires_at || session.expires_at <= timestamp();\n}\n"],"mappings":"6HAUA,SAAgB,EAAc,EAAkC,CAAC,EAAgB,CAChF,IAAM,EAAuB,CAC5B,MAAO,KACP,KAAM,KACN,MAAO,KACP,kBAAmB,KACnB,SAAU,KACV,aAAc,KACd,cAAe,KACf,WAAY,SACZ,MAAO,KACP,WAAY,KACZ,WAAY,KACZ,OAAQ,IACT,EAQA,GANI,OAAO,EAAO,YAAe,UAAY,CAAC,MAAM,EAAO,UAAU,IACpE,EAAQ,WAAa,KAAK,MAAM,EAAO,UAAU,EAAI,EAAA,UAAU,GAGhE,OAAO,OAAO,EAAS,CAAM,EAEzB,EAAQ,cAAgB,EAAQ,YAAY,YAAY,IAAM,SACjE,MAAM,IAAI,EAAA,cAAc,2BAA2B,EAAQ,YAAY,EAGxE,OAAO,CACR,CAQA,SAAgB,EAAY,EAA+C,CAC1E,GAAI,CAAC,EACJ,OAAO,KAGR,IAAI,EAA8B,EAAc,EAEhD,GAAI,CACH,OAAO,OAAO,EAAS,KAAK,MAAM,CAAU,CAAC,CAC9C,MAAQ,CACP,EAAU,IACX,CAEA,OAAO,CACR,CAQA,SAAgB,EAAiB,EAA8B,CAC9D,OAAO,KAAK,UAAU,CAAO,CAC9B,CAQA,SAAgB,EAAiB,EAAgD,CAChF,MAAO,CAAC,GAAS,cAAgB,CAAC,EAAQ,YAAc,EAAQ,YAAc,EAAA,UAAU,CACzF"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { SessionData } from '../types/oidc';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a new session object with default values and merges it with provided parameters.
|
|
4
|
+
*
|
|
5
|
+
* @param {Record<string, unknown>} params - Optional parameters to merge into the new session object.
|
|
6
|
+
* @returns {SessionData} The newly created session object.
|
|
7
|
+
*/
|
|
8
|
+
export declare function createSession(params?: Record<string, unknown>): SessionData;
|
|
9
|
+
/**
|
|
10
|
+
* Loads a serialized session from a JSON string.
|
|
11
|
+
*
|
|
12
|
+
* @param {string | null} serialized - The serialized session string to parse.
|
|
13
|
+
* @returns {SessionData | null} The parsed session object, or null if parsing fails.
|
|
14
|
+
*/
|
|
15
|
+
export declare function loadSession(serialized: string | null): SessionData | null;
|
|
16
|
+
/**
|
|
17
|
+
* Serializes a session object into a JSON string.
|
|
18
|
+
*
|
|
19
|
+
* @param {SessionData} session - The session object to serialize.
|
|
20
|
+
* @returns {string} The serialized session string.
|
|
21
|
+
*/
|
|
22
|
+
export declare function serializeSession(session: SessionData): string;
|
|
23
|
+
/**
|
|
24
|
+
* Checks if a session is expired based on its access token and expiration timestamp.
|
|
25
|
+
*
|
|
26
|
+
* @param {Partial<SessionData> | null} session - The session object to check for expiration.
|
|
27
|
+
* @returns {boolean} True if the session is expired or invalid, false otherwise.
|
|
28
|
+
*/
|
|
29
|
+
export declare function isSessionExpired(session?: Partial<SessionData> | null): boolean;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{ProtocolError as e}from"./errors.mjs";import{timestamp as t}from"./common.mjs";function n(n={}){let r={state:null,code:null,error:null,error_description:null,id_token:null,access_token:null,refresh_token:null,token_type:`bearer`,scope:null,expires_in:null,expires_at:null,claims:null};if(typeof n.expires_in==`number`&&!isNaN(n.expires_in)&&(r.expires_at=Math.floor(n.expires_in)+t()),Object.assign(r,n),r.access_token&&r.token_type?.toLowerCase()!==`bearer`)throw new e(`Unsupported token_type: ${r.token_type}`);return r}function r(e){if(!e)return null;let t=n();try{Object.assign(t,JSON.parse(e))}catch{t=null}return t}function i(e){return JSON.stringify(e)}function a(e){return!e?.access_token||!e.expires_at||e.expires_at<=t()}export{n as createSession,a as isSessionExpired,r as loadSession,i as serializeSession};
|
|
2
|
+
//# sourceMappingURL=session.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.mjs","names":[],"sources":["../../src/utils/session.ts"],"sourcesContent":["import type { SessionData } from '../types/oidc';\nimport { ProtocolError } from './errors';\nimport { timestamp } from './common';\n\n/**\n * Creates a new session object with default values and merges it with provided parameters.\n *\n * @param {Record<string, unknown>} params - Optional parameters to merge into the new session object.\n * @returns {SessionData} The newly created session object.\n */\nexport function createSession(params: Record<string, unknown> = {}): SessionData {\n\tconst session: SessionData = {\n\t\tstate: null,\n\t\tcode: null,\n\t\terror: null,\n\t\terror_description: null,\n\t\tid_token: null,\n\t\taccess_token: null,\n\t\trefresh_token: null,\n\t\ttoken_type: 'bearer',\n\t\tscope: null,\n\t\texpires_in: null,\n\t\texpires_at: null,\n\t\tclaims: null,\n\t};\n\n\tif (typeof params.expires_in === 'number' && !isNaN(params.expires_in)) {\n\t\tsession.expires_at = Math.floor(params.expires_in) + timestamp();\n\t}\n\n\tObject.assign(session, params);\n\n\tif (session.access_token && session.token_type?.toLowerCase() !== 'bearer') {\n\t\tthrow new ProtocolError(`Unsupported token_type: ${session.token_type}`);\n\t}\n\n\treturn session;\n}\n\n/**\n * Loads a serialized session from a JSON string.\n *\n * @param {string | null} serialized - The serialized session string to parse.\n * @returns {SessionData | null} The parsed session object, or null if parsing fails.\n */\nexport function loadSession(serialized: string | null): SessionData | null {\n\tif (!serialized) {\n\t\treturn null;\n\t}\n\n\tlet session: SessionData | null = createSession();\n\n\ttry {\n\t\tObject.assign(session, JSON.parse(serialized));\n\t} catch {\n\t\tsession = null;\n\t}\n\n\treturn session;\n}\n\n/**\n * Serializes a session object into a JSON string.\n *\n * @param {SessionData} session - The session object to serialize.\n * @returns {string} The serialized session string.\n */\nexport function serializeSession(session: SessionData): string {\n\treturn JSON.stringify(session);\n}\n\n/**\n * Checks if a session is expired based on its access token and expiration timestamp.\n *\n * @param {Partial<SessionData> | null} session - The session object to check for expiration.\n * @returns {boolean} True if the session is expired or invalid, false otherwise.\n */\nexport function isSessionExpired(session?: Partial<SessionData> | null): boolean {\n\treturn !session?.access_token || !session.expires_at || session.expires_at <= timestamp();\n}\n"],"mappings":"sFAUA,SAAgB,EAAc,EAAkC,CAAC,EAAgB,CAChF,IAAM,EAAuB,CAC5B,MAAO,KACP,KAAM,KACN,MAAO,KACP,kBAAmB,KACnB,SAAU,KACV,aAAc,KACd,cAAe,KACf,WAAY,SACZ,MAAO,KACP,WAAY,KACZ,WAAY,KACZ,OAAQ,IACT,EAQA,GANI,OAAO,EAAO,YAAe,UAAY,CAAC,MAAM,EAAO,UAAU,IACpE,EAAQ,WAAa,KAAK,MAAM,EAAO,UAAU,EAAI,EAAU,GAGhE,OAAO,OAAO,EAAS,CAAM,EAEzB,EAAQ,cAAgB,EAAQ,YAAY,YAAY,IAAM,SACjE,MAAM,IAAI,EAAc,2BAA2B,EAAQ,YAAY,EAGxE,OAAO,CACR,CAQA,SAAgB,EAAY,EAA+C,CAC1E,GAAI,CAAC,EACJ,OAAO,KAGR,IAAI,EAA8B,EAAc,EAEhD,GAAI,CACH,OAAO,OAAO,EAAS,KAAK,MAAM,CAAU,CAAC,CAC9C,MAAQ,CACP,EAAU,IACX,CAEA,OAAO,CACR,CAQA,SAAgB,EAAiB,EAA8B,CAC9D,OAAO,KAAK,UAAU,CAAO,CAC9B,CAQA,SAAgB,EAAiB,EAAgD,CAChF,MAAO,CAAC,GAAS,cAAgB,CAAC,EAAQ,YAAc,EAAQ,YAAc,EAAU,CACzF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../assets/oidc.cjs");exports.createState=e.b,exports.parseState=e.x,exports.serializeState=e.S;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { StateData } from '../types/oidc';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a new state object for OAuth 2.0 authorization requests, including a code verifier and challenge for PKCE.
|
|
4
|
+
*
|
|
5
|
+
* @param {Record<string, unknown>} [metadata={}] Optional metadata to associate with the state.
|
|
6
|
+
* @returns {Promise<StateData>} A promise that resolves to the newly created state object.
|
|
7
|
+
*/
|
|
8
|
+
export declare function createState(metadata?: Record<string, unknown>): Promise<StateData>;
|
|
9
|
+
/**
|
|
10
|
+
* Parses a serialized state string into a StateData object.
|
|
11
|
+
*
|
|
12
|
+
* @param {string} serialized - The serialized state string to parse.
|
|
13
|
+
* @returns {StateData} The parsed StateData object.
|
|
14
|
+
* @throws {Error} If the serialized string is invalid or cannot be parsed.
|
|
15
|
+
*/
|
|
16
|
+
export declare function parseState(serialized: string): StateData;
|
|
17
|
+
/**
|
|
18
|
+
* Serializes a StateData object into a string for storage or transmission.
|
|
19
|
+
*
|
|
20
|
+
* @param {StateData} state - The StateData object to serialize.
|
|
21
|
+
* @returns {string} The serialized state string.
|
|
22
|
+
*/
|
|
23
|
+
export declare function serializeState(state: StateData): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{S as e,b as t,x as n}from"../assets/oidc.mjs";export{t as createState,n as parseState,e as serializeState};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strivacity/sdk-core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-beta.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Strivacity JavaScript SDK client",
|
|
6
6
|
"author": "strivacity <opensource@strivacity.com>",
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "https://github.com/Strivacity/sdk-js"
|
|
10
10
|
},
|
|
11
|
+
"sideEffects": false,
|
|
11
12
|
"main": "./dist/index.cjs",
|
|
12
13
|
"types": "./dist/index.d.ts",
|
|
13
14
|
"exports": {
|
|
@@ -17,29 +18,77 @@
|
|
|
17
18
|
"require": "./dist/index.cjs",
|
|
18
19
|
"default": "./dist/index.mjs"
|
|
19
20
|
},
|
|
21
|
+
"./flows": {
|
|
22
|
+
"types": "./dist/flows/index.d.ts",
|
|
23
|
+
"import": "./dist/flows/index.mjs",
|
|
24
|
+
"require": "./dist/flows/index.cjs",
|
|
25
|
+
"default": "./dist/flows/index.mjs"
|
|
26
|
+
},
|
|
20
27
|
"./flows/*": {
|
|
21
28
|
"types": "./dist/flows/*.d.ts",
|
|
22
29
|
"import": "./dist/flows/*.mjs",
|
|
23
30
|
"require": "./dist/flows/*.cjs",
|
|
24
31
|
"default": "./dist/flows/*.mjs"
|
|
25
32
|
},
|
|
33
|
+
"./handlers": {
|
|
34
|
+
"types": "./dist/handlers/index.d.ts",
|
|
35
|
+
"import": "./dist/handlers/index.mjs",
|
|
36
|
+
"require": "./dist/handlers/index.cjs",
|
|
37
|
+
"default": "./dist/handlers/index.mjs"
|
|
38
|
+
},
|
|
26
39
|
"./handlers/*": {
|
|
27
40
|
"types": "./dist/handlers/*.d.ts",
|
|
28
41
|
"import": "./dist/handlers/*.mjs",
|
|
29
42
|
"require": "./dist/handlers/*.cjs",
|
|
30
43
|
"default": "./dist/handlers/*.mjs"
|
|
31
44
|
},
|
|
45
|
+
"./storages": {
|
|
46
|
+
"types": "./dist/storages/index.d.ts",
|
|
47
|
+
"import": "./dist/storages/index.mjs",
|
|
48
|
+
"require": "./dist/storages/index.cjs",
|
|
49
|
+
"default": "./dist/storages/index.mjs"
|
|
50
|
+
},
|
|
32
51
|
"./storages/*": {
|
|
33
52
|
"types": "./dist/storages/*.d.ts",
|
|
34
53
|
"import": "./dist/storages/*.mjs",
|
|
35
54
|
"require": "./dist/storages/*.cjs",
|
|
36
55
|
"default": "./dist/storages/*.mjs"
|
|
37
56
|
},
|
|
57
|
+
"./server": {
|
|
58
|
+
"types": "./dist/server/index.d.ts",
|
|
59
|
+
"import": "./dist/server/index.mjs",
|
|
60
|
+
"require": "./dist/server/index.cjs",
|
|
61
|
+
"default": "./dist/server/index.mjs"
|
|
62
|
+
},
|
|
63
|
+
"./server/*": {
|
|
64
|
+
"types": "./dist/server/*.d.ts",
|
|
65
|
+
"import": "./dist/server/*.mjs",
|
|
66
|
+
"require": "./dist/server/*.cjs",
|
|
67
|
+
"default": "./dist/server/*.mjs"
|
|
68
|
+
},
|
|
69
|
+
"./utils": {
|
|
70
|
+
"types": "./dist/utils/index.d.ts",
|
|
71
|
+
"import": "./dist/utils/index.mjs",
|
|
72
|
+
"require": "./dist/utils/index.cjs",
|
|
73
|
+
"default": "./dist/utils/index.mjs"
|
|
74
|
+
},
|
|
38
75
|
"./utils/*": {
|
|
39
76
|
"types": "./dist/utils/*.d.ts",
|
|
40
77
|
"import": "./dist/utils/*.mjs",
|
|
41
78
|
"require": "./dist/utils/*.cjs",
|
|
42
79
|
"default": "./dist/utils/*.mjs"
|
|
80
|
+
},
|
|
81
|
+
"./types": {
|
|
82
|
+
"types": "./dist/types/index.d.ts",
|
|
83
|
+
"import": "./dist/types/index.mjs",
|
|
84
|
+
"require": "./dist/types/index.cjs",
|
|
85
|
+
"default": "./dist/types/index.mjs"
|
|
86
|
+
},
|
|
87
|
+
"./types/*": {
|
|
88
|
+
"types": "./dist/types/*.d.ts",
|
|
89
|
+
"import": "./dist/types/*.mjs",
|
|
90
|
+
"require": "./dist/types/*.cjs",
|
|
91
|
+
"default": "./dist/types/*.mjs"
|
|
43
92
|
}
|
|
44
93
|
},
|
|
45
94
|
"typesVersions": {
|
|
@@ -50,6 +99,9 @@
|
|
|
50
99
|
"storages/*": [
|
|
51
100
|
"./dist/storages/*"
|
|
52
101
|
],
|
|
102
|
+
"server/*": [
|
|
103
|
+
"./dist/server/*"
|
|
104
|
+
],
|
|
53
105
|
"utils/*": [
|
|
54
106
|
"./dist/utils/*"
|
|
55
107
|
]
|