@better-auth/sso 1.4.7-beta.3 → 1.4.7-beta.4
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/.turbo/turbo-build.log +6 -6
- package/dist/client.d.mts +1 -1
- package/dist/{index-m7FISidt.d.mts → index-GoyGoP_a.d.mts} +314 -13
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +401 -16
- package/package.json +3 -3
- package/src/index.ts +27 -0
- package/src/oidc/discovery.test.ts +823 -0
- package/src/oidc/discovery.ts +355 -0
- package/src/oidc/errors.ts +86 -0
- package/src/oidc/index.ts +31 -0
- package/src/oidc/types.ts +210 -0
- package/src/oidc.test.ts +0 -164
- package/src/routes/sso.ts +191 -23
- package/src/saml.test.ts +301 -57
- package/src/types.ts +32 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @better-auth/sso@1.4.7-beta.
|
|
2
|
+
> @better-auth/sso@1.4.7-beta.4 build /home/runner/work/better-auth/better-auth/packages/sso
|
|
3
3
|
> tsdown
|
|
4
4
|
|
|
5
5
|
[34mℹ[39m tsdown [2mv0.17.2[22m powered by rolldown [2mv1.0.0-beta.53[22m
|
|
@@ -7,10 +7,10 @@
|
|
|
7
7
|
[34mℹ[39m entry: [34msrc/index.ts, src/client.ts[39m
|
|
8
8
|
[34mℹ[39m tsconfig: [34mtsconfig.json[39m
|
|
9
9
|
[34mℹ[39m Build start
|
|
10
|
-
[34mℹ[39m [2mdist/[22m[1mindex.mjs[22m [
|
|
10
|
+
[34mℹ[39m [2mdist/[22m[1mindex.mjs[22m [2m80.81 kB[22m [2m│ gzip: 15.19 kB[22m
|
|
11
11
|
[34mℹ[39m [2mdist/[22m[1mclient.mjs[22m [2m 0.15 kB[22m [2m│ gzip: 0.14 kB[22m
|
|
12
|
+
[34mℹ[39m [2mdist/[22m[32m[1mindex.d.mts[22m[39m [2m 1.44 kB[22m [2m│ gzip: 0.52 kB[22m
|
|
12
13
|
[34mℹ[39m [2mdist/[22m[32m[1mclient.d.mts[22m[39m [2m 0.49 kB[22m [2m│ gzip: 0.29 kB[22m
|
|
13
|
-
[34mℹ[39m [2mdist/[22m[
|
|
14
|
-
[34mℹ[39m
|
|
15
|
-
[
|
|
16
|
-
[32m✔[39m Build complete in [32m11484ms[39m
|
|
14
|
+
[34mℹ[39m [2mdist/[22m[32mindex-GoyGoP_a.d.mts[39m [2m41.30 kB[22m [2m│ gzip: 8.58 kB[22m
|
|
15
|
+
[34mℹ[39m 5 files, total: 124.19 kB
|
|
16
|
+
[32m✔[39m Build complete in [32m12053ms[39m
|
package/dist/client.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { APIError } from "better-auth/api";
|
|
1
2
|
import * as z from "zod/v4";
|
|
2
3
|
import { OAuth2Tokens, User } from "better-auth";
|
|
3
|
-
import * as
|
|
4
|
+
import * as better_call7 from "better-call";
|
|
4
5
|
|
|
5
6
|
//#region src/authn-request-store.d.ts
|
|
6
7
|
|
|
@@ -326,11 +327,43 @@ interface SSOOptions {
|
|
|
326
327
|
* verification table fallback) is used automatically.
|
|
327
328
|
*/
|
|
328
329
|
authnRequestStore?: AuthnRequestStore;
|
|
330
|
+
/**
|
|
331
|
+
* Clock skew tolerance for SAML assertion timestamp validation in milliseconds.
|
|
332
|
+
* Allows for minor time differences between IdP and SP servers.
|
|
333
|
+
*
|
|
334
|
+
* Defaults to 300000 (5 minutes) to accommodate:
|
|
335
|
+
* - Network latency and processing time
|
|
336
|
+
* - Clock synchronization differences (NTP drift)
|
|
337
|
+
* - Distributed systems across timezones
|
|
338
|
+
*
|
|
339
|
+
* For stricter security, reduce to 1-2 minutes (60000-120000).
|
|
340
|
+
* For highly distributed systems, increase up to 10 minutes (600000).
|
|
341
|
+
*
|
|
342
|
+
* @default 300000 (5 minutes)
|
|
343
|
+
*/
|
|
344
|
+
clockSkew?: number;
|
|
345
|
+
/**
|
|
346
|
+
* Require timestamp conditions (NotBefore/NotOnOrAfter) in SAML assertions.
|
|
347
|
+
* When enabled, assertions without timestamp conditions will be rejected.
|
|
348
|
+
*
|
|
349
|
+
* When disabled (default), assertions without timestamps are accepted
|
|
350
|
+
* but a warning is logged.
|
|
351
|
+
*
|
|
352
|
+
* **SAML Spec Notes:**
|
|
353
|
+
* - SAML 2.0 Core: Timestamps are OPTIONAL
|
|
354
|
+
* - SAML2Int (enterprise profile): Timestamps are REQUIRED
|
|
355
|
+
*
|
|
356
|
+
* **Recommendation:** Enable for enterprise/production deployments
|
|
357
|
+
* where your IdP follows SAML2Int (Okta, Azure AD, OneLogin, etc.)
|
|
358
|
+
*
|
|
359
|
+
* @default false
|
|
360
|
+
*/
|
|
361
|
+
requireTimestamps?: boolean;
|
|
329
362
|
};
|
|
330
363
|
}
|
|
331
364
|
//#endregion
|
|
332
365
|
//#region src/routes/domain-verification.d.ts
|
|
333
|
-
declare const requestDomainVerification: (options: SSOOptions) =>
|
|
366
|
+
declare const requestDomainVerification: (options: SSOOptions) => better_call7.StrictEndpoint<"/sso/request-domain-verification", {
|
|
334
367
|
method: "POST";
|
|
335
368
|
body: z.ZodObject<{
|
|
336
369
|
providerId: z.ZodString;
|
|
@@ -352,7 +385,7 @@ declare const requestDomainVerification: (options: SSOOptions) => better_call0.S
|
|
|
352
385
|
};
|
|
353
386
|
};
|
|
354
387
|
};
|
|
355
|
-
use: ((inputContext:
|
|
388
|
+
use: ((inputContext: better_call7.MiddlewareInputContext<better_call7.MiddlewareOptions>) => Promise<{
|
|
356
389
|
session: {
|
|
357
390
|
session: Record<string, any> & {
|
|
358
391
|
id: string;
|
|
@@ -378,7 +411,7 @@ declare const requestDomainVerification: (options: SSOOptions) => better_call0.S
|
|
|
378
411
|
}, {
|
|
379
412
|
domainVerificationToken: string;
|
|
380
413
|
}>;
|
|
381
|
-
declare const verifyDomain: (options: SSOOptions) =>
|
|
414
|
+
declare const verifyDomain: (options: SSOOptions) => better_call7.StrictEndpoint<"/sso/verify-domain", {
|
|
382
415
|
method: "POST";
|
|
383
416
|
body: z.ZodObject<{
|
|
384
417
|
providerId: z.ZodString;
|
|
@@ -403,7 +436,7 @@ declare const verifyDomain: (options: SSOOptions) => better_call0.StrictEndpoint
|
|
|
403
436
|
};
|
|
404
437
|
};
|
|
405
438
|
};
|
|
406
|
-
use: ((inputContext:
|
|
439
|
+
use: ((inputContext: better_call7.MiddlewareInputContext<better_call7.MiddlewareOptions>) => Promise<{
|
|
407
440
|
session: {
|
|
408
441
|
session: Record<string, any> & {
|
|
409
442
|
id: string;
|
|
@@ -429,7 +462,27 @@ declare const verifyDomain: (options: SSOOptions) => better_call0.StrictEndpoint
|
|
|
429
462
|
}, void>;
|
|
430
463
|
//#endregion
|
|
431
464
|
//#region src/routes/sso.d.ts
|
|
432
|
-
|
|
465
|
+
/** Default clock skew tolerance: 5 minutes */
|
|
466
|
+
declare const DEFAULT_CLOCK_SKEW_MS: number;
|
|
467
|
+
interface TimestampValidationOptions {
|
|
468
|
+
clockSkew?: number;
|
|
469
|
+
requireTimestamps?: boolean;
|
|
470
|
+
logger?: {
|
|
471
|
+
warn: (message: string, data?: Record<string, unknown>) => void;
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
/** Conditions extracted from SAML assertion */
|
|
475
|
+
interface SAMLConditions {
|
|
476
|
+
notBefore?: string;
|
|
477
|
+
notOnOrAfter?: string;
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* Validates SAML assertion timestamp conditions (NotBefore/NotOnOrAfter).
|
|
481
|
+
* Prevents acceptance of expired or future-dated assertions.
|
|
482
|
+
* @throws {APIError} If timestamps are invalid, expired, or not yet valid
|
|
483
|
+
*/
|
|
484
|
+
declare function validateSAMLTimestamp(conditions: SAMLConditions | undefined, options?: TimestampValidationOptions): void;
|
|
485
|
+
declare const spMetadata: () => better_call7.StrictEndpoint<"/sso/saml2/sp/metadata", {
|
|
433
486
|
method: "GET";
|
|
434
487
|
query: z.ZodObject<{
|
|
435
488
|
providerId: z.ZodString;
|
|
@@ -451,7 +504,7 @@ declare const spMetadata: () => better_call0.StrictEndpoint<"/sso/saml2/sp/metad
|
|
|
451
504
|
};
|
|
452
505
|
};
|
|
453
506
|
}, Response>;
|
|
454
|
-
declare const registerSSOProvider: <O extends SSOOptions>(options: O) =>
|
|
507
|
+
declare const registerSSOProvider: <O extends SSOOptions>(options: O) => better_call7.StrictEndpoint<"/sso/register", {
|
|
455
508
|
method: "POST";
|
|
456
509
|
body: z.ZodObject<{
|
|
457
510
|
providerId: z.ZodString;
|
|
@@ -469,6 +522,7 @@ declare const registerSSOProvider: <O extends SSOOptions>(options: O) => better_
|
|
|
469
522
|
}>>;
|
|
470
523
|
jwksEndpoint: z.ZodOptional<z.ZodString>;
|
|
471
524
|
discoveryEndpoint: z.ZodOptional<z.ZodString>;
|
|
525
|
+
skipDiscovery: z.ZodOptional<z.ZodBoolean>;
|
|
472
526
|
scopes: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
473
527
|
pkce: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
474
528
|
mapping: z.ZodOptional<z.ZodObject<{
|
|
@@ -529,7 +583,7 @@ declare const registerSSOProvider: <O extends SSOOptions>(options: O) => better_
|
|
|
529
583
|
organizationId: z.ZodOptional<z.ZodString>;
|
|
530
584
|
overrideUserInfo: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
531
585
|
}, z.core.$strip>;
|
|
532
|
-
use: ((inputContext:
|
|
586
|
+
use: ((inputContext: better_call7.MiddlewareInputContext<better_call7.MiddlewareOptions>) => Promise<{
|
|
533
587
|
session: {
|
|
534
588
|
session: Record<string, any> & {
|
|
535
589
|
id: string;
|
|
@@ -719,7 +773,7 @@ declare const registerSSOProvider: <O extends SSOOptions>(options: O) => better_
|
|
|
719
773
|
domainVerified: boolean;
|
|
720
774
|
domainVerificationToken: string;
|
|
721
775
|
} & SSOProvider<O> : SSOProvider<O>>;
|
|
722
|
-
declare const signInSSO: (options?: SSOOptions) =>
|
|
776
|
+
declare const signInSSO: (options?: SSOOptions) => better_call7.StrictEndpoint<"/sign-in/sso", {
|
|
723
777
|
method: "POST";
|
|
724
778
|
body: z.ZodObject<{
|
|
725
779
|
email: z.ZodOptional<z.ZodString>;
|
|
@@ -813,7 +867,7 @@ declare const signInSSO: (options?: SSOOptions) => better_call0.StrictEndpoint<"
|
|
|
813
867
|
url: string;
|
|
814
868
|
redirect: boolean;
|
|
815
869
|
}>;
|
|
816
|
-
declare const callbackSSO: (options?: SSOOptions) =>
|
|
870
|
+
declare const callbackSSO: (options?: SSOOptions) => better_call7.StrictEndpoint<"/sso/callback/:providerId", {
|
|
817
871
|
method: "GET";
|
|
818
872
|
query: z.ZodObject<{
|
|
819
873
|
code: z.ZodOptional<z.ZodString>;
|
|
@@ -836,7 +890,7 @@ declare const callbackSSO: (options?: SSOOptions) => better_call0.StrictEndpoint
|
|
|
836
890
|
scope: "server";
|
|
837
891
|
};
|
|
838
892
|
}, never>;
|
|
839
|
-
declare const callbackSSOSAML: (options?: SSOOptions) =>
|
|
893
|
+
declare const callbackSSOSAML: (options?: SSOOptions) => better_call7.StrictEndpoint<"/sso/saml2/callback/:providerId", {
|
|
840
894
|
method: "POST";
|
|
841
895
|
body: z.ZodObject<{
|
|
842
896
|
SAMLResponse: z.ZodString;
|
|
@@ -863,7 +917,7 @@ declare const callbackSSOSAML: (options?: SSOOptions) => better_call0.StrictEndp
|
|
|
863
917
|
scope: "server";
|
|
864
918
|
};
|
|
865
919
|
}, never>;
|
|
866
|
-
declare const acsEndpoint: (options?: SSOOptions) =>
|
|
920
|
+
declare const acsEndpoint: (options?: SSOOptions) => better_call7.StrictEndpoint<"/sso/saml2/sp/acs/:providerId", {
|
|
867
921
|
method: "POST";
|
|
868
922
|
params: z.ZodObject<{
|
|
869
923
|
providerId: z.ZodOptional<z.ZodString>;
|
|
@@ -888,6 +942,253 @@ declare const acsEndpoint: (options?: SSOOptions) => better_call0.StrictEndpoint
|
|
|
888
942
|
};
|
|
889
943
|
}, never>;
|
|
890
944
|
//#endregion
|
|
945
|
+
//#region src/oidc/types.d.ts
|
|
946
|
+
/**
|
|
947
|
+
* OIDC Discovery Types
|
|
948
|
+
*
|
|
949
|
+
* Types for the OIDC discovery document and hydrated configuration.
|
|
950
|
+
* Based on OpenID Connect Discovery 1.0 specification.
|
|
951
|
+
*
|
|
952
|
+
* @see https://openid.net/specs/openid-connect-discovery-1_0.html
|
|
953
|
+
*/
|
|
954
|
+
/**
|
|
955
|
+
* Raw OIDC Discovery Document as returned by the IdP's
|
|
956
|
+
* .well-known/openid-configuration endpoint.
|
|
957
|
+
*
|
|
958
|
+
* Required fields for Better Auth's OIDC support:
|
|
959
|
+
* - issuer
|
|
960
|
+
* - authorization_endpoint
|
|
961
|
+
* - token_endpoint
|
|
962
|
+
* - jwks_uri (required for ID token validation)
|
|
963
|
+
*
|
|
964
|
+
*/
|
|
965
|
+
interface OIDCDiscoveryDocument {
|
|
966
|
+
/** REQUIRED. URL using the https scheme that the OP asserts as its Issuer Identifier. */
|
|
967
|
+
issuer: string;
|
|
968
|
+
/** REQUIRED. URL of the OP's OAuth 2.0 Authorization Endpoint. */
|
|
969
|
+
authorization_endpoint: string;
|
|
970
|
+
/**
|
|
971
|
+
* REQUIRED (spec says "unless only implicit flow is used").
|
|
972
|
+
* URL of the OP's OAuth 2.0 Token Endpoint.
|
|
973
|
+
* We only support authorization code flow.
|
|
974
|
+
*/
|
|
975
|
+
token_endpoint: string;
|
|
976
|
+
/** REQUIRED. URL of the OP's JSON Web Key Set document for ID token validation. */
|
|
977
|
+
jwks_uri: string;
|
|
978
|
+
/** RECOMMENDED. URL of the OP's UserInfo Endpoint. */
|
|
979
|
+
userinfo_endpoint?: string;
|
|
980
|
+
/**
|
|
981
|
+
* OPTIONAL. JSON array containing a list of Client Authentication methods
|
|
982
|
+
* supported by this Token Endpoint.
|
|
983
|
+
* Default: ["client_secret_basic"]
|
|
984
|
+
*/
|
|
985
|
+
token_endpoint_auth_methods_supported?: string[];
|
|
986
|
+
/** OPTIONAL. JSON array containing a list of the OAuth 2.0 scope values that this server supports. */
|
|
987
|
+
scopes_supported?: string[];
|
|
988
|
+
/** OPTIONAL. JSON array containing a list of the OAuth 2.0 response_type values that this OP supports. */
|
|
989
|
+
response_types_supported?: string[];
|
|
990
|
+
/** OPTIONAL. JSON array containing a list of the Subject Identifier types that this OP supports. */
|
|
991
|
+
subject_types_supported?: string[];
|
|
992
|
+
/** OPTIONAL. JSON array containing a list of the JWS signing algorithms supported by the OP. */
|
|
993
|
+
id_token_signing_alg_values_supported?: string[];
|
|
994
|
+
/** OPTIONAL. JSON array containing a list of the claim names that the OP may supply values for. */
|
|
995
|
+
claims_supported?: string[];
|
|
996
|
+
/** OPTIONAL. URL of a page containing human-readable information about the OP. */
|
|
997
|
+
service_documentation?: string;
|
|
998
|
+
/** OPTIONAL. Boolean value specifying whether the OP supports use of the claims parameter. */
|
|
999
|
+
claims_parameter_supported?: boolean;
|
|
1000
|
+
/** OPTIONAL. Boolean value specifying whether the OP supports use of the request parameter. */
|
|
1001
|
+
request_parameter_supported?: boolean;
|
|
1002
|
+
/** OPTIONAL. Boolean value specifying whether the OP supports use of the request_uri parameter. */
|
|
1003
|
+
request_uri_parameter_supported?: boolean;
|
|
1004
|
+
/** OPTIONAL. Boolean value specifying whether the OP requires any request_uri values to be pre-registered. */
|
|
1005
|
+
require_request_uri_registration?: boolean;
|
|
1006
|
+
/** OPTIONAL. URL of the OP's end session endpoint. */
|
|
1007
|
+
end_session_endpoint?: string;
|
|
1008
|
+
/** OPTIONAL. URL of the OP's revocation endpoint. */
|
|
1009
|
+
revocation_endpoint?: string;
|
|
1010
|
+
/** OPTIONAL. URL of the OP's introspection endpoint. */
|
|
1011
|
+
introspection_endpoint?: string;
|
|
1012
|
+
/** OPTIONAL. JSON array of PKCE code challenge methods supported (e.g., "S256", "plain"). */
|
|
1013
|
+
code_challenge_methods_supported?: string[];
|
|
1014
|
+
/** Allow additional fields from the discovery document */
|
|
1015
|
+
[key: string]: unknown;
|
|
1016
|
+
}
|
|
1017
|
+
/**
|
|
1018
|
+
* Error codes for OIDC discovery operations.
|
|
1019
|
+
*/
|
|
1020
|
+
type DiscoveryErrorCode = /** Request to discovery endpoint timed out */
|
|
1021
|
+
"discovery_timeout"
|
|
1022
|
+
/** Discovery endpoint returned 404 or similar */ | "discovery_not_found"
|
|
1023
|
+
/** Discovery endpoint returned invalid JSON */ | "discovery_invalid_json"
|
|
1024
|
+
/** Discovery URL is invalid or malformed */ | "discovery_invalid_url"
|
|
1025
|
+
/** Discovery document issuer doesn't match configured issuer */ | "issuer_mismatch"
|
|
1026
|
+
/** Discovery document is missing required fields */ | "discovery_incomplete"
|
|
1027
|
+
/** IdP only advertises token auth methods that Better Auth doesn't currently support */ | "unsupported_token_auth_method"
|
|
1028
|
+
/** Catch-all for unexpected errors */ | "discovery_unexpected_error";
|
|
1029
|
+
/**
|
|
1030
|
+
* Custom error class for OIDC discovery failures.
|
|
1031
|
+
* Can be caught and mapped to APIError at the edge.
|
|
1032
|
+
*/
|
|
1033
|
+
declare class DiscoveryError extends Error {
|
|
1034
|
+
readonly code: DiscoveryErrorCode;
|
|
1035
|
+
readonly details?: Record<string, unknown>;
|
|
1036
|
+
constructor(code: DiscoveryErrorCode, message: string, details?: Record<string, unknown>, options?: {
|
|
1037
|
+
cause?: unknown;
|
|
1038
|
+
});
|
|
1039
|
+
}
|
|
1040
|
+
/**
|
|
1041
|
+
* Hydrated OIDC configuration after discovery.
|
|
1042
|
+
* This is the normalized shape that gets persisted to the database
|
|
1043
|
+
* or merged into provider config at runtime.
|
|
1044
|
+
*
|
|
1045
|
+
* Field names are camelCase to match Better Auth conventions.
|
|
1046
|
+
*/
|
|
1047
|
+
interface HydratedOIDCConfig {
|
|
1048
|
+
/** The issuer URL (validated to match configured issuer) */
|
|
1049
|
+
issuer: string;
|
|
1050
|
+
/** The discovery endpoint URL */
|
|
1051
|
+
discoveryEndpoint: string;
|
|
1052
|
+
/** URL of the authorization endpoint */
|
|
1053
|
+
authorizationEndpoint: string;
|
|
1054
|
+
/** URL of the token endpoint */
|
|
1055
|
+
tokenEndpoint: string;
|
|
1056
|
+
/** URL of the JWKS endpoint */
|
|
1057
|
+
jwksEndpoint: string;
|
|
1058
|
+
/** URL of the userinfo endpoint (optional) */
|
|
1059
|
+
userInfoEndpoint?: string;
|
|
1060
|
+
/** Token endpoint authentication method */
|
|
1061
|
+
tokenEndpointAuthentication?: "client_secret_basic" | "client_secret_post";
|
|
1062
|
+
/** Scopes supported by the IdP */
|
|
1063
|
+
scopesSupported?: string[];
|
|
1064
|
+
}
|
|
1065
|
+
/**
|
|
1066
|
+
* Parameters for the discoverOIDCConfig function.
|
|
1067
|
+
*/
|
|
1068
|
+
interface DiscoverOIDCConfigParams {
|
|
1069
|
+
/** The issuer URL to discover configuration from */
|
|
1070
|
+
issuer: string;
|
|
1071
|
+
/**
|
|
1072
|
+
* Optional existing configuration.
|
|
1073
|
+
* Values provided here will override discovered values.
|
|
1074
|
+
*/
|
|
1075
|
+
existingConfig?: Partial<HydratedOIDCConfig>;
|
|
1076
|
+
/**
|
|
1077
|
+
* Optional custom discovery endpoint URL.
|
|
1078
|
+
* If not provided, defaults to <issuer>/.well-known/openid-configuration
|
|
1079
|
+
*/
|
|
1080
|
+
discoveryEndpoint?: string;
|
|
1081
|
+
/**
|
|
1082
|
+
* Optional timeout in milliseconds for the discovery request.
|
|
1083
|
+
* @default 10000 (10 seconds)
|
|
1084
|
+
*/
|
|
1085
|
+
timeout?: number;
|
|
1086
|
+
}
|
|
1087
|
+
/**
|
|
1088
|
+
* Required fields that must be present in a valid discovery document.
|
|
1089
|
+
*/
|
|
1090
|
+
declare const REQUIRED_DISCOVERY_FIELDS: readonly ["issuer", "authorization_endpoint", "token_endpoint", "jwks_uri"];
|
|
1091
|
+
type RequiredDiscoveryField = (typeof REQUIRED_DISCOVERY_FIELDS)[number];
|
|
1092
|
+
//#endregion
|
|
1093
|
+
//#region src/oidc/discovery.d.ts
|
|
1094
|
+
/**
|
|
1095
|
+
* Main entry point: Discover and hydrate OIDC configuration from an issuer.
|
|
1096
|
+
*
|
|
1097
|
+
* This function:
|
|
1098
|
+
* 1. Computes the discovery URL from the issuer
|
|
1099
|
+
* 2. Validates the discovery URL (stub for now)
|
|
1100
|
+
* 3. Fetches the discovery document
|
|
1101
|
+
* 4. Validates the discovery document (issuer match + required fields)
|
|
1102
|
+
* 5. Normalizes URLs (stub for now)
|
|
1103
|
+
* 6. Selects token endpoint auth method
|
|
1104
|
+
* 7. Merges with existing config (existing values take precedence)
|
|
1105
|
+
*
|
|
1106
|
+
* @param params - Discovery parameters
|
|
1107
|
+
* @returns Hydrated OIDC configuration ready for persistence
|
|
1108
|
+
* @throws DiscoveryError on any failure
|
|
1109
|
+
*/
|
|
1110
|
+
declare function discoverOIDCConfig(params: DiscoverOIDCConfigParams): Promise<HydratedOIDCConfig>;
|
|
1111
|
+
/**
|
|
1112
|
+
* Compute the discovery URL from an issuer URL.
|
|
1113
|
+
*
|
|
1114
|
+
* Per OIDC Discovery spec, the discovery document is located at:
|
|
1115
|
+
* <issuer>/.well-known/openid-configuration
|
|
1116
|
+
*
|
|
1117
|
+
* Handles trailing slashes correctly.
|
|
1118
|
+
*/
|
|
1119
|
+
declare function computeDiscoveryUrl(issuer: string): string;
|
|
1120
|
+
/**
|
|
1121
|
+
* Validate a discovery URL before fetching.
|
|
1122
|
+
*
|
|
1123
|
+
* @param url - The discovery URL to validate
|
|
1124
|
+
* @throws DiscoveryError if URL is invalid
|
|
1125
|
+
*/
|
|
1126
|
+
declare function validateDiscoveryUrl(url: string): void;
|
|
1127
|
+
/**
|
|
1128
|
+
* Fetch the OIDC discovery document from the IdP.
|
|
1129
|
+
*
|
|
1130
|
+
* @param url - The discovery endpoint URL
|
|
1131
|
+
* @param timeout - Request timeout in milliseconds
|
|
1132
|
+
* @returns The parsed discovery document
|
|
1133
|
+
* @throws DiscoveryError on network errors, timeouts, or invalid responses
|
|
1134
|
+
*/
|
|
1135
|
+
declare function fetchDiscoveryDocument(url: string, timeout?: number): Promise<OIDCDiscoveryDocument>;
|
|
1136
|
+
/**
|
|
1137
|
+
* Validate a discovery document.
|
|
1138
|
+
*
|
|
1139
|
+
* Checks:
|
|
1140
|
+
* 1. All required fields are present
|
|
1141
|
+
* 2. Issuer matches the configured issuer (case-sensitive, exact match)
|
|
1142
|
+
*
|
|
1143
|
+
* Invariant: If this function returns without throwing, the document is safe
|
|
1144
|
+
* to use for hydrating OIDC config (required fields present, issuer matches
|
|
1145
|
+
* configured value, basic structural sanity verified).
|
|
1146
|
+
*
|
|
1147
|
+
* @param doc - The discovery document to validate
|
|
1148
|
+
* @param configuredIssuer - The expected issuer value
|
|
1149
|
+
* @throws DiscoveryError if validation fails
|
|
1150
|
+
*/
|
|
1151
|
+
declare function validateDiscoveryDocument(doc: OIDCDiscoveryDocument, configuredIssuer: string): void;
|
|
1152
|
+
/**
|
|
1153
|
+
* Normalize URLs in the discovery document.
|
|
1154
|
+
*
|
|
1155
|
+
* @param doc - The discovery document
|
|
1156
|
+
* @param _issuerBase - The base issuer URL
|
|
1157
|
+
* @returns The normalized discovery document
|
|
1158
|
+
*/
|
|
1159
|
+
declare function normalizeDiscoveryUrls(doc: OIDCDiscoveryDocument, _issuerBase: string): OIDCDiscoveryDocument;
|
|
1160
|
+
/**
|
|
1161
|
+
* Normalize a single URL endpoint.
|
|
1162
|
+
*
|
|
1163
|
+
* @param endpoint - The endpoint URL to normalize
|
|
1164
|
+
* @param _issuerBase - The base issuer URL
|
|
1165
|
+
* @returns The normalized endpoint URL
|
|
1166
|
+
*/
|
|
1167
|
+
declare function normalizeUrl(endpoint: string, _issuerBase: string): string;
|
|
1168
|
+
/**
|
|
1169
|
+
* Select the token endpoint authentication method.
|
|
1170
|
+
*
|
|
1171
|
+
* @param doc - The discovery document
|
|
1172
|
+
* @param existing - Existing authentication method from config
|
|
1173
|
+
* @returns The selected authentication method
|
|
1174
|
+
*/
|
|
1175
|
+
declare function selectTokenEndpointAuthMethod(doc: OIDCDiscoveryDocument, existing?: "client_secret_basic" | "client_secret_post"): "client_secret_basic" | "client_secret_post";
|
|
1176
|
+
/**
|
|
1177
|
+
* Check if a provider configuration needs runtime discovery.
|
|
1178
|
+
*
|
|
1179
|
+
* Returns true if we need discovery at runtime to complete the token exchange
|
|
1180
|
+
* and validation. Specifically checks for:
|
|
1181
|
+
* - `tokenEndpoint` - required for exchanging authorization code for tokens
|
|
1182
|
+
* - `jwksEndpoint` - required for validating ID token signatures
|
|
1183
|
+
*
|
|
1184
|
+
* Note: `authorizationEndpoint` is handled separately in the sign-in flow,
|
|
1185
|
+
* so it's not checked here.
|
|
1186
|
+
*
|
|
1187
|
+
* @param config - Partial OIDC config from the provider
|
|
1188
|
+
* @returns true if runtime discovery should be performed
|
|
1189
|
+
*/
|
|
1190
|
+
declare function needsRuntimeDiscovery(config: Partial<HydratedOIDCConfig> | undefined): boolean;
|
|
1191
|
+
//#endregion
|
|
891
1192
|
//#region src/index.d.ts
|
|
892
1193
|
type DomainVerificationEndpoints = {
|
|
893
1194
|
requestDomainVerification: ReturnType<typeof requestDomainVerification>;
|
|
@@ -924,4 +1225,4 @@ declare function sso<O extends SSOOptions>(options?: O | undefined): {
|
|
|
924
1225
|
endpoints: SSOEndpoints<O>;
|
|
925
1226
|
};
|
|
926
1227
|
//#endregion
|
|
927
|
-
export { SSOOptions as a,
|
|
1228
|
+
export { createInMemoryAuthnRequestStore as A, OIDCConfig as C, AuthnRequestRecord as D, SSOProvider as E, AuthnRequestStore as O, validateSAMLTimestamp as S, SSOOptions as T, REQUIRED_DISCOVERY_FIELDS as _, fetchDiscoveryDocument as a, SAMLConditions as b, normalizeUrl as c, validateDiscoveryUrl as d, DiscoverOIDCConfigParams as f, OIDCDiscoveryDocument as g, HydratedOIDCConfig as h, discoverOIDCConfig as i, DEFAULT_AUTHN_REQUEST_TTL_MS as k, selectTokenEndpointAuthMethod as l, DiscoveryErrorCode as m, sso as n, needsRuntimeDiscovery as o, DiscoveryError as p, computeDiscoveryUrl as r, normalizeDiscoveryUrls as s, SSOPlugin as t, validateDiscoveryDocument as u, RequiredDiscoveryField as v, SAMLConfig as w, TimestampValidationOptions as x, DEFAULT_CLOCK_SKEW_MS as y };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { AuthnRequestRecord, AuthnRequestStore, DEFAULT_AUTHN_REQUEST_TTL_MS, OIDCConfig, SAMLConfig, SSOOptions, SSOPlugin, SSOProvider, createInMemoryAuthnRequestStore, sso };
|
|
1
|
+
import { A as createInMemoryAuthnRequestStore, C as OIDCConfig, D as AuthnRequestRecord, E as SSOProvider, O as AuthnRequestStore, S as validateSAMLTimestamp, T as SSOOptions, _ as REQUIRED_DISCOVERY_FIELDS, a as fetchDiscoveryDocument, b as SAMLConditions, c as normalizeUrl, d as validateDiscoveryUrl, f as DiscoverOIDCConfigParams, g as OIDCDiscoveryDocument, h as HydratedOIDCConfig, i as discoverOIDCConfig, k as DEFAULT_AUTHN_REQUEST_TTL_MS, l as selectTokenEndpointAuthMethod, m as DiscoveryErrorCode, n as sso, o as needsRuntimeDiscovery, p as DiscoveryError, r as computeDiscoveryUrl, s as normalizeDiscoveryUrls, t as SSOPlugin, u as validateDiscoveryDocument, v as RequiredDiscoveryField, w as SAMLConfig, x as TimestampValidationOptions, y as DEFAULT_CLOCK_SKEW_MS } from "./index-GoyGoP_a.mjs";
|
|
2
|
+
export { AuthnRequestRecord, AuthnRequestStore, DEFAULT_AUTHN_REQUEST_TTL_MS, DEFAULT_CLOCK_SKEW_MS, DiscoverOIDCConfigParams, DiscoveryError, DiscoveryErrorCode, HydratedOIDCConfig, OIDCConfig, OIDCDiscoveryDocument, REQUIRED_DISCOVERY_FIELDS, RequiredDiscoveryField, SAMLConditions, SAMLConfig, SSOOptions, SSOPlugin, SSOProvider, TimestampValidationOptions, computeDiscoveryUrl, createInMemoryAuthnRequestStore, discoverOIDCConfig, fetchDiscoveryDocument, needsRuntimeDiscovery, normalizeDiscoveryUrls, normalizeUrl, selectTokenEndpointAuthMethod, sso, validateDiscoveryDocument, validateDiscoveryUrl, validateSAMLTimestamp };
|