@better-auth/sso 1.6.26 → 1.6.28
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
package/dist/client.mjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { APIError } from "better-auth/api";
|
|
2
2
|
import * as z from "zod";
|
|
3
3
|
import { Awaitable, BetterAuthPlugin, OAuth2Tokens, User } from "better-auth";
|
|
4
|
+
import * as _$better_call0 from "better-call";
|
|
5
|
+
|
|
4
6
|
//#region src/saml/algorithms.d.ts
|
|
5
7
|
declare const SignatureAlgorithm: {
|
|
6
8
|
readonly RSA_SHA1: "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
|
|
@@ -435,7 +437,7 @@ interface SSOOptions {
|
|
|
435
437
|
}
|
|
436
438
|
//#endregion
|
|
437
439
|
//#region src/routes/domain-verification.d.ts
|
|
438
|
-
declare const requestDomainVerification: (options: SSOOptions) =>
|
|
440
|
+
declare const requestDomainVerification: (options: SSOOptions) => _$better_call0.StrictEndpoint<"/sso/request-domain-verification", {
|
|
439
441
|
method: "POST";
|
|
440
442
|
body: z.ZodObject<{
|
|
441
443
|
providerId: z.ZodString;
|
|
@@ -457,7 +459,7 @@ declare const requestDomainVerification: (options: SSOOptions) => import("better
|
|
|
457
459
|
};
|
|
458
460
|
};
|
|
459
461
|
};
|
|
460
|
-
use: (
|
|
462
|
+
use: _$better_call0.Middleware<_$better_call0.MiddlewareOptions, (inputContext: _$better_call0.MiddlewareInputContext<_$better_call0.MiddlewareOptions>) => Promise<{
|
|
461
463
|
session: {
|
|
462
464
|
session: Record<string, any> & {
|
|
463
465
|
id: string;
|
|
@@ -479,11 +481,11 @@ declare const requestDomainVerification: (options: SSOOptions) => import("better
|
|
|
479
481
|
image?: string | null | undefined;
|
|
480
482
|
};
|
|
481
483
|
};
|
|
482
|
-
}
|
|
484
|
+
}>>[];
|
|
483
485
|
}, {
|
|
484
486
|
domainVerificationToken: string;
|
|
485
487
|
}>;
|
|
486
|
-
declare const verifyDomain: (options: SSOOptions) =>
|
|
488
|
+
declare const verifyDomain: (options: SSOOptions) => _$better_call0.StrictEndpoint<"/sso/verify-domain", {
|
|
487
489
|
method: "POST";
|
|
488
490
|
body: z.ZodObject<{
|
|
489
491
|
providerId: z.ZodString;
|
|
@@ -508,7 +510,7 @@ declare const verifyDomain: (options: SSOOptions) => import("better-call").Stric
|
|
|
508
510
|
};
|
|
509
511
|
};
|
|
510
512
|
};
|
|
511
|
-
use: (
|
|
513
|
+
use: _$better_call0.Middleware<_$better_call0.MiddlewareOptions, (inputContext: _$better_call0.MiddlewareInputContext<_$better_call0.MiddlewareOptions>) => Promise<{
|
|
512
514
|
session: {
|
|
513
515
|
session: Record<string, any> & {
|
|
514
516
|
id: string;
|
|
@@ -530,13 +532,13 @@ declare const verifyDomain: (options: SSOOptions) => import("better-call").Stric
|
|
|
530
532
|
image?: string | null | undefined;
|
|
531
533
|
};
|
|
532
534
|
};
|
|
533
|
-
}
|
|
535
|
+
}>>[];
|
|
534
536
|
}, void>;
|
|
535
537
|
//#endregion
|
|
536
538
|
//#region src/routes/providers.d.ts
|
|
537
|
-
declare const listSSOProviders: () =>
|
|
539
|
+
declare const listSSOProviders: () => _$better_call0.StrictEndpoint<"/sso/providers", {
|
|
538
540
|
method: "GET";
|
|
539
|
-
use: (
|
|
541
|
+
use: _$better_call0.Middleware<_$better_call0.MiddlewareOptions, (inputContext: _$better_call0.MiddlewareInputContext<_$better_call0.MiddlewareOptions>) => Promise<{
|
|
540
542
|
session: {
|
|
541
543
|
session: Record<string, any> & {
|
|
542
544
|
id: string;
|
|
@@ -558,7 +560,7 @@ declare const listSSOProviders: () => import("better-call").StrictEndpoint<"/sso
|
|
|
558
560
|
image?: string | null | undefined;
|
|
559
561
|
};
|
|
560
562
|
};
|
|
561
|
-
}
|
|
563
|
+
}>>[];
|
|
562
564
|
metadata: {
|
|
563
565
|
openapi: {
|
|
564
566
|
operationId: string;
|
|
@@ -612,9 +614,9 @@ declare const listSSOProviders: () => import("better-call").StrictEndpoint<"/sso
|
|
|
612
614
|
spMetadataUrl: string;
|
|
613
615
|
}[];
|
|
614
616
|
}>;
|
|
615
|
-
declare const getSSOProvider: () =>
|
|
617
|
+
declare const getSSOProvider: () => _$better_call0.StrictEndpoint<"/sso/get-provider", {
|
|
616
618
|
method: "GET";
|
|
617
|
-
use: (
|
|
619
|
+
use: _$better_call0.Middleware<_$better_call0.MiddlewareOptions, (inputContext: _$better_call0.MiddlewareInputContext<_$better_call0.MiddlewareOptions>) => Promise<{
|
|
618
620
|
session: {
|
|
619
621
|
session: Record<string, any> & {
|
|
620
622
|
id: string;
|
|
@@ -636,7 +638,7 @@ declare const getSSOProvider: () => import("better-call").StrictEndpoint<"/sso/g
|
|
|
636
638
|
image?: string | null | undefined;
|
|
637
639
|
};
|
|
638
640
|
};
|
|
639
|
-
}
|
|
641
|
+
}>>[];
|
|
640
642
|
query: z.ZodObject<{
|
|
641
643
|
providerId: z.ZodString;
|
|
642
644
|
}, z.core.$strip>;
|
|
@@ -697,9 +699,9 @@ declare const getSSOProvider: () => import("better-call").StrictEndpoint<"/sso/g
|
|
|
697
699
|
} | undefined;
|
|
698
700
|
spMetadataUrl: string;
|
|
699
701
|
}>;
|
|
700
|
-
declare const updateSSOProvider: (options: SSOOptions) =>
|
|
702
|
+
declare const updateSSOProvider: (options: SSOOptions) => _$better_call0.StrictEndpoint<"/sso/update-provider", {
|
|
701
703
|
method: "POST";
|
|
702
|
-
use: (
|
|
704
|
+
use: _$better_call0.Middleware<_$better_call0.MiddlewareOptions, (inputContext: _$better_call0.MiddlewareInputContext<_$better_call0.MiddlewareOptions>) => Promise<{
|
|
703
705
|
session: {
|
|
704
706
|
session: Record<string, any> & {
|
|
705
707
|
id: string;
|
|
@@ -721,7 +723,7 @@ declare const updateSSOProvider: (options: SSOOptions) => import("better-call").
|
|
|
721
723
|
image?: string | null | undefined;
|
|
722
724
|
};
|
|
723
725
|
};
|
|
724
|
-
}
|
|
726
|
+
}>>[];
|
|
725
727
|
body: z.ZodObject<{
|
|
726
728
|
issuer: z.ZodOptional<z.ZodString>;
|
|
727
729
|
domain: z.ZodOptional<z.ZodString>;
|
|
@@ -856,9 +858,9 @@ declare const updateSSOProvider: (options: SSOOptions) => import("better-call").
|
|
|
856
858
|
} | undefined;
|
|
857
859
|
spMetadataUrl: string;
|
|
858
860
|
}>;
|
|
859
|
-
declare const deleteSSOProvider: () =>
|
|
861
|
+
declare const deleteSSOProvider: () => _$better_call0.StrictEndpoint<"/sso/delete-provider", {
|
|
860
862
|
method: "POST";
|
|
861
|
-
use: (
|
|
863
|
+
use: _$better_call0.Middleware<_$better_call0.MiddlewareOptions, (inputContext: _$better_call0.MiddlewareInputContext<_$better_call0.MiddlewareOptions>) => Promise<{
|
|
862
864
|
session: {
|
|
863
865
|
session: Record<string, any> & {
|
|
864
866
|
id: string;
|
|
@@ -880,7 +882,7 @@ declare const deleteSSOProvider: () => import("better-call").StrictEndpoint<"/ss
|
|
|
880
882
|
image?: string | null | undefined;
|
|
881
883
|
};
|
|
882
884
|
};
|
|
883
|
-
}
|
|
885
|
+
}>>[];
|
|
884
886
|
body: z.ZodObject<{
|
|
885
887
|
providerId: z.ZodString;
|
|
886
888
|
}, z.core.$strip>;
|
|
@@ -927,7 +929,7 @@ interface SAMLConditions {
|
|
|
927
929
|
declare function validateSAMLTimestamp(conditions: SAMLConditions | undefined, options?: TimestampValidationOptions): void;
|
|
928
930
|
//#endregion
|
|
929
931
|
//#region src/routes/sso.d.ts
|
|
930
|
-
declare const spMetadata: (options?: SSOOptions) =>
|
|
932
|
+
declare const spMetadata: (options?: SSOOptions) => _$better_call0.StrictEndpoint<"/sso/saml2/sp/metadata", {
|
|
931
933
|
method: "GET";
|
|
932
934
|
query: z.ZodObject<{
|
|
933
935
|
providerId: z.ZodString;
|
|
@@ -949,7 +951,7 @@ declare const spMetadata: (options?: SSOOptions) => import("better-call").Strict
|
|
|
949
951
|
};
|
|
950
952
|
};
|
|
951
953
|
}, Response>;
|
|
952
|
-
declare const registerSSOProvider: <O extends SSOOptions>(options: O) =>
|
|
954
|
+
declare const registerSSOProvider: <O extends SSOOptions>(options: O) => _$better_call0.StrictEndpoint<"/sso/register", {
|
|
953
955
|
method: "POST";
|
|
954
956
|
body: z.ZodObject<{
|
|
955
957
|
providerId: z.ZodString;
|
|
@@ -1030,7 +1032,7 @@ declare const registerSSOProvider: <O extends SSOOptions>(options: O) => import(
|
|
|
1030
1032
|
organizationId: z.ZodOptional<z.ZodString>;
|
|
1031
1033
|
overrideUserInfo: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
1032
1034
|
}, z.core.$strip>;
|
|
1033
|
-
use: (
|
|
1035
|
+
use: _$better_call0.Middleware<_$better_call0.MiddlewareOptions, (inputContext: _$better_call0.MiddlewareInputContext<_$better_call0.MiddlewareOptions>) => Promise<{
|
|
1034
1036
|
session: {
|
|
1035
1037
|
session: Record<string, any> & {
|
|
1036
1038
|
id: string;
|
|
@@ -1052,7 +1054,7 @@ declare const registerSSOProvider: <O extends SSOOptions>(options: O) => import(
|
|
|
1052
1054
|
image?: string | null | undefined;
|
|
1053
1055
|
};
|
|
1054
1056
|
};
|
|
1055
|
-
}
|
|
1057
|
+
}>>[];
|
|
1056
1058
|
metadata: {
|
|
1057
1059
|
openapi: {
|
|
1058
1060
|
operationId: string;
|
|
@@ -1228,7 +1230,7 @@ declare const registerSSOProvider: <O extends SSOOptions>(options: O) => import(
|
|
|
1228
1230
|
oidcConfig: OIDCConfig | null;
|
|
1229
1231
|
samlConfig: SAMLConfig | null;
|
|
1230
1232
|
} & Omit<SSOProvider<O>, "oidcConfig" | "samlConfig">>;
|
|
1231
|
-
declare const signInSSO: (options?: SSOOptions) =>
|
|
1233
|
+
declare const signInSSO: (options?: SSOOptions) => _$better_call0.StrictEndpoint<"/sign-in/sso", {
|
|
1232
1234
|
method: "POST";
|
|
1233
1235
|
body: z.ZodObject<{
|
|
1234
1236
|
email: z.ZodOptional<z.ZodString>;
|
|
@@ -1322,7 +1324,7 @@ declare const signInSSO: (options?: SSOOptions) => import("better-call").StrictE
|
|
|
1322
1324
|
url: string;
|
|
1323
1325
|
redirect: boolean;
|
|
1324
1326
|
}>;
|
|
1325
|
-
declare const callbackSSO: (options?: SSOOptions) =>
|
|
1327
|
+
declare const callbackSSO: (options?: SSOOptions) => _$better_call0.StrictEndpoint<"/sso/callback/:providerId", {
|
|
1326
1328
|
method: "GET";
|
|
1327
1329
|
query: z.ZodObject<{
|
|
1328
1330
|
code: z.ZodOptional<z.ZodString>;
|
|
@@ -1350,7 +1352,7 @@ declare const callbackSSO: (options?: SSOOptions) => import("better-call").Stric
|
|
|
1350
1352
|
* Used when `options.redirectURI` is set — the `providerId` is read from
|
|
1351
1353
|
* the OAuth state instead of the URL path.
|
|
1352
1354
|
*/
|
|
1353
|
-
declare const callbackSSOShared: (options?: SSOOptions) =>
|
|
1355
|
+
declare const callbackSSOShared: (options?: SSOOptions) => _$better_call0.StrictEndpoint<"/sso/callback", {
|
|
1354
1356
|
metadata: {
|
|
1355
1357
|
openapi: {
|
|
1356
1358
|
operationId: string;
|
|
@@ -1373,7 +1375,7 @@ declare const callbackSSOShared: (options?: SSOOptions) => import("better-call")
|
|
|
1373
1375
|
}, z.core.$strip>;
|
|
1374
1376
|
allowedMediaTypes: readonly ["application/x-www-form-urlencoded", "application/json"];
|
|
1375
1377
|
}, void>;
|
|
1376
|
-
declare const callbackSSOSAML: (options?: SSOOptions) =>
|
|
1378
|
+
declare const callbackSSOSAML: (options?: SSOOptions) => _$better_call0.StrictEndpoint<"/sso/saml2/callback/:providerId", {
|
|
1377
1379
|
method: ("GET" | "POST")[];
|
|
1378
1380
|
body: z.ZodOptional<z.ZodObject<{
|
|
1379
1381
|
SAMLResponse: z.ZodString;
|
|
@@ -1403,7 +1405,7 @@ declare const callbackSSOSAML: (options?: SSOOptions) => import("better-call").S
|
|
|
1403
1405
|
scope: "server";
|
|
1404
1406
|
};
|
|
1405
1407
|
}, never>;
|
|
1406
|
-
declare const acsEndpoint: (options?: SSOOptions) =>
|
|
1408
|
+
declare const acsEndpoint: (options?: SSOOptions) => _$better_call0.StrictEndpoint<"/sso/saml2/sp/acs/:providerId", {
|
|
1407
1409
|
method: "POST";
|
|
1408
1410
|
body: z.ZodObject<{
|
|
1409
1411
|
SAMLResponse: z.ZodString;
|
|
@@ -1424,7 +1426,7 @@ declare const acsEndpoint: (options?: SSOOptions) => import("better-call").Stric
|
|
|
1424
1426
|
scope: "server";
|
|
1425
1427
|
};
|
|
1426
1428
|
}, never>;
|
|
1427
|
-
declare const sloEndpoint: (options?: SSOOptions) =>
|
|
1429
|
+
declare const sloEndpoint: (options?: SSOOptions) => _$better_call0.StrictEndpoint<"/sso/saml2/sp/slo/:providerId", {
|
|
1428
1430
|
method: ("GET" | "POST")[];
|
|
1429
1431
|
body: z.ZodOptional<z.ZodObject<{
|
|
1430
1432
|
SAMLRequest: z.ZodOptional<z.ZodString>;
|
|
@@ -1445,12 +1447,12 @@ declare const sloEndpoint: (options?: SSOOptions) => import("better-call").Stric
|
|
|
1445
1447
|
scope: "server";
|
|
1446
1448
|
};
|
|
1447
1449
|
}, void | Response>;
|
|
1448
|
-
declare const initiateSLO: (options?: SSOOptions) =>
|
|
1450
|
+
declare const initiateSLO: (options?: SSOOptions) => _$better_call0.StrictEndpoint<"/sso/saml2/logout/:providerId", {
|
|
1449
1451
|
method: "POST";
|
|
1450
1452
|
body: z.ZodObject<{
|
|
1451
1453
|
callbackURL: z.ZodOptional<z.ZodString>;
|
|
1452
1454
|
}, z.core.$strip>;
|
|
1453
|
-
use: (
|
|
1455
|
+
use: _$better_call0.Middleware<_$better_call0.MiddlewareOptions, (inputContext: _$better_call0.MiddlewareInputContext<_$better_call0.MiddlewareOptions>) => Promise<{
|
|
1454
1456
|
session: {
|
|
1455
1457
|
session: Record<string, any> & {
|
|
1456
1458
|
id: string;
|
|
@@ -1472,7 +1474,7 @@ declare const initiateSLO: (options?: SSOOptions) => import("better-call").Stric
|
|
|
1472
1474
|
image?: string | null | undefined;
|
|
1473
1475
|
};
|
|
1474
1476
|
};
|
|
1475
|
-
}
|
|
1477
|
+
}>>[];
|
|
1476
1478
|
metadata: {
|
|
1477
1479
|
readonly scope: "server";
|
|
1478
1480
|
};
|
|
@@ -1575,27 +1577,7 @@ interface OIDCDiscoveryDocument {
|
|
|
1575
1577
|
/**
|
|
1576
1578
|
* Error codes for OIDC discovery operations.
|
|
1577
1579
|
*/
|
|
1578
|
-
type DiscoveryErrorCode =
|
|
1579
|
-
/** Request to discovery endpoint timed out */
|
|
1580
|
-
"discovery_timeout" |
|
|
1581
|
-
/** Discovery endpoint returned 404 or similar */
|
|
1582
|
-
"discovery_not_found" |
|
|
1583
|
-
/** Discovery endpoint returned invalid JSON */
|
|
1584
|
-
"discovery_invalid_json" |
|
|
1585
|
-
/** OIDC endpoint URL (discovery or per-endpoint: authorization, token, userinfo, jwks) is invalid, malformed, or uses a non-`http(s)` scheme */
|
|
1586
|
-
"discovery_invalid_url" |
|
|
1587
|
-
/** OIDC endpoint URL is not trusted by the trusted origins configuration */
|
|
1588
|
-
"discovery_untrusted_origin" |
|
|
1589
|
-
/** 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.) */
|
|
1590
|
-
"discovery_private_host" |
|
|
1591
|
-
/** Discovery document issuer doesn't match configured issuer */
|
|
1592
|
-
"issuer_mismatch" |
|
|
1593
|
-
/** Discovery document is missing required fields */
|
|
1594
|
-
"discovery_incomplete" |
|
|
1595
|
-
/** IdP only advertises token auth methods that Better Auth doesn't currently support */
|
|
1596
|
-
"unsupported_token_auth_method" |
|
|
1597
|
-
/** Catch-all for unexpected errors */
|
|
1598
|
-
"discovery_unexpected_error";
|
|
1580
|
+
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" /** 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";
|
|
1599
1581
|
/**
|
|
1600
1582
|
* Custom error class for OIDC discovery failures.
|
|
1601
1583
|
* Can be caught and mapped to APIError at the edge.
|
package/dist/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as DataEncryptionAlgorithm, C as TimestampValidationOptions, D as SSOOptions, E as SAMLConfig, M as DigestAlgorithm, N as KeyEncryptionAlgorithm, O as SSOProvider, P as SignatureAlgorithm, S as SAMLConditions, T as OIDCConfig, _ as REQUIRED_DISCOVERY_FIELDS, a as fetchDiscoveryDocument, b as DEFAULT_MAX_SAML_METADATA_SIZE, 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 validateSAMLTimestamp, x as DEFAULT_MAX_SAML_RESPONSE_SIZE, y as DEFAULT_CLOCK_SKEW_MS } from "./index-
|
|
2
|
-
export {
|
|
1
|
+
import { A as DataEncryptionAlgorithm, C as TimestampValidationOptions, D as SSOOptions, E as SAMLConfig, M as DigestAlgorithm, N as KeyEncryptionAlgorithm, O as SSOProvider, P as SignatureAlgorithm, S as SAMLConditions, T as OIDCConfig, _ as REQUIRED_DISCOVERY_FIELDS, a as fetchDiscoveryDocument, b as DEFAULT_MAX_SAML_METADATA_SIZE, 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 validateSAMLTimestamp, x as DEFAULT_MAX_SAML_RESPONSE_SIZE, y as DEFAULT_CLOCK_SKEW_MS } from "./index-CMcY1z4e.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 };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as PACKAGE_VERSION } from "./version-
|
|
1
|
+
import { t as PACKAGE_VERSION } from "./version-6ZHwEASO.mjs";
|
|
2
2
|
import { APIError, createAuthEndpoint, createAuthMiddleware, getSessionFromCtx, sessionMiddleware } from "better-auth/api";
|
|
3
3
|
import { XMLParser, XMLValidator } from "fast-xml-parser";
|
|
4
4
|
import { X509Certificate } from "node:crypto";
|
|
@@ -147,98 +147,127 @@ function maskClientId(clientId) {
|
|
|
147
147
|
}
|
|
148
148
|
//#endregion
|
|
149
149
|
//#region src/linking/org-assignment.ts
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
const
|
|
156
|
-
if (!
|
|
157
|
-
|
|
158
|
-
|
|
150
|
+
function getEmailDomain(email) {
|
|
151
|
+
const parts = email.trim().toLowerCase().split("@");
|
|
152
|
+
if (parts.length !== 2 || !parts[0] || !parts[1]) return null;
|
|
153
|
+
const domain = parts[1];
|
|
154
|
+
if (domain.includes("/") || domain.includes("\\") || domain.includes(":")) return null;
|
|
155
|
+
const normalizedDomains = parseProviderDomains(domain);
|
|
156
|
+
if (!normalizedDomains || normalizedDomains.length !== 1) return null;
|
|
157
|
+
return normalizedDomains[0] ?? null;
|
|
158
|
+
}
|
|
159
|
+
async function findVerifiedDomainProviders(ctx, domain) {
|
|
160
|
+
return (await ctx.context.adapter.findMany({
|
|
161
|
+
model: "ssoProvider",
|
|
162
|
+
where: [{
|
|
163
|
+
field: "domainVerified",
|
|
164
|
+
value: true
|
|
165
|
+
}]
|
|
166
|
+
})).filter((provider) => domainMatches(domain, provider.domain));
|
|
167
|
+
}
|
|
168
|
+
async function assignOrganization(ctx, options) {
|
|
169
|
+
if (options.provisioningOptions?.disabled) return "provisioning-disabled";
|
|
170
|
+
if (!ctx.context.hasPlugin("organization")) return "ineligible-source";
|
|
171
|
+
let user;
|
|
172
|
+
let provider;
|
|
173
|
+
let organizationId;
|
|
174
|
+
let userInfo;
|
|
175
|
+
let token;
|
|
176
|
+
if (options.reason === "provider-bound") {
|
|
177
|
+
if (!options.provider.organizationId) return "no-target";
|
|
178
|
+
user = options.user;
|
|
179
|
+
provider = options.provider;
|
|
180
|
+
organizationId = options.provider.organizationId;
|
|
181
|
+
userInfo = options.profile.rawAttributes || {};
|
|
182
|
+
token = options.token;
|
|
183
|
+
} else {
|
|
184
|
+
if (!options.domainVerification?.enabled) return "provisioning-disabled";
|
|
185
|
+
const canonicalUser = await ctx.context.internalAdapter.findUserById(options.user.id);
|
|
186
|
+
if (!canonicalUser) {
|
|
187
|
+
ctx.context.logger.error("Unable to assign SSO organization membership because the canonical user was not found", { userId: options.user.id });
|
|
188
|
+
return "ineligible-source";
|
|
189
|
+
}
|
|
190
|
+
if (!canonicalUser.emailVerified) return "unverified-identity";
|
|
191
|
+
const domain = getEmailDomain(canonicalUser.email);
|
|
192
|
+
if (!domain) return "unverified-identity";
|
|
193
|
+
const matchingProviders = (await findVerifiedDomainProviders(ctx, domain)).filter((matchingProvider) => Boolean(matchingProvider.organizationId));
|
|
194
|
+
if (new Set(matchingProviders.map((matchingProvider) => matchingProvider.organizationId)).size > 1) {
|
|
195
|
+
ctx.context.logger.warn("Skipped SSO organization provisioning because a verified domain maps to multiple organizations", {
|
|
196
|
+
domain,
|
|
197
|
+
userId: canonicalUser.id
|
|
198
|
+
});
|
|
199
|
+
return "ambiguous-target";
|
|
200
|
+
}
|
|
201
|
+
if (matchingProviders.length === 0) return "no-target";
|
|
202
|
+
matchingProviders.sort((left, right) => left.providerId.localeCompare(right.providerId));
|
|
203
|
+
const selectedProvider = matchingProviders[0];
|
|
204
|
+
if (!selectedProvider) return "no-target";
|
|
205
|
+
user = canonicalUser;
|
|
206
|
+
provider = selectedProvider;
|
|
207
|
+
organizationId = selectedProvider.organizationId;
|
|
208
|
+
userInfo = {};
|
|
209
|
+
token = void 0;
|
|
210
|
+
}
|
|
159
211
|
if (await ctx.context.adapter.findOne({
|
|
160
212
|
model: "member",
|
|
161
213
|
where: [{
|
|
162
214
|
field: "organizationId",
|
|
163
|
-
value:
|
|
215
|
+
value: organizationId
|
|
164
216
|
}, {
|
|
165
217
|
field: "userId",
|
|
166
218
|
value: user.id
|
|
167
219
|
}]
|
|
168
|
-
})) return;
|
|
169
|
-
|
|
220
|
+
})) return "already-member";
|
|
221
|
+
if (await ctx.context.adapter.findOne({
|
|
222
|
+
model: "invitation",
|
|
223
|
+
where: [
|
|
224
|
+
{
|
|
225
|
+
field: "organizationId",
|
|
226
|
+
value: organizationId
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
field: "email",
|
|
230
|
+
value: user.email.toLowerCase()
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
field: "status",
|
|
234
|
+
value: "pending"
|
|
235
|
+
}
|
|
236
|
+
]
|
|
237
|
+
})) return "invitation-pending";
|
|
238
|
+
const role = options.provisioningOptions?.getRole ? await options.provisioningOptions.getRole({
|
|
170
239
|
user,
|
|
171
|
-
userInfo
|
|
240
|
+
userInfo,
|
|
172
241
|
token,
|
|
173
242
|
provider
|
|
174
|
-
}) : provisioningOptions?.defaultRole || "member";
|
|
243
|
+
}) : options.provisioningOptions?.defaultRole || "member";
|
|
175
244
|
await ctx.context.adapter.create({
|
|
176
245
|
model: "member",
|
|
177
246
|
data: {
|
|
178
|
-
organizationId
|
|
247
|
+
organizationId,
|
|
179
248
|
userId: user.id,
|
|
180
249
|
role,
|
|
181
250
|
createdAt: /* @__PURE__ */ new Date()
|
|
182
251
|
}
|
|
183
252
|
});
|
|
253
|
+
return "assigned";
|
|
184
254
|
}
|
|
185
255
|
/**
|
|
186
|
-
* Assigns a user to
|
|
187
|
-
* Looks up SSO providers that match the user's email domain and assigns
|
|
188
|
-
* the user to the associated organization.
|
|
189
|
-
*
|
|
190
|
-
* This enables domain-based org assignment for non-SSO sign-in methods
|
|
191
|
-
* (e.g., Google OAuth with @acme.com email gets added to Acme's org).
|
|
256
|
+
* Assigns a user to the organization explicitly bound to an SSO provider.
|
|
192
257
|
*/
|
|
193
|
-
async function
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
const domain = user.email.split("@")[1];
|
|
198
|
-
if (!domain) return;
|
|
199
|
-
const whereClause = [{
|
|
200
|
-
field: "domain",
|
|
201
|
-
value: domain
|
|
202
|
-
}];
|
|
203
|
-
if (domainVerification?.enabled) whereClause.push({
|
|
204
|
-
field: "domainVerified",
|
|
205
|
-
value: true
|
|
206
|
-
});
|
|
207
|
-
let ssoProvider = await ctx.context.adapter.findOne({
|
|
208
|
-
model: "ssoProvider",
|
|
209
|
-
where: whereClause
|
|
258
|
+
async function assignOrganizationFromProvider(ctx, options) {
|
|
259
|
+
await assignOrganization(ctx, {
|
|
260
|
+
reason: "provider-bound",
|
|
261
|
+
...options
|
|
210
262
|
});
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
if (await ctx.context.adapter.findOne({
|
|
220
|
-
model: "member",
|
|
221
|
-
where: [{
|
|
222
|
-
field: "organizationId",
|
|
223
|
-
value: ssoProvider.organizationId
|
|
224
|
-
}, {
|
|
225
|
-
field: "userId",
|
|
226
|
-
value: user.id
|
|
227
|
-
}]
|
|
228
|
-
})) return;
|
|
229
|
-
const role = provisioningOptions?.getRole ? await provisioningOptions.getRole({
|
|
230
|
-
user,
|
|
231
|
-
userInfo: {},
|
|
232
|
-
provider: ssoProvider
|
|
233
|
-
}) : provisioningOptions?.defaultRole || "member";
|
|
234
|
-
await ctx.context.adapter.create({
|
|
235
|
-
model: "member",
|
|
236
|
-
data: {
|
|
237
|
-
organizationId: ssoProvider.organizationId,
|
|
238
|
-
userId: user.id,
|
|
239
|
-
role,
|
|
240
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
241
|
-
}
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Assigns a verified user to the organization for their verified email domain.
|
|
266
|
+
*/
|
|
267
|
+
async function assignOrganizationByDomain(ctx, options) {
|
|
268
|
+
await assignOrganization(ctx, {
|
|
269
|
+
reason: "verified-domain",
|
|
270
|
+
...options
|
|
242
271
|
});
|
|
243
272
|
}
|
|
244
273
|
//#endregion
|
|
@@ -1555,6 +1584,23 @@ const deleteSSOProvider = () => {
|
|
|
1555
1584
|
const DNS_LABEL_MAX_LENGTH = 63;
|
|
1556
1585
|
const DEFAULT_TOKEN_PREFIX = "better-auth-token";
|
|
1557
1586
|
const domainVerificationBodySchema = z.object({ providerId: z.string() });
|
|
1587
|
+
async function completeDomainVerification(adapter, provider) {
|
|
1588
|
+
if (!await adapter.incrementOne({
|
|
1589
|
+
model: "ssoProvider",
|
|
1590
|
+
where: [{
|
|
1591
|
+
field: "id",
|
|
1592
|
+
value: provider.id
|
|
1593
|
+
}, {
|
|
1594
|
+
field: "domain",
|
|
1595
|
+
value: provider.domain
|
|
1596
|
+
}],
|
|
1597
|
+
increment: {},
|
|
1598
|
+
set: { domainVerified: true }
|
|
1599
|
+
})) throw new APIError("CONFLICT", {
|
|
1600
|
+
code: "SSO_PROVIDER_CHANGED",
|
|
1601
|
+
message: "SSO provider changed while domain verification was in progress. Reload the provider and try again"
|
|
1602
|
+
});
|
|
1603
|
+
}
|
|
1558
1604
|
function getVerificationIdentifier(options, providerId) {
|
|
1559
1605
|
return `_${options.domainVerification?.tokenPrefix || DEFAULT_TOKEN_PREFIX}-${providerId}`;
|
|
1560
1606
|
}
|
|
@@ -1604,7 +1650,7 @@ const verifyDomain = (options) => {
|
|
|
1604
1650
|
description: "Verify the provider domain ownership via DNS records",
|
|
1605
1651
|
responses: {
|
|
1606
1652
|
"404": { description: "Provider not found" },
|
|
1607
|
-
"409": { description: "Domain has already been verified or
|
|
1653
|
+
"409": { description: "Domain has already been verified, or the provider changed while verification was in progress" },
|
|
1608
1654
|
"502": { description: "Unable to verify domain ownership due to upstream validator error" },
|
|
1609
1655
|
"204": { description: "Domain ownership was verified" }
|
|
1610
1656
|
}
|
|
@@ -1659,14 +1705,7 @@ const verifyDomain = (options) => {
|
|
|
1659
1705
|
code: "DOMAIN_VERIFICATION_FAILED"
|
|
1660
1706
|
});
|
|
1661
1707
|
}
|
|
1662
|
-
await ctx.context.adapter
|
|
1663
|
-
model: "ssoProvider",
|
|
1664
|
-
where: [{
|
|
1665
|
-
field: "providerId",
|
|
1666
|
-
value: provider.providerId
|
|
1667
|
-
}],
|
|
1668
|
-
update: { domainVerified: true }
|
|
1669
|
-
});
|
|
1708
|
+
await completeDomainVerification(ctx.context.adapter, provider);
|
|
1670
1709
|
ctx.setStatus(204);
|
|
1671
1710
|
});
|
|
1672
1711
|
};
|
|
@@ -2577,13 +2616,13 @@ const registerSSOProvider = (options) => {
|
|
|
2577
2616
|
if (!member) throw new APIError("BAD_REQUEST", { message: "You are not a member of the organization" });
|
|
2578
2617
|
if (ctx.context.hasPlugin("organization") && !hasOrgAdminRole(member)) throw new APIError("FORBIDDEN", { message: "You must be an organization owner or admin to register SSO providers" });
|
|
2579
2618
|
}
|
|
2580
|
-
if (
|
|
2619
|
+
if (new Set([
|
|
2581
2620
|
...BUILT_IN_ACCOUNT_PROVIDER_IDS,
|
|
2582
2621
|
...Object.keys(ctx.context.options.socialProviders ?? {}),
|
|
2583
2622
|
...ctx.context.socialProviders.map((p) => p.id),
|
|
2584
2623
|
...ctx.context.trustedProviders,
|
|
2585
2624
|
...options?.defaultSSO?.map((p) => p.providerId) ?? []
|
|
2586
|
-
])
|
|
2625
|
+
]).has(body.providerId)) {
|
|
2587
2626
|
ctx.context.logger.warn(`SSO provider registration rejected for reserved providerId: ${body.providerId}`);
|
|
2588
2627
|
throw new APIError("UNPROCESSABLE_ENTITY", { message: "This providerId is reserved and cannot be used for an SSO provider" });
|
|
2589
2628
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@better-auth/sso",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.28",
|
|
4
4
|
"description": "SSO plugin for Better Auth",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -65,20 +65,20 @@
|
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"@types/body-parser": "^1.19.6",
|
|
67
67
|
"@types/express": "^5.0.6",
|
|
68
|
-
"better-call": "1.
|
|
68
|
+
"better-call": "1.4.0",
|
|
69
69
|
"body-parser": "^2.3.0",
|
|
70
70
|
"express": "^5.2.1",
|
|
71
71
|
"oauth2-mock-server": "^8.2.2",
|
|
72
|
-
"tsdown": "0.
|
|
73
|
-
"@better-auth/core": "1.6.
|
|
74
|
-
"better-auth": "1.6.
|
|
72
|
+
"tsdown": "0.21.10",
|
|
73
|
+
"@better-auth/core": "1.6.28",
|
|
74
|
+
"better-auth": "1.6.28"
|
|
75
75
|
},
|
|
76
76
|
"peerDependencies": {
|
|
77
77
|
"@better-auth/utils": "0.4.2",
|
|
78
78
|
"@better-fetch/fetch": "1.3.1",
|
|
79
|
-
"better-call": "1.
|
|
80
|
-
"@better-auth/core": "^1.6.
|
|
81
|
-
"better-auth": "^1.6.
|
|
79
|
+
"better-call": "1.4.0",
|
|
80
|
+
"@better-auth/core": "^1.6.28",
|
|
81
|
+
"better-auth": "^1.6.28"
|
|
82
82
|
},
|
|
83
83
|
"scripts": {
|
|
84
84
|
"build": "tsdown",
|