@better-auth/sso 1.4.7 → 1.4.8-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +6 -6
- package/dist/client.d.mts +1 -1
- package/dist/{index-B9WMxRdD.d.mts → index-DNWhGQW-.d.mts} +81 -69
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +462 -264
- package/package.json +3 -3
- package/src/constants.ts +42 -0
- package/src/domain-verification.test.ts +1 -0
- package/src/index.ts +38 -11
- package/src/linking/index.ts +2 -0
- package/src/linking/org-assignment.ts +158 -0
- package/src/linking/types.ts +10 -0
- package/src/routes/sso.ts +338 -332
- package/src/saml/algorithms.test.ts +205 -0
- package/src/saml/algorithms.ts +259 -0
- package/src/saml/index.ts +9 -0
- package/src/saml.test.ts +350 -127
- package/src/types.ts +24 -16
- package/src/authn-request-store.ts +0 -76
- package/src/authn-request.test.ts +0 -99
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @better-auth/sso@1.4.
|
|
2
|
+
> @better-auth/sso@1.4.8-beta.1 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 [2m92.44 kB[22m [2m│ gzip: 18.07 kB[22m
|
|
11
11
|
[34mℹ[39m [2mdist/[22m[1mclient.mjs[22m [2m 0.15 kB[22m [2m│ gzip: 0.14 kB[22m
|
|
12
|
-
[34mℹ[39m [2mdist/[22m[32m[1mindex.d.mts[22m[39m [2m 1.
|
|
12
|
+
[34mℹ[39m [2mdist/[22m[32m[1mindex.d.mts[22m[39m [2m 1.48 kB[22m [2m│ gzip: 0.51 kB[22m
|
|
13
13
|
[34mℹ[39m [2mdist/[22m[32m[1mclient.d.mts[22m[39m [2m 0.49 kB[22m [2m│ gzip: 0.30 kB[22m
|
|
14
|
-
[34mℹ[39m [2mdist/[22m[32mindex-
|
|
15
|
-
[34mℹ[39m 5 files, total:
|
|
16
|
-
[32m✔[39m Build complete in [
|
|
14
|
+
[34mℹ[39m [2mdist/[22m[32mindex-DNWhGQW-.d.mts[39m [2m42.86 kB[22m [2m│ gzip: 8.79 kB[22m
|
|
15
|
+
[34mℹ[39m 5 files, total: 137.41 kB
|
|
16
|
+
[32m✔[39m Build complete in [32m12113ms[39m
|
package/dist/client.d.mts
CHANGED
|
@@ -1,43 +1,47 @@
|
|
|
1
1
|
import { APIError } from "better-auth/api";
|
|
2
|
-
import * as z from "zod/v4";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
2
|
+
import * as z$1 from "zod/v4";
|
|
3
|
+
import z from "zod/v4";
|
|
4
|
+
import { Awaitable, OAuth2Tokens, User } from "better-auth";
|
|
5
|
+
import * as better_call0 from "better-call";
|
|
5
6
|
|
|
6
|
-
//#region src/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
7
|
+
//#region src/saml/algorithms.d.ts
|
|
8
|
+
declare const SignatureAlgorithm: {
|
|
9
|
+
readonly RSA_SHA1: "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
|
|
10
|
+
readonly RSA_SHA256: "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256";
|
|
11
|
+
readonly RSA_SHA384: "http://www.w3.org/2001/04/xmldsig-more#rsa-sha384";
|
|
12
|
+
readonly RSA_SHA512: "http://www.w3.org/2001/04/xmldsig-more#rsa-sha512";
|
|
13
|
+
readonly ECDSA_SHA256: "http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha256";
|
|
14
|
+
readonly ECDSA_SHA384: "http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha384";
|
|
15
|
+
readonly ECDSA_SHA512: "http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha512";
|
|
16
|
+
};
|
|
17
|
+
declare const DigestAlgorithm: {
|
|
18
|
+
readonly SHA1: "http://www.w3.org/2000/09/xmldsig#sha1";
|
|
19
|
+
readonly SHA256: "http://www.w3.org/2001/04/xmlenc#sha256";
|
|
20
|
+
readonly SHA384: "http://www.w3.org/2001/04/xmldsig-more#sha384";
|
|
21
|
+
readonly SHA512: "http://www.w3.org/2001/04/xmlenc#sha512";
|
|
22
|
+
};
|
|
23
|
+
declare const KeyEncryptionAlgorithm: {
|
|
24
|
+
readonly RSA_1_5: "http://www.w3.org/2001/04/xmlenc#rsa-1_5";
|
|
25
|
+
readonly RSA_OAEP: "http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p";
|
|
26
|
+
readonly RSA_OAEP_SHA256: "http://www.w3.org/2009/xmlenc11#rsa-oaep";
|
|
27
|
+
};
|
|
28
|
+
declare const DataEncryptionAlgorithm: {
|
|
29
|
+
readonly TRIPLEDES_CBC: "http://www.w3.org/2001/04/xmlenc#tripledes-cbc";
|
|
30
|
+
readonly AES_128_CBC: "http://www.w3.org/2001/04/xmlenc#aes128-cbc";
|
|
31
|
+
readonly AES_192_CBC: "http://www.w3.org/2001/04/xmlenc#aes192-cbc";
|
|
32
|
+
readonly AES_256_CBC: "http://www.w3.org/2001/04/xmlenc#aes256-cbc";
|
|
33
|
+
readonly AES_128_GCM: "http://www.w3.org/2009/xmlenc11#aes128-gcm";
|
|
34
|
+
readonly AES_192_GCM: "http://www.w3.org/2009/xmlenc11#aes192-gcm";
|
|
35
|
+
readonly AES_256_GCM: "http://www.w3.org/2009/xmlenc11#aes256-gcm";
|
|
36
|
+
};
|
|
37
|
+
type DeprecatedAlgorithmBehavior = "reject" | "warn" | "allow";
|
|
38
|
+
interface AlgorithmValidationOptions {
|
|
39
|
+
onDeprecated?: DeprecatedAlgorithmBehavior;
|
|
40
|
+
allowedSignatureAlgorithms?: string[];
|
|
41
|
+
allowedDigestAlgorithms?: string[];
|
|
42
|
+
allowedKeyEncryptionAlgorithms?: string[];
|
|
43
|
+
allowedDataEncryptionAlgorithms?: string[];
|
|
28
44
|
}
|
|
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
45
|
//#endregion
|
|
42
46
|
//#region src/types.d.ts
|
|
43
47
|
interface OIDCMapping {
|
|
@@ -148,7 +152,7 @@ interface SSOOptions {
|
|
|
148
152
|
* The SSO provider
|
|
149
153
|
*/
|
|
150
154
|
provider: SSOProvider<SSOOptions>;
|
|
151
|
-
}) =>
|
|
155
|
+
}) => Awaitable<void>) | undefined;
|
|
152
156
|
/**
|
|
153
157
|
* Organization provisioning options
|
|
154
158
|
*/
|
|
@@ -244,7 +248,7 @@ interface SSOOptions {
|
|
|
244
248
|
* ```
|
|
245
249
|
* @default 10
|
|
246
250
|
*/
|
|
247
|
-
providersLimit?: (number | ((user: User) =>
|
|
251
|
+
providersLimit?: (number | ((user: User) => Awaitable<number>)) | undefined;
|
|
248
252
|
/**
|
|
249
253
|
* Trust the email verified flag from the provider.
|
|
250
254
|
*
|
|
@@ -253,7 +257,13 @@ interface SSOOptions {
|
|
|
253
257
|
*
|
|
254
258
|
* If you want to allow account linking for specific trusted providers, enable the `accountLinking` option in your auth config and specify those
|
|
255
259
|
* providers in the `trustedProviders` list.
|
|
260
|
+
*
|
|
256
261
|
* @default false
|
|
262
|
+
*
|
|
263
|
+
* @deprecated This option is discouraged for new projects. Relying on provider-level `email_verified` is a weaker
|
|
264
|
+
* trust signal compared to using `trustedProviders` in `accountLinking` or enabling `domainVerification` for SSO.
|
|
265
|
+
* Existing configurations will continue to work, but new integrations should use explicit trust mechanisms.
|
|
266
|
+
* This option may be removed in a future major version.
|
|
257
267
|
*/
|
|
258
268
|
trustEmailVerified?: boolean | undefined;
|
|
259
269
|
/**
|
|
@@ -311,16 +321,6 @@ interface SSOOptions {
|
|
|
311
321
|
* @default 300000 (5 minutes)
|
|
312
322
|
*/
|
|
313
323
|
requestTTL?: number;
|
|
314
|
-
/**
|
|
315
|
-
* Custom AuthnRequest store implementation.
|
|
316
|
-
* Use this to provide a custom storage backend (e.g., Redis-backed store).
|
|
317
|
-
*
|
|
318
|
-
* Providing a custom store automatically enables InResponseTo validation.
|
|
319
|
-
*
|
|
320
|
-
* Note: When not provided, the default storage (secondaryStorage with
|
|
321
|
-
* verification table fallback) is used automatically.
|
|
322
|
-
*/
|
|
323
|
-
authnRequestStore?: AuthnRequestStore;
|
|
324
324
|
/**
|
|
325
325
|
* Clock skew tolerance for SAML assertion timestamp validation in milliseconds.
|
|
326
326
|
* Allows for minor time differences between IdP and SP servers.
|
|
@@ -353,15 +353,29 @@ interface SSOOptions {
|
|
|
353
353
|
* @default false
|
|
354
354
|
*/
|
|
355
355
|
requireTimestamps?: boolean;
|
|
356
|
+
/**
|
|
357
|
+
* Algorithm validation options for SAML responses.
|
|
358
|
+
*
|
|
359
|
+
* Controls behavior when deprecated algorithms (SHA-1, RSA1_5, 3DES)
|
|
360
|
+
* are detected in SAML responses.
|
|
361
|
+
*
|
|
362
|
+
* @example
|
|
363
|
+
* ```ts
|
|
364
|
+
* algorithms: {
|
|
365
|
+
* onDeprecated: "reject" // Reject deprecated algorithms
|
|
366
|
+
* }
|
|
367
|
+
* ```
|
|
368
|
+
*/
|
|
369
|
+
algorithms?: AlgorithmValidationOptions;
|
|
356
370
|
};
|
|
357
371
|
}
|
|
358
372
|
//#endregion
|
|
359
373
|
//#region src/routes/domain-verification.d.ts
|
|
360
|
-
declare const requestDomainVerification: (options: SSOOptions) =>
|
|
374
|
+
declare const requestDomainVerification: (options: SSOOptions) => better_call0.StrictEndpoint<"/sso/request-domain-verification", {
|
|
361
375
|
method: "POST";
|
|
362
|
-
body: z.ZodObject<{
|
|
363
|
-
providerId: z.ZodString;
|
|
364
|
-
}, z.core.$strip>;
|
|
376
|
+
body: z$1.ZodObject<{
|
|
377
|
+
providerId: z$1.ZodString;
|
|
378
|
+
}, z$1.core.$strip>;
|
|
365
379
|
metadata: {
|
|
366
380
|
openapi: {
|
|
367
381
|
summary: string;
|
|
@@ -379,7 +393,7 @@ declare const requestDomainVerification: (options: SSOOptions) => better_call7.S
|
|
|
379
393
|
};
|
|
380
394
|
};
|
|
381
395
|
};
|
|
382
|
-
use: ((inputContext:
|
|
396
|
+
use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
|
|
383
397
|
session: {
|
|
384
398
|
session: Record<string, any> & {
|
|
385
399
|
id: string;
|
|
@@ -405,11 +419,11 @@ declare const requestDomainVerification: (options: SSOOptions) => better_call7.S
|
|
|
405
419
|
}, {
|
|
406
420
|
domainVerificationToken: string;
|
|
407
421
|
}>;
|
|
408
|
-
declare const verifyDomain: (options: SSOOptions) =>
|
|
422
|
+
declare const verifyDomain: (options: SSOOptions) => better_call0.StrictEndpoint<"/sso/verify-domain", {
|
|
409
423
|
method: "POST";
|
|
410
|
-
body: z.ZodObject<{
|
|
411
|
-
providerId: z.ZodString;
|
|
412
|
-
}, z.core.$strip>;
|
|
424
|
+
body: z$1.ZodObject<{
|
|
425
|
+
providerId: z$1.ZodString;
|
|
426
|
+
}, z$1.core.$strip>;
|
|
413
427
|
metadata: {
|
|
414
428
|
openapi: {
|
|
415
429
|
summary: string;
|
|
@@ -430,7 +444,7 @@ declare const verifyDomain: (options: SSOOptions) => better_call7.StrictEndpoint
|
|
|
430
444
|
};
|
|
431
445
|
};
|
|
432
446
|
};
|
|
433
|
-
use: ((inputContext:
|
|
447
|
+
use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
|
|
434
448
|
session: {
|
|
435
449
|
session: Record<string, any> & {
|
|
436
450
|
id: string;
|
|
@@ -456,8 +470,6 @@ declare const verifyDomain: (options: SSOOptions) => better_call7.StrictEndpoint
|
|
|
456
470
|
}, void>;
|
|
457
471
|
//#endregion
|
|
458
472
|
//#region src/routes/sso.d.ts
|
|
459
|
-
/** Default clock skew tolerance: 5 minutes */
|
|
460
|
-
declare const DEFAULT_CLOCK_SKEW_MS: number;
|
|
461
473
|
interface TimestampValidationOptions {
|
|
462
474
|
clockSkew?: number;
|
|
463
475
|
requireTimestamps?: boolean;
|
|
@@ -476,7 +488,7 @@ interface SAMLConditions {
|
|
|
476
488
|
* @throws {APIError} If timestamps are invalid, expired, or not yet valid
|
|
477
489
|
*/
|
|
478
490
|
declare function validateSAMLTimestamp(conditions: SAMLConditions | undefined, options?: TimestampValidationOptions): void;
|
|
479
|
-
declare const spMetadata: () =>
|
|
491
|
+
declare const spMetadata: () => better_call0.StrictEndpoint<"/sso/saml2/sp/metadata", {
|
|
480
492
|
method: "GET";
|
|
481
493
|
query: z.ZodObject<{
|
|
482
494
|
providerId: z.ZodString;
|
|
@@ -498,7 +510,7 @@ declare const spMetadata: () => better_call7.StrictEndpoint<"/sso/saml2/sp/metad
|
|
|
498
510
|
};
|
|
499
511
|
};
|
|
500
512
|
}, Response>;
|
|
501
|
-
declare const registerSSOProvider: <O extends SSOOptions>(options: O) =>
|
|
513
|
+
declare const registerSSOProvider: <O extends SSOOptions>(options: O) => better_call0.StrictEndpoint<"/sso/register", {
|
|
502
514
|
method: "POST";
|
|
503
515
|
body: z.ZodObject<{
|
|
504
516
|
providerId: z.ZodString;
|
|
@@ -577,7 +589,7 @@ declare const registerSSOProvider: <O extends SSOOptions>(options: O) => better_
|
|
|
577
589
|
organizationId: z.ZodOptional<z.ZodString>;
|
|
578
590
|
overrideUserInfo: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
579
591
|
}, z.core.$strip>;
|
|
580
|
-
use: ((inputContext:
|
|
592
|
+
use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
|
|
581
593
|
session: {
|
|
582
594
|
session: Record<string, any> & {
|
|
583
595
|
id: string;
|
|
@@ -767,7 +779,7 @@ declare const registerSSOProvider: <O extends SSOOptions>(options: O) => better_
|
|
|
767
779
|
domainVerified: boolean;
|
|
768
780
|
domainVerificationToken: string;
|
|
769
781
|
} & SSOProvider<O> : SSOProvider<O>>;
|
|
770
|
-
declare const signInSSO: (options?: SSOOptions) =>
|
|
782
|
+
declare const signInSSO: (options?: SSOOptions) => better_call0.StrictEndpoint<"/sign-in/sso", {
|
|
771
783
|
method: "POST";
|
|
772
784
|
body: z.ZodObject<{
|
|
773
785
|
email: z.ZodOptional<z.ZodString>;
|
|
@@ -861,7 +873,7 @@ declare const signInSSO: (options?: SSOOptions) => better_call7.StrictEndpoint<"
|
|
|
861
873
|
url: string;
|
|
862
874
|
redirect: boolean;
|
|
863
875
|
}>;
|
|
864
|
-
declare const callbackSSO: (options?: SSOOptions) =>
|
|
876
|
+
declare const callbackSSO: (options?: SSOOptions) => better_call0.StrictEndpoint<"/sso/callback/:providerId", {
|
|
865
877
|
method: "GET";
|
|
866
878
|
query: z.ZodObject<{
|
|
867
879
|
code: z.ZodOptional<z.ZodString>;
|
|
@@ -884,7 +896,7 @@ declare const callbackSSO: (options?: SSOOptions) => better_call7.StrictEndpoint
|
|
|
884
896
|
scope: "server";
|
|
885
897
|
};
|
|
886
898
|
}, never>;
|
|
887
|
-
declare const callbackSSOSAML: (options?: SSOOptions) =>
|
|
899
|
+
declare const callbackSSOSAML: (options?: SSOOptions) => better_call0.StrictEndpoint<"/sso/saml2/callback/:providerId", {
|
|
888
900
|
method: "POST";
|
|
889
901
|
body: z.ZodObject<{
|
|
890
902
|
SAMLResponse: z.ZodString;
|
|
@@ -911,7 +923,7 @@ declare const callbackSSOSAML: (options?: SSOOptions) => better_call7.StrictEndp
|
|
|
911
923
|
scope: "server";
|
|
912
924
|
};
|
|
913
925
|
}, never>;
|
|
914
|
-
declare const acsEndpoint: (options?: SSOOptions) =>
|
|
926
|
+
declare const acsEndpoint: (options?: SSOOptions) => better_call0.StrictEndpoint<"/sso/saml2/sp/acs/:providerId", {
|
|
915
927
|
method: "POST";
|
|
916
928
|
params: z.ZodObject<{
|
|
917
929
|
providerId: z.ZodOptional<z.ZodString>;
|
|
@@ -1230,4 +1242,4 @@ declare function sso<O extends SSOOptions>(options?: O | undefined): {
|
|
|
1230
1242
|
endpoints: SSOEndpoints<O>;
|
|
1231
1243
|
};
|
|
1232
1244
|
//#endregion
|
|
1233
|
-
export {
|
|
1245
|
+
export { KeyEncryptionAlgorithm as A, SAMLConfig as C, DataEncryptionAlgorithm as D, AlgorithmValidationOptions as E, DeprecatedAlgorithmBehavior as O, OIDCConfig as S, SSOProvider 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, SignatureAlgorithm as j, DigestAlgorithm 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, SSOOptions as w, validateSAMLTimestamp as x, SAMLConditions as y };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as
|
|
2
|
-
export {
|
|
1
|
+
import { A as KeyEncryptionAlgorithm, C as SAMLConfig, D as DataEncryptionAlgorithm, E as AlgorithmValidationOptions, O as DeprecatedAlgorithmBehavior, S as OIDCConfig, T as SSOProvider, _ 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 SignatureAlgorithm, k as DigestAlgorithm, 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 SSOOptions, x as validateSAMLTimestamp, y as SAMLConditions } from "./index-DNWhGQW-.mjs";
|
|
2
|
+
export { AlgorithmValidationOptions, 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 };
|