@better-auth/sso 1.4.7-beta.2 → 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 +7 -7
- package/dist/client.d.mts +1 -1
- package/dist/{index-BWvN4yrs.d.mts → index-GoyGoP_a.d.mts} +390 -21
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +559 -63
- package/package.json +4 -4
- package/src/authn-request-store.ts +76 -0
- package/src/authn-request.test.ts +99 -0
- package/src/index.ts +46 -7
- 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 +415 -96
- package/src/saml.test.ts +781 -48
- package/src/types.ts +81 -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[
|
|
13
|
-
[34mℹ[39m [2mdist/[22m[32m[
|
|
14
|
-
[34mℹ[39m [2mdist/[22m[32mindex-
|
|
15
|
-
[34mℹ[39m 5 files, total:
|
|
16
|
-
[32m✔[39m Build complete in [
|
|
12
|
+
[34mℹ[39m [2mdist/[22m[32m[1mindex.d.mts[22m[39m [2m 1.44 kB[22m [2m│ gzip: 0.52 kB[22m
|
|
13
|
+
[34mℹ[39m [2mdist/[22m[32m[1mclient.d.mts[22m[39m [2m 0.49 kB[22m [2m│ gzip: 0.29 kB[22m
|
|
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,7 +1,44 @@
|
|
|
1
|
+
import { APIError } from "better-auth/api";
|
|
1
2
|
import * as z from "zod/v4";
|
|
2
3
|
import { OAuth2Tokens, User } from "better-auth";
|
|
3
4
|
import * as better_call7 from "better-call";
|
|
4
5
|
|
|
6
|
+
//#region src/authn-request-store.d.ts
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* AuthnRequest Store
|
|
10
|
+
*
|
|
11
|
+
* Tracks SAML AuthnRequest IDs to enable InResponseTo validation.
|
|
12
|
+
* This prevents:
|
|
13
|
+
* - Unsolicited SAML responses
|
|
14
|
+
* - Cross-provider response injection
|
|
15
|
+
* - Replay attacks
|
|
16
|
+
* - Expired login completions
|
|
17
|
+
*/
|
|
18
|
+
interface AuthnRequestRecord {
|
|
19
|
+
id: string;
|
|
20
|
+
providerId: string;
|
|
21
|
+
createdAt: number;
|
|
22
|
+
expiresAt: number;
|
|
23
|
+
}
|
|
24
|
+
interface AuthnRequestStore {
|
|
25
|
+
save(record: AuthnRequestRecord): Promise<void>;
|
|
26
|
+
get(id: string): Promise<AuthnRequestRecord | null>;
|
|
27
|
+
delete(id: string): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Default TTL for AuthnRequest records (5 minutes).
|
|
31
|
+
* This should be sufficient for most IdPs while protecting against stale requests.
|
|
32
|
+
*/
|
|
33
|
+
declare const DEFAULT_AUTHN_REQUEST_TTL_MS: number;
|
|
34
|
+
/**
|
|
35
|
+
* In-memory implementation of AuthnRequestStore.
|
|
36
|
+
* ⚠️ Only suitable for testing or single-instance non-serverless deployments.
|
|
37
|
+
* For production, rely on the default behavior (uses verification table)
|
|
38
|
+
* or provide a custom Redis-backed store.
|
|
39
|
+
*/
|
|
40
|
+
declare function createInMemoryAuthnRequestStore(): AuthnRequestStore;
|
|
41
|
+
//#endregion
|
|
5
42
|
//#region src/types.d.ts
|
|
6
43
|
interface OIDCMapping {
|
|
7
44
|
id?: string | undefined;
|
|
@@ -243,6 +280,86 @@ interface SSOOptions {
|
|
|
243
280
|
*/
|
|
244
281
|
tokenPrefix?: string;
|
|
245
282
|
};
|
|
283
|
+
/**
|
|
284
|
+
* SAML security options for AuthnRequest/InResponseTo validation.
|
|
285
|
+
* This prevents unsolicited responses, replay attacks, and cross-provider injection.
|
|
286
|
+
*/
|
|
287
|
+
saml?: {
|
|
288
|
+
/**
|
|
289
|
+
* Enable InResponseTo validation for SP-initiated SAML flows.
|
|
290
|
+
* When enabled, AuthnRequest IDs are tracked and validated against SAML responses.
|
|
291
|
+
*
|
|
292
|
+
* Storage behavior:
|
|
293
|
+
* - Uses `secondaryStorage` (e.g., Redis) if configured in your auth options
|
|
294
|
+
* - Falls back to the verification table in the database otherwise
|
|
295
|
+
*
|
|
296
|
+
* This works correctly in serverless environments without any additional configuration.
|
|
297
|
+
*
|
|
298
|
+
* @default false
|
|
299
|
+
*/
|
|
300
|
+
enableInResponseToValidation?: boolean;
|
|
301
|
+
/**
|
|
302
|
+
* Allow IdP-initiated SSO (unsolicited SAML responses).
|
|
303
|
+
* When true, responses without InResponseTo are accepted.
|
|
304
|
+
* When false, all responses must correlate to a stored AuthnRequest.
|
|
305
|
+
*
|
|
306
|
+
* Only applies when InResponseTo validation is enabled.
|
|
307
|
+
*
|
|
308
|
+
* @default true
|
|
309
|
+
*/
|
|
310
|
+
allowIdpInitiated?: boolean;
|
|
311
|
+
/**
|
|
312
|
+
* TTL for AuthnRequest records in milliseconds.
|
|
313
|
+
* Requests older than this will be rejected.
|
|
314
|
+
*
|
|
315
|
+
* Only applies when InResponseTo validation is enabled.
|
|
316
|
+
*
|
|
317
|
+
* @default 300000 (5 minutes)
|
|
318
|
+
*/
|
|
319
|
+
requestTTL?: number;
|
|
320
|
+
/**
|
|
321
|
+
* Custom AuthnRequest store implementation.
|
|
322
|
+
* Use this to provide a custom storage backend (e.g., Redis-backed store).
|
|
323
|
+
*
|
|
324
|
+
* Providing a custom store automatically enables InResponseTo validation.
|
|
325
|
+
*
|
|
326
|
+
* Note: When not provided, the default storage (secondaryStorage with
|
|
327
|
+
* verification table fallback) is used automatically.
|
|
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;
|
|
362
|
+
};
|
|
246
363
|
}
|
|
247
364
|
//#endregion
|
|
248
365
|
//#region src/routes/domain-verification.d.ts
|
|
@@ -291,8 +408,6 @@ declare const requestDomainVerification: (options: SSOOptions) => better_call7.S
|
|
|
291
408
|
};
|
|
292
409
|
};
|
|
293
410
|
}>)[];
|
|
294
|
-
} & {
|
|
295
|
-
use: any[];
|
|
296
411
|
}, {
|
|
297
412
|
domainVerificationToken: string;
|
|
298
413
|
}>;
|
|
@@ -344,11 +459,29 @@ declare const verifyDomain: (options: SSOOptions) => better_call7.StrictEndpoint
|
|
|
344
459
|
};
|
|
345
460
|
};
|
|
346
461
|
}>)[];
|
|
347
|
-
} & {
|
|
348
|
-
use: any[];
|
|
349
462
|
}, void>;
|
|
350
463
|
//#endregion
|
|
351
464
|
//#region src/routes/sso.d.ts
|
|
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;
|
|
352
485
|
declare const spMetadata: () => better_call7.StrictEndpoint<"/sso/saml2/sp/metadata", {
|
|
353
486
|
method: "GET";
|
|
354
487
|
query: z.ZodObject<{
|
|
@@ -370,8 +503,6 @@ declare const spMetadata: () => better_call7.StrictEndpoint<"/sso/saml2/sp/metad
|
|
|
370
503
|
};
|
|
371
504
|
};
|
|
372
505
|
};
|
|
373
|
-
} & {
|
|
374
|
-
use: any[];
|
|
375
506
|
}, Response>;
|
|
376
507
|
declare const registerSSOProvider: <O extends SSOOptions>(options: O) => better_call7.StrictEndpoint<"/sso/register", {
|
|
377
508
|
method: "POST";
|
|
@@ -391,6 +522,7 @@ declare const registerSSOProvider: <O extends SSOOptions>(options: O) => better_
|
|
|
391
522
|
}>>;
|
|
392
523
|
jwksEndpoint: z.ZodOptional<z.ZodString>;
|
|
393
524
|
discoveryEndpoint: z.ZodOptional<z.ZodString>;
|
|
525
|
+
skipDiscovery: z.ZodOptional<z.ZodBoolean>;
|
|
394
526
|
scopes: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
395
527
|
pkce: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
396
528
|
mapping: z.ZodOptional<z.ZodObject<{
|
|
@@ -635,8 +767,6 @@ declare const registerSSOProvider: <O extends SSOOptions>(options: O) => better_
|
|
|
635
767
|
};
|
|
636
768
|
};
|
|
637
769
|
};
|
|
638
|
-
} & {
|
|
639
|
-
use: any[];
|
|
640
770
|
}, O["domainVerification"] extends {
|
|
641
771
|
enabled: true;
|
|
642
772
|
} ? {
|
|
@@ -657,8 +787,8 @@ declare const signInSSO: (options?: SSOOptions) => better_call7.StrictEndpoint<"
|
|
|
657
787
|
loginHint: z.ZodOptional<z.ZodString>;
|
|
658
788
|
requestSignUp: z.ZodOptional<z.ZodBoolean>;
|
|
659
789
|
providerType: z.ZodOptional<z.ZodEnum<{
|
|
660
|
-
oidc: "oidc";
|
|
661
790
|
saml: "saml";
|
|
791
|
+
oidc: "oidc";
|
|
662
792
|
}>>;
|
|
663
793
|
}, z.core.$strip>;
|
|
664
794
|
metadata: {
|
|
@@ -733,8 +863,6 @@ declare const signInSSO: (options?: SSOOptions) => better_call7.StrictEndpoint<"
|
|
|
733
863
|
};
|
|
734
864
|
};
|
|
735
865
|
};
|
|
736
|
-
} & {
|
|
737
|
-
use: any[];
|
|
738
866
|
}, {
|
|
739
867
|
url: string;
|
|
740
868
|
redirect: boolean;
|
|
@@ -749,7 +877,6 @@ declare const callbackSSO: (options?: SSOOptions) => better_call7.StrictEndpoint
|
|
|
749
877
|
}, z.core.$strip>;
|
|
750
878
|
allowedMediaTypes: string[];
|
|
751
879
|
metadata: {
|
|
752
|
-
isAction: false;
|
|
753
880
|
openapi: {
|
|
754
881
|
operationId: string;
|
|
755
882
|
summary: string;
|
|
@@ -760,9 +887,8 @@ declare const callbackSSO: (options?: SSOOptions) => better_call7.StrictEndpoint
|
|
|
760
887
|
};
|
|
761
888
|
};
|
|
762
889
|
};
|
|
890
|
+
scope: "server";
|
|
763
891
|
};
|
|
764
|
-
} & {
|
|
765
|
-
use: any[];
|
|
766
892
|
}, never>;
|
|
767
893
|
declare const callbackSSOSAML: (options?: SSOOptions) => better_call7.StrictEndpoint<"/sso/saml2/callback/:providerId", {
|
|
768
894
|
method: "POST";
|
|
@@ -771,7 +897,6 @@ declare const callbackSSOSAML: (options?: SSOOptions) => better_call7.StrictEndp
|
|
|
771
897
|
RelayState: z.ZodOptional<z.ZodString>;
|
|
772
898
|
}, z.core.$strip>;
|
|
773
899
|
metadata: {
|
|
774
|
-
isAction: false;
|
|
775
900
|
allowedMediaTypes: string[];
|
|
776
901
|
openapi: {
|
|
777
902
|
operationId: string;
|
|
@@ -789,9 +914,8 @@ declare const callbackSSOSAML: (options?: SSOOptions) => better_call7.StrictEndp
|
|
|
789
914
|
};
|
|
790
915
|
};
|
|
791
916
|
};
|
|
917
|
+
scope: "server";
|
|
792
918
|
};
|
|
793
|
-
} & {
|
|
794
|
-
use: any[];
|
|
795
919
|
}, never>;
|
|
796
920
|
declare const acsEndpoint: (options?: SSOOptions) => better_call7.StrictEndpoint<"/sso/saml2/sp/acs/:providerId", {
|
|
797
921
|
method: "POST";
|
|
@@ -803,7 +927,6 @@ declare const acsEndpoint: (options?: SSOOptions) => better_call7.StrictEndpoint
|
|
|
803
927
|
RelayState: z.ZodOptional<z.ZodString>;
|
|
804
928
|
}, z.core.$strip>;
|
|
805
929
|
metadata: {
|
|
806
|
-
isAction: false;
|
|
807
930
|
allowedMediaTypes: string[];
|
|
808
931
|
openapi: {
|
|
809
932
|
operationId: string;
|
|
@@ -815,11 +938,257 @@ declare const acsEndpoint: (options?: SSOOptions) => better_call7.StrictEndpoint
|
|
|
815
938
|
};
|
|
816
939
|
};
|
|
817
940
|
};
|
|
941
|
+
scope: "server";
|
|
818
942
|
};
|
|
819
|
-
} & {
|
|
820
|
-
use: any[];
|
|
821
943
|
}, never>;
|
|
822
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
|
|
823
1192
|
//#region src/index.d.ts
|
|
824
1193
|
type DomainVerificationEndpoints = {
|
|
825
1194
|
requestDomainVerification: ReturnType<typeof requestDomainVerification>;
|
|
@@ -856,4 +1225,4 @@ declare function sso<O extends SSOOptions>(options?: O | undefined): {
|
|
|
856
1225
|
endpoints: SSOEndpoints<O>;
|
|
857
1226
|
};
|
|
858
1227
|
//#endregion
|
|
859
|
-
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 { OIDCConfig, SAMLConfig, SSOOptions, SSOPlugin, SSOProvider, 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 };
|