@better-auth/sso 1.7.0-rc.1 → 1.7.0-rc.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/client.d.mts CHANGED
@@ -1,6 +1,5 @@
1
- import { t as SSOPlugin } from "./index-A_DJ_AqL.mjs";
1
+ import { t as SSOPlugin } from "./index-Sxfa9KQp.mjs";
2
2
  import { DBFieldAttribute } from "better-auth/db";
3
-
4
3
  //#region src/client.d.ts
5
4
  interface SSOClientOptions {
6
5
  domainVerification?: {
package/dist/client.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as PACKAGE_VERSION } from "./version-lPD-GbqS.mjs";
1
+ import { t as PACKAGE_VERSION } from "./version-xoFrTW0m.mjs";
2
2
  //#region src/client.ts
3
3
  const ssoClient = (options) => {
4
4
  return {
@@ -1,9 +1,11 @@
1
1
  import { APIError } from "better-auth/api";
2
2
  import * as z from "zod";
3
+ import "@better-fetch/fetch";
4
+ import samlifyDefault from "samlify";
3
5
  import { DBFieldAttribute, FieldAttributeToObject, InferAdditionalFieldsFromPluginOptions, RemoveFieldsWithReturnedFalse } from "better-auth/db";
4
- import { Awaitable, OAuth2Tokens, User } from "better-auth";
5
- import * as better_call0 from "better-call";
6
-
6
+ import { Awaitable, DBTransactionAdapter, OAuth2Tokens, User } from "better-auth";
7
+ import "@better-auth/core/db/adapter";
8
+ import "@better-auth/core";
7
9
  //#region src/saml/algorithms.d.ts
8
10
  declare const SignatureAlgorithm: {
9
11
  readonly RSA_SHA1: "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
@@ -45,7 +47,6 @@ interface AlgorithmValidationOptions {
45
47
  //#endregion
46
48
  //#region src/types.d.ts
47
49
  interface OIDCMapping {
48
- id?: string | undefined;
49
50
  email?: string | undefined;
50
51
  emailVerified?: string | undefined;
51
52
  name?: string | undefined;
@@ -53,7 +54,6 @@ interface OIDCMapping {
53
54
  extraFields?: Record<string, string> | undefined;
54
55
  }
55
56
  interface SAMLMapping {
56
- id?: string | undefined;
57
57
  email?: string | undefined;
58
58
  emailVerified?: string | undefined;
59
59
  name?: string | undefined;
@@ -90,6 +90,41 @@ interface OIDCConfig {
90
90
  */
91
91
  allowIdpInitiated?: boolean | undefined;
92
92
  }
93
+ interface SAMLIdentityProviderMetadataBase {
94
+ /**
95
+ * IdP signing certificate(s). Pass a single PEM string or an array for
96
+ * rolling rotation. Takes precedence over the top-level `cert` when both
97
+ * are set. Omit when `metadata` XML is supplied.
98
+ */
99
+ cert?: string | string[] | undefined;
100
+ privateKey?: string | undefined;
101
+ privateKeyPass?: string | undefined;
102
+ isAssertionEncrypted?: boolean | undefined;
103
+ encPrivateKey?: string | undefined;
104
+ encPrivateKeyPass?: string | undefined;
105
+ singleSignOnService?: Array<{
106
+ Binding: string;
107
+ Location: string;
108
+ }> | undefined;
109
+ singleLogoutService?: Array<{
110
+ Binding: string;
111
+ Location: string;
112
+ }> | undefined;
113
+ }
114
+ /**
115
+ * The trusted identity-provider authority for a SAML connection.
116
+ *
117
+ * Metadata XML carries the IdP entity ID. Manual configurations must declare
118
+ * `entityID` explicitly so the service provider's issuer is never mistaken
119
+ * for the identity provider's authority.
120
+ */
121
+ type SAMLIdentityProviderMetadata = SAMLIdentityProviderMetadataBase & ({
122
+ metadata: string;
123
+ entityID?: string | undefined;
124
+ } | {
125
+ metadata?: undefined;
126
+ entityID: string;
127
+ });
93
128
  interface SAMLConfig {
94
129
  /**
95
130
  * SP Entity ID. Used as the `entityID` in SP metadata when
@@ -118,29 +153,12 @@ interface SAMLConfig {
118
153
  * flows when no RelayState callback URL is available.
119
154
  */
120
155
  callbackUrl?: string | undefined;
121
- idpMetadata?: {
122
- metadata?: string;
123
- entityID?: string;
124
- /**
125
- * IdP signing certificate(s). Pass a single PEM string or an array
126
- * for rolling rotation. Takes precedence over the top-level `cert`
127
- * when both are set. Omit when `metadata` XML is supplied.
128
- */
129
- cert?: string | string[];
130
- privateKey?: string;
131
- privateKeyPass?: string;
132
- isAssertionEncrypted?: boolean;
133
- encPrivateKey?: string;
134
- encPrivateKeyPass?: string;
135
- singleSignOnService?: Array<{
136
- Binding: string;
137
- Location: string;
138
- }>;
139
- singleLogoutService?: Array<{
140
- Binding: string;
141
- Location: string;
142
- }>;
143
- } | undefined;
156
+ /**
157
+ * Fallback absolute URL or same-origin relative path for IdP-initiated SAML
158
+ * responses when RelayState has no safe callback, including error redirects.
159
+ */
160
+ idpInitiatedCallbackUrl?: string | undefined;
161
+ idpMetadata: SAMLIdentityProviderMetadata;
144
162
  /**
145
163
  * SP metadata configuration. All fields are optional; when omitted,
146
164
  * SP metadata is auto-generated from `issuer`, `wantAssertionsSigned`,
@@ -157,9 +175,10 @@ interface SAMLConfig {
157
175
  encPrivateKeyPass?: string | undefined;
158
176
  };
159
177
  /**
160
- * Request signed assertions from the IdP. When true, the SP metadata
161
- * advertises `WantAssertionsSigned="true"` and samlify will reject
162
- * unsigned assertions.
178
+ * Request and require signed assertions from the IdP. When true, generated
179
+ * SP metadata advertises `WantAssertionsSigned="true"` and the ACS rejects
180
+ * unsigned assertions. Custom SP metadata supplies the effective policy and
181
+ * accepts the XML Schema boolean forms `true`, `false`, `1`, and `0`.
163
182
  */
164
183
  wantAssertionsSigned?: boolean | undefined;
165
184
  authnRequestsSigned?: boolean | undefined;
@@ -204,7 +223,125 @@ type SSOProviderSchema<O extends SSOOptions> = {
204
223
  } ? Field : {});
205
224
  };
206
225
  };
226
+ /** Decision returned by an SSO user resolver. */
227
+ type SSOUserResolution = {
228
+ action: "continue";
229
+ } | {
230
+ action: "link";
231
+ userId: string;
232
+ profile: "preserve" | "update";
233
+ } | {
234
+ action: "reject";
235
+ code: string;
236
+ message?: string | undefined;
237
+ };
238
+ /** Normalized provider attributes available to an SSO user resolver. */
239
+ type SSOProviderUserProfile = {
240
+ email: string;
241
+ emailVerified: boolean;
242
+ name: string;
243
+ image?: string | null | undefined;
244
+ } & Record<string, unknown>;
245
+ /**
246
+ * Opaque reference to the SSO provider configuration accepted for the current
247
+ * authentication flow.
248
+ *
249
+ * This reference is a transient authentication fence. Applications must not
250
+ * persist it as a tenant or user binding.
251
+ */
252
+ interface SSOProviderReference {
253
+ providerId: string;
254
+ source: {
255
+ type: "configured";
256
+ } | {
257
+ type: "persisted";
258
+ recordId: string;
259
+ };
260
+ authenticationConfigurationFingerprint: string;
261
+ }
262
+ interface BaseSSOUserResolutionInput {
263
+ providerId: string;
264
+ accountKey: {
265
+ issuer: string;
266
+ providerAccountId: string;
267
+ };
268
+ providerUser: SSOProviderUserProfile;
269
+ providerReference: SSOProviderReference;
270
+ }
271
+ /** OIDC identity and profile data available to an application's SSO resolver. */
272
+ interface SSOOIDCUserResolutionInput extends BaseSSOUserResolutionInput {
273
+ protocol: "oidc";
274
+ /** Raw claims from UserInfo, or the verified ID Token when UserInfo is absent. */
275
+ providerClaims: Record<string, unknown>;
276
+ /** Claims from the cryptographically verified ID Token. */
277
+ verifiedIdTokenClaims: Record<string, unknown>;
278
+ }
279
+ /** SAML identity and assertion data available to an application's SSO resolver. */
280
+ interface SSOSAMLUserResolutionInput extends BaseSSOUserResolutionInput {
281
+ protocol: "saml";
282
+ /**
283
+ * Attributes from the verified assertion. Multi-valued attributes remain
284
+ * arrays and all scalar values remain strings.
285
+ */
286
+ providerAttributes: Record<string, string | readonly string[]>;
287
+ }
288
+ /** Verified SSO identity and provider data available to an application resolver. */
289
+ type SSOUserResolutionInput = SSOOIDCUserResolutionInput | SSOSAMLUserResolutionInput;
290
+ /** Transaction-bound capabilities available while resolving an SSO user. */
291
+ interface SSOUserResolutionContext {
292
+ database: DBTransactionAdapter;
293
+ }
294
+ interface BaseSSOProviderMutationGuardInput {
295
+ provider: {
296
+ id: string;
297
+ providerId: string;
298
+ organizationId: string | null;
299
+ };
300
+ /**
301
+ * Opaque reference to the exact locked provider configuration.
302
+ *
303
+ * This value is transient and must not be persisted as a tenant binding.
304
+ */
305
+ providerReference: SSOProviderReference;
306
+ }
307
+ /** Mutation attempted against one exact persisted SSO provider row. */
308
+ type SSOProviderMutationGuardInput = (BaseSSOProviderMutationGuardInput & {
309
+ action: "update";
310
+ /**
311
+ * True when the validated proposal changes provider identity,
312
+ * routing, or verification policy used to authenticate accounts.
313
+ */
314
+ isAuthenticationBoundaryChange: boolean;
315
+ }) | (BaseSSOProviderMutationGuardInput & {
316
+ action: "delete";
317
+ });
318
+ /** Transaction-bound context for guarding a persisted provider mutation. */
319
+ interface SSOProviderMutationGuardContext {
320
+ database: DBTransactionAdapter;
321
+ }
207
322
  interface SSOOptions {
323
+ /**
324
+ * Resolve a verified provider identity to a Better Auth user.
325
+ *
326
+ * For OIDC, `accountKey` is derived from the validated ID Token. For SAML,
327
+ * it contains the verified IdP entity ID and signed NameID. Profile fields,
328
+ * raw OIDC claims, and SAML assertion attributes are protocol-accepted
329
+ * provider data and may require application-level validation.
330
+ *
331
+ * The callback runs on every SSO sign-in inside the same native database
332
+ * transaction as account finalization and session creation.
333
+ */
334
+ resolveUser?: ((input: SSOUserResolutionInput, context: SSOUserResolutionContext) => Awaitable<SSOUserResolution>) | undefined;
335
+ /**
336
+ * Guards updates and deletion of an exact persisted SSO provider.
337
+ *
338
+ * The callback runs after the provider row is locked and before any provider
339
+ * or linked Account mutation. Update inputs disclose only whether the
340
+ * validated proposal changes the authentication boundary; proposed secrets
341
+ * and configuration values are never exposed. Throw to reject the mutation.
342
+ * Better Auth converts callback failures into a stable conflict response.
343
+ */
344
+ guardProviderMutation?: ((input: SSOProviderMutationGuardInput, context: SSOProviderMutationGuardContext) => Awaitable<void>) | undefined;
208
345
  /**
209
346
  * custom function to provision a user when they sign in with an SSO provider.
210
347
  */
@@ -341,7 +478,7 @@ interface SSOOptions {
341
478
  domain?: string | undefined;
342
479
  domainVerified?: string | undefined;
343
480
  };
344
- additionalFields?: { [key in string]: DBFieldAttribute };
481
+ additionalFields?: { [key in string]: DBFieldAttribute; };
345
482
  };
346
483
  } | undefined;
347
484
  /**
@@ -511,7 +648,7 @@ interface SSOOptions {
511
648
  */
512
649
  maxResponseSize?: number;
513
650
  /**
514
- * Maximum allowed size for IdP metadata XML in bytes.
651
+ * Maximum allowed size for IdP or SP metadata XML in bytes.
515
652
  *
516
653
  * @default 102400 (100KB)
517
654
  */
@@ -536,11 +673,16 @@ interface SSOOptions {
536
673
  * @default false
537
674
  */
538
675
  wantLogoutResponseSigned?: boolean;
676
+ /**
677
+ * Global fallback absolute URL or same-origin relative path for
678
+ * IdP-initiated SAML responses when the provider has no safe callback.
679
+ */
680
+ idpInitiatedCallbackUrl?: string | undefined;
539
681
  };
540
682
  }
541
683
  //#endregion
542
684
  //#region src/routes/domain-verification.d.ts
543
- declare const requestDomainVerification: (options: SSOOptions) => better_call0.StrictEndpoint<"/sso/request-domain-verification", {
685
+ declare const requestDomainVerification: (options: SSOOptions) => import("better-call").StrictEndpoint<"/sso/request-domain-verification", {
544
686
  method: "POST";
545
687
  body: z.ZodObject<{
546
688
  providerId: z.ZodString;
@@ -562,7 +704,7 @@ declare const requestDomainVerification: (options: SSOOptions) => better_call0.S
562
704
  };
563
705
  };
564
706
  };
565
- use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
707
+ use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
566
708
  session: {
567
709
  session: Record<string, any> & {
568
710
  id: string;
@@ -588,7 +730,7 @@ declare const requestDomainVerification: (options: SSOOptions) => better_call0.S
588
730
  }, {
589
731
  domainVerificationToken: string;
590
732
  }>;
591
- declare const verifyDomain: (options: SSOOptions) => better_call0.StrictEndpoint<"/sso/verify-domain", {
733
+ declare const verifyDomain: (options: SSOOptions) => import("better-call").StrictEndpoint<"/sso/verify-domain", {
592
734
  method: "POST";
593
735
  body: z.ZodObject<{
594
736
  providerId: z.ZodString;
@@ -613,7 +755,7 @@ declare const verifyDomain: (options: SSOOptions) => better_call0.StrictEndpoint
613
755
  };
614
756
  };
615
757
  };
616
- use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
758
+ use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
617
759
  session: {
618
760
  session: Record<string, any> & {
619
761
  id: string;
@@ -651,9 +793,9 @@ type ParsedCert = ReturnType<typeof parseCertificate>;
651
793
  type SanitizedCert = ParsedCert | {
652
794
  error: string;
653
795
  };
654
- declare const listSSOProviders: (options?: SSOOptions) => better_call0.StrictEndpoint<"/sso/providers", {
796
+ declare const listSSOProviders: (options?: SSOOptions) => import("better-call").StrictEndpoint<"/sso/providers", {
655
797
  method: "GET";
656
- use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
798
+ use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
657
799
  session: {
658
800
  session: Record<string, any> & {
659
801
  id: string;
@@ -709,6 +851,8 @@ declare const listSSOProviders: (options?: SSOOptions) => better_call0.StrictEnd
709
851
  } | undefined;
710
852
  samlConfig: {
711
853
  entryPoint: string;
854
+ callbackUrl: string | undefined;
855
+ idpInitiatedCallbackUrl: string | undefined;
712
856
  audience: string | undefined;
713
857
  wantAssertionsSigned: boolean | undefined;
714
858
  authnRequestsSigned: boolean | undefined;
@@ -720,9 +864,9 @@ declare const listSSOProviders: (options?: SSOOptions) => better_call0.StrictEnd
720
864
  spMetadataUrl: string;
721
865
  }[];
722
866
  }>;
723
- declare const getSSOProvider: (options?: SSOOptions) => better_call0.StrictEndpoint<"/sso/get-provider", {
867
+ declare const getSSOProvider: (options?: SSOOptions) => import("better-call").StrictEndpoint<"/sso/get-provider", {
724
868
  method: "GET";
725
- use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
869
+ use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
726
870
  session: {
727
871
  session: Record<string, any> & {
728
872
  id: string;
@@ -786,6 +930,8 @@ declare const getSSOProvider: (options?: SSOOptions) => better_call0.StrictEndpo
786
930
  } | undefined;
787
931
  samlConfig: {
788
932
  entryPoint: string;
933
+ callbackUrl: string | undefined;
934
+ idpInitiatedCallbackUrl: string | undefined;
789
935
  audience: string | undefined;
790
936
  wantAssertionsSigned: boolean | undefined;
791
937
  authnRequestsSigned: boolean | undefined;
@@ -796,9 +942,9 @@ declare const getSSOProvider: (options?: SSOOptions) => better_call0.StrictEndpo
796
942
  } | undefined;
797
943
  spMetadataUrl: string;
798
944
  }>;
799
- declare const updateSSOProvider: (options: SSOOptions) => better_call0.StrictEndpoint<"/sso/update-provider", {
945
+ declare const updateSSOProvider: (options: SSOOptions) => import("better-call").StrictEndpoint<"/sso/update-provider", {
800
946
  method: "POST";
801
- use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
947
+ use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
802
948
  session: {
803
949
  session: Record<string, any> & {
804
950
  id: string;
@@ -844,22 +990,44 @@ declare const updateSSOProvider: (options: SSOOptions) => better_call0.StrictEnd
844
990
  pkce: z.ZodOptional<z.ZodOptional<z.ZodDefault<z.ZodBoolean>>>;
845
991
  overrideUserInfo: z.ZodOptional<z.ZodOptional<z.ZodBoolean>>;
846
992
  mapping: z.ZodOptional<z.ZodOptional<z.ZodObject<{
847
- id: z.ZodString;
848
993
  email: z.ZodString;
849
994
  emailVerified: z.ZodOptional<z.ZodString>;
850
995
  name: z.ZodString;
851
996
  image: z.ZodOptional<z.ZodString>;
852
997
  extraFields: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
853
- }, z.core.$strip>>>;
998
+ }, z.core.$strict>>>;
854
999
  }, z.core.$strip>>;
855
1000
  samlConfig: z.ZodOptional<z.ZodObject<{
856
- entryPoint: z.ZodOptional<z.ZodString>;
857
- cert: z.ZodOptional<z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>>;
858
1001
  audience: z.ZodOptional<z.ZodOptional<z.ZodString>>;
859
- callbackUrl: z.ZodOptional<z.ZodOptional<z.ZodString>>;
860
- idpMetadata: z.ZodOptional<z.ZodOptional<z.ZodObject<{
1002
+ mapping: z.ZodOptional<z.ZodOptional<z.ZodObject<{
1003
+ email: z.ZodString;
1004
+ emailVerified: z.ZodOptional<z.ZodString>;
1005
+ name: z.ZodString;
1006
+ firstName: z.ZodOptional<z.ZodString>;
1007
+ lastName: z.ZodOptional<z.ZodString>;
1008
+ extraFields: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
1009
+ }, z.core.$strict>>>;
1010
+ privateKey: z.ZodOptional<z.ZodOptional<z.ZodString>>;
1011
+ spMetadata: z.ZodOptional<z.ZodOptional<z.ZodObject<{
861
1012
  metadata: z.ZodOptional<z.ZodString>;
862
1013
  entityID: z.ZodOptional<z.ZodString>;
1014
+ binding: z.ZodOptional<z.ZodString>;
1015
+ privateKey: z.ZodOptional<z.ZodString>;
1016
+ privateKeyPass: z.ZodOptional<z.ZodString>;
1017
+ isAssertionEncrypted: z.ZodOptional<z.ZodBoolean>;
1018
+ encPrivateKey: z.ZodOptional<z.ZodString>;
1019
+ encPrivateKeyPass: z.ZodOptional<z.ZodString>;
1020
+ }, z.core.$strip>>>;
1021
+ cert: z.ZodOptional<z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>>;
1022
+ entryPoint: z.ZodOptional<z.ZodString>;
1023
+ callbackUrl: z.ZodOptional<z.ZodOptional<z.ZodString>>;
1024
+ wantAssertionsSigned: z.ZodOptional<z.ZodOptional<z.ZodBoolean>>;
1025
+ authnRequestsSigned: z.ZodOptional<z.ZodOptional<z.ZodBoolean>>;
1026
+ signatureAlgorithm: z.ZodOptional<z.ZodOptional<z.ZodString>>;
1027
+ digestAlgorithm: z.ZodOptional<z.ZodOptional<z.ZodString>>;
1028
+ identifierFormat: z.ZodOptional<z.ZodOptional<z.ZodString>>;
1029
+ idpInitiatedCallbackUrl: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1030
+ idpMetadata: z.ZodOptional<z.ZodObject<{
863
1031
  cert: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
864
1032
  privateKey: z.ZodOptional<z.ZodString>;
865
1033
  privateKeyPass: z.ZodOptional<z.ZodString>;
@@ -874,32 +1042,9 @@ declare const updateSSOProvider: (options: SSOOptions) => better_call0.StrictEnd
874
1042
  Binding: z.ZodString;
875
1043
  Location: z.ZodString;
876
1044
  }, z.core.$strip>>>;
877
- }, z.core.$strip>>>;
878
- spMetadata: z.ZodOptional<z.ZodOptional<z.ZodObject<{
879
1045
  metadata: z.ZodOptional<z.ZodString>;
880
1046
  entityID: z.ZodOptional<z.ZodString>;
881
- binding: z.ZodOptional<z.ZodString>;
882
- privateKey: z.ZodOptional<z.ZodString>;
883
- privateKeyPass: z.ZodOptional<z.ZodString>;
884
- isAssertionEncrypted: z.ZodOptional<z.ZodBoolean>;
885
- encPrivateKey: z.ZodOptional<z.ZodString>;
886
- encPrivateKeyPass: z.ZodOptional<z.ZodString>;
887
- }, z.core.$strip>>>;
888
- wantAssertionsSigned: z.ZodOptional<z.ZodOptional<z.ZodBoolean>>;
889
- authnRequestsSigned: z.ZodOptional<z.ZodOptional<z.ZodBoolean>>;
890
- signatureAlgorithm: z.ZodOptional<z.ZodOptional<z.ZodString>>;
891
- digestAlgorithm: z.ZodOptional<z.ZodOptional<z.ZodString>>;
892
- identifierFormat: z.ZodOptional<z.ZodOptional<z.ZodString>>;
893
- privateKey: z.ZodOptional<z.ZodOptional<z.ZodString>>;
894
- mapping: z.ZodOptional<z.ZodOptional<z.ZodObject<{
895
- id: z.ZodString;
896
- email: z.ZodString;
897
- emailVerified: z.ZodOptional<z.ZodString>;
898
- name: z.ZodString;
899
- firstName: z.ZodOptional<z.ZodString>;
900
- lastName: z.ZodOptional<z.ZodString>;
901
- extraFields: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
902
- }, z.core.$strip>>>;
1047
+ }, z.core.$strip>>;
903
1048
  }, z.core.$strip>>;
904
1049
  providerId: z.ZodString;
905
1050
  }, z.core.$strip>;
@@ -941,6 +1086,8 @@ declare const updateSSOProvider: (options: SSOOptions) => better_call0.StrictEnd
941
1086
  } | undefined;
942
1087
  samlConfig: {
943
1088
  entryPoint: string;
1089
+ callbackUrl: string | undefined;
1090
+ idpInitiatedCallbackUrl: string | undefined;
944
1091
  audience: string | undefined;
945
1092
  wantAssertionsSigned: boolean | undefined;
946
1093
  authnRequestsSigned: boolean | undefined;
@@ -951,9 +1098,9 @@ declare const updateSSOProvider: (options: SSOOptions) => better_call0.StrictEnd
951
1098
  } | undefined;
952
1099
  spMetadataUrl: string;
953
1100
  }>;
954
- declare const deleteSSOProvider: () => better_call0.StrictEndpoint<"/sso/delete-provider", {
1101
+ declare const deleteSSOProvider: (options?: SSOOptions) => import("better-call").StrictEndpoint<"/sso/delete-provider", {
955
1102
  method: "POST";
956
- use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
1103
+ use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
957
1104
  session: {
958
1105
  session: Record<string, any> & {
959
1106
  id: string;
@@ -1002,7 +1149,7 @@ declare const deleteSSOProvider: () => better_call0.StrictEndpoint<"/sso/delete-
1002
1149
  }>;
1003
1150
  //#endregion
1004
1151
  //#region src/routes/sso.d.ts
1005
- declare const spMetadata: (options?: SSOOptions) => better_call0.StrictEndpoint<"/sso/saml2/sp/metadata", {
1152
+ declare const spMetadata: (options?: SSOOptions) => import("better-call").StrictEndpoint<"/sso/saml2/sp/metadata", {
1006
1153
  method: "GET";
1007
1154
  query: z.ZodObject<{
1008
1155
  providerId: z.ZodString;
@@ -1020,12 +1167,12 @@ declare const spMetadata: (options?: SSOOptions) => better_call0.StrictEndpoint<
1020
1167
  };
1021
1168
  };
1022
1169
  }, Response>;
1023
- declare const registerSSOProvider: <O extends SSOOptions>(options: O) => better_call0.StrictEndpoint<"/sso/register", {
1170
+ declare const registerSSOProvider: <O extends SSOOptions>(options: O) => import("better-call").StrictEndpoint<"/sso/register", {
1024
1171
  method: "POST";
1025
1172
  body: z.ZodObject<{
1026
1173
  [x: string]: z.ZodOptional<z.ZodAny>;
1027
1174
  }, z.core.$strip>;
1028
- use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
1175
+ use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
1029
1176
  session: {
1030
1177
  session: Record<string, any> & {
1031
1178
  id: string;
@@ -1148,10 +1295,6 @@ declare const registerSSOProvider: <O extends SSOOptions>(options: O) => better_
1148
1295
  type: string;
1149
1296
  nullable: boolean;
1150
1297
  properties: {
1151
- id: {
1152
- type: string;
1153
- description: string;
1154
- };
1155
1298
  email: {
1156
1299
  type: string;
1157
1300
  description: string;
@@ -1218,15 +1361,15 @@ declare const registerSSOProvider: <O extends SSOOptions>(options: O) => better_
1218
1361
  redirectURI: string;
1219
1362
  oidcConfig: OIDCConfig | null;
1220
1363
  samlConfig: SAMLConfig | null;
1221
- } & Omit<InferSSOProvider<O>, "oidcConfig" | "samlConfig"> & {
1364
+ } & Omit<InferSSOProvider<O>, "samlConfig" | "oidcConfig"> & {
1222
1365
  domainVerified: boolean;
1223
1366
  domainVerificationToken: string;
1224
1367
  } : {
1225
1368
  redirectURI: string;
1226
1369
  oidcConfig: OIDCConfig | null;
1227
1370
  samlConfig: SAMLConfig | null;
1228
- } & Omit<InferSSOProvider<O>, "oidcConfig" | "samlConfig">>;
1229
- declare const signInSSO: (options?: SSOOptions) => better_call0.StrictEndpoint<"/sign-in/sso", {
1371
+ } & Omit<InferSSOProvider<O>, "samlConfig" | "oidcConfig">>;
1372
+ declare const signInSSO: (options?: SSOOptions) => import("better-call").StrictEndpoint<"/sign-in/sso", {
1230
1373
  method: "POST";
1231
1374
  body: z.ZodObject<{
1232
1375
  email: z.ZodOptional<z.ZodString>;
@@ -1348,7 +1491,7 @@ declare const signInSSO: (options?: SSOOptions) => better_call0.StrictEndpoint<"
1348
1491
  url: string;
1349
1492
  redirect: boolean;
1350
1493
  }>;
1351
- declare const callbackSSO: (options?: SSOOptions) => better_call0.StrictEndpoint<"/sso/callback/:providerId", {
1494
+ declare const callbackSSO: (options?: SSOOptions) => import("better-call").StrictEndpoint<"/sso/callback/:providerId", {
1352
1495
  method: "GET";
1353
1496
  query: z.ZodObject<{
1354
1497
  code: z.ZodOptional<z.ZodString>;
@@ -1376,7 +1519,7 @@ declare const callbackSSO: (options?: SSOOptions) => better_call0.StrictEndpoint
1376
1519
  * Used when `options.redirectURI` is set — the `providerId` is read from
1377
1520
  * the OAuth state instead of the URL path.
1378
1521
  */
1379
- declare const callbackSSOShared: (options?: SSOOptions) => better_call0.StrictEndpoint<"/sso/callback", {
1522
+ declare const callbackSSOShared: (options?: SSOOptions) => import("better-call").StrictEndpoint<"/sso/callback", {
1380
1523
  metadata: {
1381
1524
  openapi: {
1382
1525
  operationId: string;
@@ -1399,7 +1542,7 @@ declare const callbackSSOShared: (options?: SSOOptions) => better_call0.StrictEn
1399
1542
  }, z.core.$strip>;
1400
1543
  allowedMediaTypes: readonly ["application/x-www-form-urlencoded", "application/json"];
1401
1544
  }, void>;
1402
- declare const acsEndpoint: (options?: SSOOptions) => better_call0.StrictEndpoint<"/sso/saml2/sp/acs/:providerId", {
1545
+ declare const acsEndpoint: (options?: SSOOptions) => import("better-call").StrictEndpoint<"/sso/saml2/sp/acs/:providerId", {
1403
1546
  method: ("GET" | "POST")[];
1404
1547
  body: z.ZodOptional<z.ZodObject<{
1405
1548
  SAMLResponse: z.ZodString;
@@ -1429,7 +1572,7 @@ declare const acsEndpoint: (options?: SSOOptions) => better_call0.StrictEndpoint
1429
1572
  scope: "server";
1430
1573
  };
1431
1574
  }, never>;
1432
- declare const sloEndpoint: (options?: SSOOptions) => better_call0.StrictEndpoint<"/sso/saml2/sp/slo/:providerId", {
1575
+ declare const sloEndpoint: (options?: SSOOptions) => import("better-call").StrictEndpoint<"/sso/saml2/sp/slo/:providerId", {
1433
1576
  method: ("GET" | "POST")[];
1434
1577
  body: z.ZodOptional<z.ZodObject<{
1435
1578
  SAMLRequest: z.ZodOptional<z.ZodString>;
@@ -1450,12 +1593,12 @@ declare const sloEndpoint: (options?: SSOOptions) => better_call0.StrictEndpoint
1450
1593
  scope: "server";
1451
1594
  };
1452
1595
  }, void | Response>;
1453
- declare const initiateSLO: (options?: SSOOptions) => better_call0.StrictEndpoint<"/sso/saml2/logout/:providerId", {
1596
+ declare const initiateSLO: (options?: SSOOptions) => import("better-call").StrictEndpoint<"/sso/saml2/logout/:providerId", {
1454
1597
  method: "POST";
1455
1598
  body: z.ZodObject<{
1456
1599
  callbackURL: z.ZodOptional<z.ZodString>;
1457
1600
  }, z.core.$strip>;
1458
- use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
1601
+ use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
1459
1602
  session: {
1460
1603
  session: Record<string, any> & {
1461
1604
  id: string;
@@ -1505,6 +1648,25 @@ declare const DEFAULT_MAX_SAML_RESPONSE_SIZE: number;
1505
1648
  */
1506
1649
  declare const DEFAULT_MAX_SAML_METADATA_SIZE: number;
1507
1650
  //#endregion
1651
+ //#region src/routes/helpers.d.ts
1652
+ interface SAMLServiceProviderPolicy {
1653
+ /** Effective assertion-signing requirement advertised by SP metadata. */
1654
+ wantAssertionsSigned: boolean;
1655
+ }
1656
+ /**
1657
+ * Parses custom SP metadata and returns its effective verification policy.
1658
+ *
1659
+ * Configurations without custom metadata use the code-defined policy directly.
1660
+ * Invalid or unusable custom metadata throws an API error with the
1661
+ * `SAML_INVALID_SP_METADATA` code.
1662
+ */
1663
+ declare function deriveSAMLServiceProviderPolicy(config: Pick<SAMLConfig, "spMetadata" | "wantAssertionsSigned">): SAMLServiceProviderPolicy;
1664
+ /**
1665
+ * Derive the verified SAML identity-provider entity ID using the same metadata
1666
+ * parsing and manual-configuration validation as SAML authentication.
1667
+ */
1668
+ declare function deriveSAMLIdentityProviderEntityID(config: SAMLConfig): string;
1669
+ //#endregion
1508
1670
  //#region src/saml/timestamp.d.ts
1509
1671
  interface TimestampValidationOptions {
1510
1672
  clockSkew?: number;
@@ -1600,7 +1762,29 @@ interface OIDCDiscoveryDocument {
1600
1762
  /**
1601
1763
  * Error codes for OIDC discovery operations.
1602
1764
  */
1603
- type DiscoveryErrorCode = /** Request to discovery endpoint timed out */"discovery_timeout" /** Discovery endpoint returned 404 or similar */ | "discovery_not_found" /** Discovery endpoint returned invalid JSON */ | "discovery_invalid_json" /** OIDC endpoint URL (discovery or per-endpoint: authorization, token, userinfo, jwks) is invalid, malformed, or uses a non-`http(s)` scheme */ | "discovery_invalid_url" /** OIDC endpoint URL is not trusted by the trusted origins configuration */ | "discovery_untrusted_origin" /** OIDC endpoint URL (discovery or per-endpoint) points to a host that is not publicly routable (loopback, RFC 1918, link-local, cloud metadata FQDN, etc.) */ | "discovery_private_host" /** Server-side OIDC endpoint fetch received an HTTP redirect response */ | "oidc_endpoint_redirect" /** Discovery document issuer doesn't match configured issuer */ | "issuer_mismatch" /** Discovery document is missing required fields */ | "discovery_incomplete" /** IdP only advertises token auth methods that Better Auth doesn't currently support */ | "unsupported_token_auth_method" /** Catch-all for unexpected errors */ | "discovery_unexpected_error";
1765
+ type DiscoveryErrorCode =
1766
+ /** Request to discovery endpoint timed out */
1767
+ "discovery_timeout" |
1768
+ /** Discovery endpoint returned 404 or similar */
1769
+ "discovery_not_found" |
1770
+ /** Discovery endpoint returned invalid JSON */
1771
+ "discovery_invalid_json" |
1772
+ /** OIDC endpoint URL (discovery or per-endpoint: authorization, token, userinfo, jwks) is invalid, malformed, or uses a non-`http(s)` scheme */
1773
+ "discovery_invalid_url" |
1774
+ /** OIDC endpoint URL is not trusted by the trusted origins configuration */
1775
+ "discovery_untrusted_origin" |
1776
+ /** OIDC endpoint URL (discovery or per-endpoint) points to a host that is not publicly routable (loopback, RFC 1918, link-local, cloud metadata FQDN, etc.) */
1777
+ "discovery_private_host" |
1778
+ /** Server-side OIDC endpoint fetch received an HTTP redirect response */
1779
+ "oidc_endpoint_redirect" |
1780
+ /** Discovery document issuer doesn't match configured issuer */
1781
+ "issuer_mismatch" |
1782
+ /** Discovery document is missing required fields */
1783
+ "discovery_incomplete" |
1784
+ /** IdP only advertises token auth methods that Better Auth doesn't currently support */
1785
+ "unsupported_token_auth_method" |
1786
+ /** Catch-all for unexpected errors */
1787
+ "discovery_unexpected_error";
1604
1788
  /**
1605
1789
  * Custom error class for OIDC discovery failures.
1606
1790
  * Can be caught and mapped to APIError at the edge.
@@ -1837,4 +2021,4 @@ declare function sso<O extends SSOOptions>(options?: O | undefined): {
1837
2021
  options: NoInfer<O>;
1838
2022
  };
1839
2023
  //#endregion
1840
- export { DataEncryptionAlgorithm as A, DEFAULT_MAX_SAML_METADATA_SIZE as C, SSOOptions as D, SAMLConfig as E, DigestAlgorithm as M, KeyEncryptionAlgorithm as N, SSOProvider as O, SignatureAlgorithm as P, DEFAULT_CLOCK_SKEW_MS as S, OIDCConfig as T, REQUIRED_DISCOVERY_FIELDS as _, fetchDiscoveryDocument as a, TimestampValidationOptions as b, normalizeUrl as c, validateDiscoveryUrl as d, DiscoverOIDCConfigParams as f, OIDCDiscoveryDocument as g, HydratedOIDCConfig as h, discoverOIDCConfig as i, DeprecatedAlgorithmBehavior as j, AlgorithmValidationOptions 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, DEFAULT_MAX_SAML_RESPONSE_SIZE as w, validateSAMLTimestamp as x, SAMLConditions as y };
2024
+ export { SAMLIdentityProviderMetadata as A, SSOUserResolutionContext as B, deriveSAMLIdentityProviderEntityID as C, DEFAULT_MAX_SAML_RESPONSE_SIZE as D, DEFAULT_MAX_SAML_METADATA_SIZE as E, SSOProviderMutationGuardInput as F, DigestAlgorithm as G, AlgorithmValidationOptions as H, SSOProviderReference as I, KeyEncryptionAlgorithm as K, SSOProviderUserProfile as L, SSOOptions as M, SSOProvider as N, OIDCConfig as O, SSOProviderMutationGuardContext as P, SSOSAMLUserResolutionInput as R, SAMLServiceProviderPolicy as S, DEFAULT_CLOCK_SKEW_MS as T, DataEncryptionAlgorithm as U, SSOUserResolutionInput as V, DeprecatedAlgorithmBehavior as W, REQUIRED_DISCOVERY_FIELDS as _, fetchDiscoveryDocument as a, TimestampValidationOptions as b, normalizeUrl as c, validateDiscoveryUrl as d, DiscoverOIDCConfigParams as f, OIDCDiscoveryDocument as g, HydratedOIDCConfig as h, discoverOIDCConfig as i, SSOOIDCUserResolutionInput as j, SAMLConfig as k, selectTokenEndpointAuthMethod as l, DiscoveryErrorCode as m, sso as n, needsRuntimeDiscovery as o, DiscoveryError as p, SignatureAlgorithm as q, computeDiscoveryUrl as r, normalizeDiscoveryUrls as s, SSOPlugin as t, validateDiscoveryDocument as u, RequiredDiscoveryField as v, deriveSAMLServiceProviderPolicy as w, validateSAMLTimestamp as x, SAMLConditions as y, SSOUserResolution as z };
package/dist/index.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { A as DataEncryptionAlgorithm, C as DEFAULT_MAX_SAML_METADATA_SIZE, D as SSOOptions, E as SAMLConfig, M as DigestAlgorithm, N as KeyEncryptionAlgorithm, O as SSOProvider, P as SignatureAlgorithm, S as DEFAULT_CLOCK_SKEW_MS, T as OIDCConfig, _ as REQUIRED_DISCOVERY_FIELDS, a as fetchDiscoveryDocument, b as TimestampValidationOptions, c as normalizeUrl, d as validateDiscoveryUrl, f as DiscoverOIDCConfigParams, g as OIDCDiscoveryDocument, h as HydratedOIDCConfig, i as discoverOIDCConfig, j as DeprecatedAlgorithmBehavior, k as AlgorithmValidationOptions, 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 DEFAULT_MAX_SAML_RESPONSE_SIZE, x as validateSAMLTimestamp, y as SAMLConditions } from "./index-A_DJ_AqL.mjs";
2
- export { AlgorithmValidationOptions, DEFAULT_CLOCK_SKEW_MS, DEFAULT_MAX_SAML_METADATA_SIZE, DEFAULT_MAX_SAML_RESPONSE_SIZE, DataEncryptionAlgorithm, DeprecatedAlgorithmBehavior, DigestAlgorithm, DiscoverOIDCConfigParams, DiscoveryError, DiscoveryErrorCode, HydratedOIDCConfig, KeyEncryptionAlgorithm, OIDCConfig, OIDCDiscoveryDocument, REQUIRED_DISCOVERY_FIELDS, RequiredDiscoveryField, SAMLConditions, SAMLConfig, SSOOptions, SSOPlugin, SSOProvider, SignatureAlgorithm, TimestampValidationOptions, computeDiscoveryUrl, discoverOIDCConfig, fetchDiscoveryDocument, needsRuntimeDiscovery, normalizeDiscoveryUrls, normalizeUrl, selectTokenEndpointAuthMethod, sso, validateDiscoveryDocument, validateDiscoveryUrl, validateSAMLTimestamp };
1
+ import { A as SAMLIdentityProviderMetadata, B as SSOUserResolutionContext, C as deriveSAMLIdentityProviderEntityID, D as DEFAULT_MAX_SAML_RESPONSE_SIZE, E as DEFAULT_MAX_SAML_METADATA_SIZE, F as SSOProviderMutationGuardInput, G as DigestAlgorithm, H as AlgorithmValidationOptions, I as SSOProviderReference, K as KeyEncryptionAlgorithm, L as SSOProviderUserProfile, M as SSOOptions, N as SSOProvider, O as OIDCConfig, P as SSOProviderMutationGuardContext, R as SSOSAMLUserResolutionInput, S as SAMLServiceProviderPolicy, T as DEFAULT_CLOCK_SKEW_MS, U as DataEncryptionAlgorithm, V as SSOUserResolutionInput, W as DeprecatedAlgorithmBehavior, _ as REQUIRED_DISCOVERY_FIELDS, a as fetchDiscoveryDocument, b as TimestampValidationOptions, c as normalizeUrl, d as validateDiscoveryUrl, f as DiscoverOIDCConfigParams, g as OIDCDiscoveryDocument, h as HydratedOIDCConfig, i as discoverOIDCConfig, j as SSOOIDCUserResolutionInput, k as SAMLConfig, l as selectTokenEndpointAuthMethod, m as DiscoveryErrorCode, n as sso, o as needsRuntimeDiscovery, p as DiscoveryError, q as SignatureAlgorithm, r as computeDiscoveryUrl, s as normalizeDiscoveryUrls, t as SSOPlugin, u as validateDiscoveryDocument, v as RequiredDiscoveryField, w as deriveSAMLServiceProviderPolicy, x as validateSAMLTimestamp, y as SAMLConditions, z as SSOUserResolution } from "./index-Sxfa9KQp.mjs";
2
+ export { type AlgorithmValidationOptions, DEFAULT_CLOCK_SKEW_MS, DEFAULT_MAX_SAML_METADATA_SIZE, DEFAULT_MAX_SAML_RESPONSE_SIZE, DataEncryptionAlgorithm, type DeprecatedAlgorithmBehavior, DigestAlgorithm, type DiscoverOIDCConfigParams, DiscoveryError, type DiscoveryErrorCode, type HydratedOIDCConfig, KeyEncryptionAlgorithm, type OIDCConfig, type OIDCDiscoveryDocument, REQUIRED_DISCOVERY_FIELDS, type RequiredDiscoveryField, type SAMLConditions, type SAMLConfig, type SAMLIdentityProviderMetadata, type SAMLServiceProviderPolicy, type SSOOIDCUserResolutionInput, type SSOOptions, SSOPlugin, type SSOProvider, type SSOProviderMutationGuardContext, type SSOProviderMutationGuardInput, type SSOProviderReference, type SSOProviderUserProfile, type SSOSAMLUserResolutionInput, type SSOUserResolution, type SSOUserResolutionContext, type SSOUserResolutionInput, SignatureAlgorithm, type TimestampValidationOptions, computeDiscoveryUrl, deriveSAMLIdentityProviderEntityID, deriveSAMLServiceProviderPolicy, discoverOIDCConfig, fetchDiscoveryDocument, needsRuntimeDiscovery, normalizeDiscoveryUrls, normalizeUrl, selectTokenEndpointAuthMethod, sso, validateDiscoveryDocument, validateDiscoveryUrl, validateSAMLTimestamp };