@better-auth/sso 1.4.0-beta.13 → 1.4.0-beta.15

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.
@@ -1,25 +1,25 @@
1
1
 
2
- > @better-auth/sso@1.4.0-beta.13 build /home/runner/work/better-auth/better-auth/packages/sso
2
+ > @better-auth/sso@1.4.0-beta.15 build /home/runner/work/better-auth/better-auth/packages/sso
3
3
  > tsdown
4
4
 
5
- ℹ tsdown v0.15.9 powered by rolldown v1.0.0-beta.44
5
+ ℹ tsdown v0.15.11 powered by rolldown v1.0.0-beta.45
6
6
  ℹ Using tsdown config: /home/runner/work/better-auth/better-auth/packages/sso/tsdown.config.ts
7
7
  ℹ entry: src/client.ts, src/index.ts
8
8
  ℹ tsconfig: tsconfig.json
9
9
  ℹ Build start
10
- ℹ [CJS] dist/client.cjs  0.19 kB │ gzip: 0.17 kB
10
+ ℹ [CJS] dist/client.cjs  0.19 kB │ gzip: 0.16 kB
11
11
  ℹ [CJS] dist/index.cjs  0.08 kB │ gzip: 0.08 kB
12
- ℹ [CJS] dist/src-BYOa9Nr6.cjs 52.34 kB │ gzip: 9.21 kB
12
+ ℹ [CJS] dist/src-BsLnNXTo.cjs 52.34 kB │ gzip: 9.21 kB
13
13
  ℹ [CJS] 3 files, total: 52.61 kB
14
14
  ℹ [ESM] dist/client.js  0.18 kB │ gzip: 0.16 kB
15
15
  ℹ [ESM] dist/index.js  0.06 kB │ gzip: 0.07 kB
16
- ℹ [ESM] dist/src-KQzfNIm4.js 49.59 kB │ gzip: 8.54 kB
16
+ ℹ [ESM] dist/src-BEPbgggK.js 49.59 kB │ gzip: 8.54 kB
17
17
  ℹ [ESM] dist/index.d.ts  0.24 kB │ gzip: 0.16 kB
18
18
  ℹ [ESM] dist/client.d.ts  0.21 kB │ gzip: 0.18 kB
19
- ℹ [ESM] dist/index-CL9gq2xe.d.ts 21.42 kB │ gzip: 3.10 kB
20
- ℹ [ESM] 6 files, total: 71.70 kB
19
+ ℹ [ESM] dist/index-CdeDxbNh.d.ts 22.04 kB │ gzip: 3.15 kB
20
+ ℹ [ESM] 6 files, total: 72.32 kB
21
21
  ℹ [CJS] dist/index.d.cts  0.24 kB │ gzip: 0.16 kB
22
22
  ℹ [CJS] dist/client.d.cts  0.21 kB │ gzip: 0.18 kB
23
- ℹ [CJS] dist/index-N2GvRGik.d.cts 21.42 kB │ gzip: 3.10 kB
24
- ℹ [CJS] 3 files, total: 21.88 kB
25
- ✔ Build complete in 8810ms
23
+ ℹ [CJS] dist/index-DJAIa5j3.d.cts 22.04 kB │ gzip: 3.16 kB
24
+ ℹ [CJS] 3 files, total: 22.50 kB
25
+ ✔ Build complete in 9377ms
package/dist/client.cjs CHANGED
@@ -1,4 +1,4 @@
1
- require('./src-BYOa9Nr6.cjs');
1
+ require('./src-BsLnNXTo.cjs');
2
2
 
3
3
  //#region src/client.ts
4
4
  const ssoClient = () => {
package/dist/client.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { s as sso } from "./index-N2GvRGik.cjs";
1
+ import { s as sso } from "./index-DJAIa5j3.cjs";
2
2
 
3
3
  //#region src/client.d.ts
4
4
  declare const ssoClient: () => {
package/dist/client.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { s as sso } from "./index-CL9gq2xe.js";
1
+ import { s as sso } from "./index-CdeDxbNh.js";
2
2
 
3
3
  //#region src/client.d.ts
4
4
  declare const ssoClient: () => {
package/dist/client.js CHANGED
@@ -1,4 +1,4 @@
1
- import "./src-KQzfNIm4.js";
1
+ import "./src-BEPbgggK.js";
2
2
 
3
3
  //#region src/client.ts
4
4
  const ssoClient = () => {
@@ -4,43 +4,43 @@ import * as better_call0 from "better-call";
4
4
 
5
5
  //#region src/index.d.ts
6
6
  interface OIDCMapping {
7
- id?: string;
8
- email?: string;
9
- emailVerified?: string;
10
- name?: string;
11
- image?: string;
12
- extraFields?: Record<string, string>;
7
+ id?: string | undefined;
8
+ email?: string | undefined;
9
+ emailVerified?: string | undefined;
10
+ name?: string | undefined;
11
+ image?: string | undefined;
12
+ extraFields?: Record<string, string> | undefined;
13
13
  }
14
14
  interface SAMLMapping {
15
- id?: string;
16
- email?: string;
17
- emailVerified?: string;
18
- name?: string;
19
- firstName?: string;
20
- lastName?: string;
21
- extraFields?: Record<string, string>;
15
+ id?: string | undefined;
16
+ email?: string | undefined;
17
+ emailVerified?: string | undefined;
18
+ name?: string | undefined;
19
+ firstName?: string | undefined;
20
+ lastName?: string | undefined;
21
+ extraFields?: Record<string, string> | undefined;
22
22
  }
23
23
  interface OIDCConfig {
24
24
  issuer: string;
25
25
  pkce: boolean;
26
26
  clientId: string;
27
27
  clientSecret: string;
28
- authorizationEndpoint?: string;
28
+ authorizationEndpoint?: string | undefined;
29
29
  discoveryEndpoint: string;
30
- userInfoEndpoint?: string;
31
- scopes?: string[];
32
- overrideUserInfo?: boolean;
33
- tokenEndpoint?: string;
34
- tokenEndpointAuthentication?: "client_secret_post" | "client_secret_basic";
35
- jwksEndpoint?: string;
36
- mapping?: OIDCMapping;
30
+ userInfoEndpoint?: string | undefined;
31
+ scopes?: string[] | undefined;
32
+ overrideUserInfo?: boolean | undefined;
33
+ tokenEndpoint?: string | undefined;
34
+ tokenEndpointAuthentication?: ("client_secret_post" | "client_secret_basic") | undefined;
35
+ jwksEndpoint?: string | undefined;
36
+ mapping?: OIDCMapping | undefined;
37
37
  }
38
38
  interface SAMLConfig {
39
39
  issuer: string;
40
40
  entryPoint: string;
41
41
  cert: string;
42
42
  callbackUrl: string;
43
- audience?: string;
43
+ audience?: string | undefined;
44
44
  idpMetadata?: {
45
45
  metadata?: string;
46
46
  entityID?: string;
@@ -56,39 +56,39 @@ interface SAMLConfig {
56
56
  Binding: string;
57
57
  Location: string;
58
58
  }>;
59
- };
59
+ } | undefined;
60
60
  spMetadata: {
61
- metadata?: string;
62
- entityID?: string;
63
- binding?: string;
64
- privateKey?: string;
65
- privateKeyPass?: string;
66
- isAssertionEncrypted?: boolean;
67
- encPrivateKey?: string;
68
- encPrivateKeyPass?: string;
61
+ metadata?: string | undefined;
62
+ entityID?: string | undefined;
63
+ binding?: string | undefined;
64
+ privateKey?: string | undefined;
65
+ privateKeyPass?: string | undefined;
66
+ isAssertionEncrypted?: boolean | undefined;
67
+ encPrivateKey?: string | undefined;
68
+ encPrivateKeyPass?: string | undefined;
69
69
  };
70
- wantAssertionsSigned?: boolean;
71
- signatureAlgorithm?: string;
72
- digestAlgorithm?: string;
73
- identifierFormat?: string;
74
- privateKey?: string;
75
- decryptionPvk?: string;
76
- additionalParams?: Record<string, any>;
77
- mapping?: SAMLMapping;
70
+ wantAssertionsSigned?: boolean | undefined;
71
+ signatureAlgorithm?: string | undefined;
72
+ digestAlgorithm?: string | undefined;
73
+ identifierFormat?: string | undefined;
74
+ privateKey?: string | undefined;
75
+ decryptionPvk?: string | undefined;
76
+ additionalParams?: Record<string, any> | undefined;
77
+ mapping?: SAMLMapping | undefined;
78
78
  }
79
79
  interface SSOProvider {
80
80
  issuer: string;
81
- oidcConfig?: OIDCConfig;
82
- samlConfig?: SAMLConfig;
81
+ oidcConfig?: OIDCConfig | undefined;
82
+ samlConfig?: SAMLConfig | undefined;
83
83
  userId: string;
84
84
  providerId: string;
85
- organizationId?: string;
85
+ organizationId?: string | undefined;
86
86
  }
87
87
  interface SSOOptions {
88
88
  /**
89
89
  * custom function to provision a user when they sign in with an SSO provider.
90
90
  */
91
- provisionUser?: (data: {
91
+ provisionUser?: ((data: {
92
92
  /**
93
93
  * The user object from the database
94
94
  */
@@ -105,7 +105,7 @@ interface SSOOptions {
105
105
  * The SSO provider
106
106
  */
107
107
  provider: SSOProvider;
108
- }) => Promise<void>;
108
+ }) => Promise<void>) | undefined;
109
109
  /**
110
110
  * Organization provisioning options
111
111
  */
@@ -130,7 +130,7 @@ interface SSOOptions {
130
130
  */
131
131
  provider: SSOProvider;
132
132
  }) => Promise<"member" | "admin">;
133
- };
133
+ } | undefined;
134
134
  /**
135
135
  * Default SSO provider configurations for testing.
136
136
  * These will take the precedence over the database providers.
@@ -153,17 +153,17 @@ interface SSOOptions {
153
153
  * OIDC configuration
154
154
  */
155
155
  oidcConfig?: OIDCConfig;
156
- }>;
156
+ }> | undefined;
157
157
  /**
158
158
  * Override user info with the provider info.
159
159
  * @default false
160
160
  */
161
- defaultOverrideUserInfo?: boolean;
161
+ defaultOverrideUserInfo?: boolean | undefined;
162
162
  /**
163
163
  * Disable implicit sign up for new users. When set to true for the provider,
164
164
  * sign-in need to be called with with requestSignUp as true to create new users.
165
165
  */
166
- disableImplicitSignUp?: boolean;
166
+ disableImplicitSignUp?: boolean | undefined;
167
167
  /**
168
168
  * Configure the maximum number of SSO providers a user can register.
169
169
  * You can also pass a function that returns a number.
@@ -178,14 +178,14 @@ interface SSOOptions {
178
178
  * ```
179
179
  * @default 10
180
180
  */
181
- providersLimit?: number | ((user: User) => Promise<number> | number);
181
+ providersLimit?: (number | ((user: User) => Promise<number> | number)) | undefined;
182
182
  /**
183
183
  * Trust the email verified flag from the provider.
184
184
  * @default false
185
185
  */
186
- trustEmailVerified?: boolean;
186
+ trustEmailVerified?: boolean | undefined;
187
187
  }
188
- declare const sso: (options?: SSOOptions) => {
188
+ declare const sso: (options?: SSOOptions | undefined) => {
189
189
  id: "sso";
190
190
  endpoints: {
191
191
  spMetadata: better_call0.StrictEndpoint<"/sso/saml2/sp/metadata", {
@@ -473,7 +473,7 @@ declare const sso: (options?: SSOOptions) => {
473
473
  issuer: string;
474
474
  userId: string;
475
475
  providerId: string;
476
- organizationId?: string;
476
+ organizationId?: string | undefined;
477
477
  }>;
478
478
  signInSSO: better_call0.StrictEndpoint<"/sign-in/sso", {
479
479
  method: "POST";
@@ -4,43 +4,43 @@ import * as z from "zod/v4";
4
4
 
5
5
  //#region src/index.d.ts
6
6
  interface OIDCMapping {
7
- id?: string;
8
- email?: string;
9
- emailVerified?: string;
10
- name?: string;
11
- image?: string;
12
- extraFields?: Record<string, string>;
7
+ id?: string | undefined;
8
+ email?: string | undefined;
9
+ emailVerified?: string | undefined;
10
+ name?: string | undefined;
11
+ image?: string | undefined;
12
+ extraFields?: Record<string, string> | undefined;
13
13
  }
14
14
  interface SAMLMapping {
15
- id?: string;
16
- email?: string;
17
- emailVerified?: string;
18
- name?: string;
19
- firstName?: string;
20
- lastName?: string;
21
- extraFields?: Record<string, string>;
15
+ id?: string | undefined;
16
+ email?: string | undefined;
17
+ emailVerified?: string | undefined;
18
+ name?: string | undefined;
19
+ firstName?: string | undefined;
20
+ lastName?: string | undefined;
21
+ extraFields?: Record<string, string> | undefined;
22
22
  }
23
23
  interface OIDCConfig {
24
24
  issuer: string;
25
25
  pkce: boolean;
26
26
  clientId: string;
27
27
  clientSecret: string;
28
- authorizationEndpoint?: string;
28
+ authorizationEndpoint?: string | undefined;
29
29
  discoveryEndpoint: string;
30
- userInfoEndpoint?: string;
31
- scopes?: string[];
32
- overrideUserInfo?: boolean;
33
- tokenEndpoint?: string;
34
- tokenEndpointAuthentication?: "client_secret_post" | "client_secret_basic";
35
- jwksEndpoint?: string;
36
- mapping?: OIDCMapping;
30
+ userInfoEndpoint?: string | undefined;
31
+ scopes?: string[] | undefined;
32
+ overrideUserInfo?: boolean | undefined;
33
+ tokenEndpoint?: string | undefined;
34
+ tokenEndpointAuthentication?: ("client_secret_post" | "client_secret_basic") | undefined;
35
+ jwksEndpoint?: string | undefined;
36
+ mapping?: OIDCMapping | undefined;
37
37
  }
38
38
  interface SAMLConfig {
39
39
  issuer: string;
40
40
  entryPoint: string;
41
41
  cert: string;
42
42
  callbackUrl: string;
43
- audience?: string;
43
+ audience?: string | undefined;
44
44
  idpMetadata?: {
45
45
  metadata?: string;
46
46
  entityID?: string;
@@ -56,39 +56,39 @@ interface SAMLConfig {
56
56
  Binding: string;
57
57
  Location: string;
58
58
  }>;
59
- };
59
+ } | undefined;
60
60
  spMetadata: {
61
- metadata?: string;
62
- entityID?: string;
63
- binding?: string;
64
- privateKey?: string;
65
- privateKeyPass?: string;
66
- isAssertionEncrypted?: boolean;
67
- encPrivateKey?: string;
68
- encPrivateKeyPass?: string;
61
+ metadata?: string | undefined;
62
+ entityID?: string | undefined;
63
+ binding?: string | undefined;
64
+ privateKey?: string | undefined;
65
+ privateKeyPass?: string | undefined;
66
+ isAssertionEncrypted?: boolean | undefined;
67
+ encPrivateKey?: string | undefined;
68
+ encPrivateKeyPass?: string | undefined;
69
69
  };
70
- wantAssertionsSigned?: boolean;
71
- signatureAlgorithm?: string;
72
- digestAlgorithm?: string;
73
- identifierFormat?: string;
74
- privateKey?: string;
75
- decryptionPvk?: string;
76
- additionalParams?: Record<string, any>;
77
- mapping?: SAMLMapping;
70
+ wantAssertionsSigned?: boolean | undefined;
71
+ signatureAlgorithm?: string | undefined;
72
+ digestAlgorithm?: string | undefined;
73
+ identifierFormat?: string | undefined;
74
+ privateKey?: string | undefined;
75
+ decryptionPvk?: string | undefined;
76
+ additionalParams?: Record<string, any> | undefined;
77
+ mapping?: SAMLMapping | undefined;
78
78
  }
79
79
  interface SSOProvider {
80
80
  issuer: string;
81
- oidcConfig?: OIDCConfig;
82
- samlConfig?: SAMLConfig;
81
+ oidcConfig?: OIDCConfig | undefined;
82
+ samlConfig?: SAMLConfig | undefined;
83
83
  userId: string;
84
84
  providerId: string;
85
- organizationId?: string;
85
+ organizationId?: string | undefined;
86
86
  }
87
87
  interface SSOOptions {
88
88
  /**
89
89
  * custom function to provision a user when they sign in with an SSO provider.
90
90
  */
91
- provisionUser?: (data: {
91
+ provisionUser?: ((data: {
92
92
  /**
93
93
  * The user object from the database
94
94
  */
@@ -105,7 +105,7 @@ interface SSOOptions {
105
105
  * The SSO provider
106
106
  */
107
107
  provider: SSOProvider;
108
- }) => Promise<void>;
108
+ }) => Promise<void>) | undefined;
109
109
  /**
110
110
  * Organization provisioning options
111
111
  */
@@ -130,7 +130,7 @@ interface SSOOptions {
130
130
  */
131
131
  provider: SSOProvider;
132
132
  }) => Promise<"member" | "admin">;
133
- };
133
+ } | undefined;
134
134
  /**
135
135
  * Default SSO provider configurations for testing.
136
136
  * These will take the precedence over the database providers.
@@ -153,17 +153,17 @@ interface SSOOptions {
153
153
  * OIDC configuration
154
154
  */
155
155
  oidcConfig?: OIDCConfig;
156
- }>;
156
+ }> | undefined;
157
157
  /**
158
158
  * Override user info with the provider info.
159
159
  * @default false
160
160
  */
161
- defaultOverrideUserInfo?: boolean;
161
+ defaultOverrideUserInfo?: boolean | undefined;
162
162
  /**
163
163
  * Disable implicit sign up for new users. When set to true for the provider,
164
164
  * sign-in need to be called with with requestSignUp as true to create new users.
165
165
  */
166
- disableImplicitSignUp?: boolean;
166
+ disableImplicitSignUp?: boolean | undefined;
167
167
  /**
168
168
  * Configure the maximum number of SSO providers a user can register.
169
169
  * You can also pass a function that returns a number.
@@ -178,14 +178,14 @@ interface SSOOptions {
178
178
  * ```
179
179
  * @default 10
180
180
  */
181
- providersLimit?: number | ((user: User) => Promise<number> | number);
181
+ providersLimit?: (number | ((user: User) => Promise<number> | number)) | undefined;
182
182
  /**
183
183
  * Trust the email verified flag from the provider.
184
184
  * @default false
185
185
  */
186
- trustEmailVerified?: boolean;
186
+ trustEmailVerified?: boolean | undefined;
187
187
  }
188
- declare const sso: (options?: SSOOptions) => {
188
+ declare const sso: (options?: SSOOptions | undefined) => {
189
189
  id: "sso";
190
190
  endpoints: {
191
191
  spMetadata: better_call0.StrictEndpoint<"/sso/saml2/sp/metadata", {
@@ -473,7 +473,7 @@ declare const sso: (options?: SSOOptions) => {
473
473
  issuer: string;
474
474
  userId: string;
475
475
  providerId: string;
476
- organizationId?: string;
476
+ organizationId?: string | undefined;
477
477
  }>;
478
478
  signInSSO: better_call0.StrictEndpoint<"/sign-in/sso", {
479
479
  method: "POST";
package/dist/index.cjs CHANGED
@@ -1,3 +1,3 @@
1
- const require_src = require('./src-BYOa9Nr6.cjs');
1
+ const require_src = require('./src-BsLnNXTo.cjs');
2
2
 
3
3
  exports.sso = require_src.sso;
package/dist/index.d.cts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as SSOOptions, i as SAMLMapping, n as OIDCMapping, o as SSOProvider, r as SAMLConfig, s as sso, t as OIDCConfig } from "./index-N2GvRGik.cjs";
1
+ import { a as SSOOptions, i as SAMLMapping, n as OIDCMapping, o as SSOProvider, r as SAMLConfig, s as sso, t as OIDCConfig } from "./index-DJAIa5j3.cjs";
2
2
  export { OIDCConfig, OIDCMapping, SAMLConfig, SAMLMapping, SSOOptions, SSOProvider, sso };
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as SSOOptions, i as SAMLMapping, n as OIDCMapping, o as SSOProvider, r as SAMLConfig, s as sso, t as OIDCConfig } from "./index-CL9gq2xe.js";
1
+ import { a as SSOOptions, i as SAMLMapping, n as OIDCMapping, o as SSOProvider, r as SAMLConfig, s as sso, t as OIDCConfig } from "./index-CdeDxbNh.js";
2
2
  export { OIDCConfig, OIDCMapping, SAMLConfig, SAMLMapping, SSOOptions, SSOProvider, sso };
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import { t as sso } from "./src-KQzfNIm4.js";
1
+ import { t as sso } from "./src-BEPbgggK.js";
2
2
 
3
3
  export { sso };
@@ -1,13 +1,13 @@
1
+ import { BetterFetchError, betterFetch } from "@better-fetch/fetch";
1
2
  import { generateState } from "better-auth";
2
3
  import { APIError, sessionMiddleware } from "better-auth/api";
4
+ import { setSessionCookie } from "better-auth/cookies";
3
5
  import { createAuthorizationURL, handleOAuthUserInfo, parseState, validateAuthorizationCode, validateToken } from "better-auth/oauth2";
4
6
  import { createAuthEndpoint } from "better-auth/plugins";
5
- import * as z from "zod/v4";
6
- import * as saml from "samlify";
7
- import { BetterFetchError, betterFetch } from "@better-fetch/fetch";
8
- import { decodeJwt } from "jose";
9
- import { setSessionCookie } from "better-auth/cookies";
10
7
  import { XMLValidator } from "fast-xml-parser";
8
+ import { decodeJwt } from "jose";
9
+ import * as saml from "samlify";
10
+ import * as z from "zod/v4";
11
11
 
12
12
  //#region src/index.ts
13
13
  saml.setSchemaValidator({ async validate(xml) {
@@ -21,26 +21,26 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
21
21
  }) : target, mod));
22
22
 
23
23
  //#endregion
24
+ let __better_fetch_fetch = require("@better-fetch/fetch");
25
+ __better_fetch_fetch = __toESM(__better_fetch_fetch);
24
26
  let better_auth = require("better-auth");
25
27
  better_auth = __toESM(better_auth);
26
28
  let better_auth_api = require("better-auth/api");
27
29
  better_auth_api = __toESM(better_auth_api);
30
+ let better_auth_cookies = require("better-auth/cookies");
31
+ better_auth_cookies = __toESM(better_auth_cookies);
28
32
  let better_auth_oauth2 = require("better-auth/oauth2");
29
33
  better_auth_oauth2 = __toESM(better_auth_oauth2);
30
34
  let better_auth_plugins = require("better-auth/plugins");
31
35
  better_auth_plugins = __toESM(better_auth_plugins);
32
- let zod_v4 = require("zod/v4");
33
- zod_v4 = __toESM(zod_v4);
34
- let samlify = require("samlify");
35
- samlify = __toESM(samlify);
36
- let __better_fetch_fetch = require("@better-fetch/fetch");
37
- __better_fetch_fetch = __toESM(__better_fetch_fetch);
38
- let jose = require("jose");
39
- jose = __toESM(jose);
40
- let better_auth_cookies = require("better-auth/cookies");
41
- better_auth_cookies = __toESM(better_auth_cookies);
42
36
  let fast_xml_parser = require("fast-xml-parser");
43
37
  fast_xml_parser = __toESM(fast_xml_parser);
38
+ let jose = require("jose");
39
+ jose = __toESM(jose);
40
+ let samlify = require("samlify");
41
+ samlify = __toESM(samlify);
42
+ let zod_v4 = require("zod/v4");
43
+ zod_v4 = __toESM(zod_v4);
44
44
 
45
45
  //#region src/index.ts
46
46
  samlify.setSchemaValidator({ async validate(xml) {
package/package.json CHANGED
@@ -1,9 +1,15 @@
1
1
  {
2
2
  "name": "@better-auth/sso",
3
3
  "author": "Bereket Engida",
4
- "version": "1.4.0-beta.13",
4
+ "version": "1.4.0-beta.15",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
+ "homepage": "https://www.better-auth.com/docs/plugins/sso",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/better-auth/better-auth",
11
+ "directory": "packages/sso"
12
+ },
7
13
  "license": "MIT",
8
14
  "keywords": [
9
15
  "sso",
@@ -56,15 +62,15 @@
56
62
  },
57
63
  "devDependencies": {
58
64
  "@types/body-parser": "^1.19.6",
59
- "@types/express": "^5.0.3",
65
+ "@types/express": "^5.0.5",
60
66
  "better-call": "1.0.24",
61
67
  "body-parser": "^2.2.0",
62
68
  "express": "^5.1.0",
63
- "tsdown": "^0.15.9",
64
- "better-auth": "^1.4.0-beta.13"
69
+ "tsdown": "^0.15.11",
70
+ "better-auth": "^1.4.0-beta.15"
65
71
  },
66
72
  "peerDependencies": {
67
- "better-auth": "1.4.0-beta.13"
73
+ "better-auth": "1.4.0-beta.15"
68
74
  },
69
75
  "scripts": {
70
76
  "test": "vitest",
package/src/index.ts CHANGED
@@ -1,12 +1,14 @@
1
+ import { BetterFetchError, betterFetch } from "@better-fetch/fetch";
1
2
  import {
2
- generateState,
3
3
  type Account,
4
4
  type BetterAuthPlugin,
5
+ generateState,
5
6
  type OAuth2Tokens,
6
7
  type Session,
7
8
  type User,
8
9
  } from "better-auth";
9
10
  import { APIError, sessionMiddleware } from "better-auth/api";
11
+ import { setSessionCookie } from "better-auth/cookies";
10
12
  import {
11
13
  createAuthorizationURL,
12
14
  handleOAuthUserInfo,
@@ -14,17 +16,14 @@ import {
14
16
  validateAuthorizationCode,
15
17
  validateToken,
16
18
  } from "better-auth/oauth2";
17
-
18
19
  import { createAuthEndpoint } from "better-auth/plugins";
19
- import * as z from "zod/v4";
20
+ import { XMLValidator } from "fast-xml-parser";
21
+ import { decodeJwt } from "jose";
20
22
  import * as saml from "samlify";
21
23
  import type { BindingContext } from "samlify/types/src/entity";
22
- import { betterFetch, BetterFetchError } from "@better-fetch/fetch";
23
- import { decodeJwt } from "jose";
24
- import { setSessionCookie } from "better-auth/cookies";
25
- import type { FlowResult } from "samlify/types/src/flow";
26
- import { XMLValidator } from "fast-xml-parser";
27
24
  import type { IdentityProvider } from "samlify/types/src/entity-idp";
25
+ import type { FlowResult } from "samlify/types/src/flow";
26
+ import * as z from "zod/v4";
28
27
 
29
28
  const fastValidator = {
30
29
  async validate(xml: string) {
@@ -67,22 +66,22 @@ function safeJsonParse<T>(value: string | T | null | undefined): T | null {
67
66
  }
68
67
 
69
68
  export interface OIDCMapping {
70
- id?: string;
71
- email?: string;
72
- emailVerified?: string;
73
- name?: string;
74
- image?: string;
75
- extraFields?: Record<string, string>;
69
+ id?: string | undefined;
70
+ email?: string | undefined;
71
+ emailVerified?: string | undefined;
72
+ name?: string | undefined;
73
+ image?: string | undefined;
74
+ extraFields?: Record<string, string> | undefined;
76
75
  }
77
76
 
78
77
  export interface SAMLMapping {
79
- id?: string;
80
- email?: string;
81
- emailVerified?: string;
82
- name?: string;
83
- firstName?: string;
84
- lastName?: string;
85
- extraFields?: Record<string, string>;
78
+ id?: string | undefined;
79
+ email?: string | undefined;
80
+ emailVerified?: string | undefined;
81
+ name?: string | undefined;
82
+ firstName?: string | undefined;
83
+ lastName?: string | undefined;
84
+ extraFields?: Record<string, string> | undefined;
86
85
  }
87
86
 
88
87
  export interface OIDCConfig {
@@ -90,15 +89,17 @@ export interface OIDCConfig {
90
89
  pkce: boolean;
91
90
  clientId: string;
92
91
  clientSecret: string;
93
- authorizationEndpoint?: string;
92
+ authorizationEndpoint?: string | undefined;
94
93
  discoveryEndpoint: string;
95
- userInfoEndpoint?: string;
96
- scopes?: string[];
97
- overrideUserInfo?: boolean;
98
- tokenEndpoint?: string;
99
- tokenEndpointAuthentication?: "client_secret_post" | "client_secret_basic";
100
- jwksEndpoint?: string;
101
- mapping?: OIDCMapping;
94
+ userInfoEndpoint?: string | undefined;
95
+ scopes?: string[] | undefined;
96
+ overrideUserInfo?: boolean | undefined;
97
+ tokenEndpoint?: string | undefined;
98
+ tokenEndpointAuthentication?:
99
+ | ("client_secret_post" | "client_secret_basic")
100
+ | undefined;
101
+ jwksEndpoint?: string | undefined;
102
+ mapping?: OIDCMapping | undefined;
102
103
  }
103
104
 
104
105
  export interface SAMLConfig {
@@ -106,132 +107,140 @@ export interface SAMLConfig {
106
107
  entryPoint: string;
107
108
  cert: string;
108
109
  callbackUrl: string;
109
- audience?: string;
110
- idpMetadata?: {
111
- metadata?: string;
112
- entityID?: string;
113
- entityURL?: string;
114
- redirectURL?: string;
115
- cert?: string;
116
- privateKey?: string;
117
- privateKeyPass?: string;
118
- isAssertionEncrypted?: boolean;
119
- encPrivateKey?: string;
120
- encPrivateKeyPass?: string;
121
- singleSignOnService?: Array<{
122
- Binding: string;
123
- Location: string;
124
- }>;
125
- };
110
+ audience?: string | undefined;
111
+ idpMetadata?:
112
+ | {
113
+ metadata?: string;
114
+ entityID?: string;
115
+ entityURL?: string;
116
+ redirectURL?: string;
117
+ cert?: string;
118
+ privateKey?: string;
119
+ privateKeyPass?: string;
120
+ isAssertionEncrypted?: boolean;
121
+ encPrivateKey?: string;
122
+ encPrivateKeyPass?: string;
123
+ singleSignOnService?: Array<{
124
+ Binding: string;
125
+ Location: string;
126
+ }>;
127
+ }
128
+ | undefined;
126
129
  spMetadata: {
127
- metadata?: string;
128
- entityID?: string;
129
- binding?: string;
130
- privateKey?: string;
131
- privateKeyPass?: string;
132
- isAssertionEncrypted?: boolean;
133
- encPrivateKey?: string;
134
- encPrivateKeyPass?: string;
130
+ metadata?: string | undefined;
131
+ entityID?: string | undefined;
132
+ binding?: string | undefined;
133
+ privateKey?: string | undefined;
134
+ privateKeyPass?: string | undefined;
135
+ isAssertionEncrypted?: boolean | undefined;
136
+ encPrivateKey?: string | undefined;
137
+ encPrivateKeyPass?: string | undefined;
135
138
  };
136
- wantAssertionsSigned?: boolean;
137
- signatureAlgorithm?: string;
138
- digestAlgorithm?: string;
139
- identifierFormat?: string;
140
- privateKey?: string;
141
- decryptionPvk?: string;
142
- additionalParams?: Record<string, any>;
143
- mapping?: SAMLMapping;
139
+ wantAssertionsSigned?: boolean | undefined;
140
+ signatureAlgorithm?: string | undefined;
141
+ digestAlgorithm?: string | undefined;
142
+ identifierFormat?: string | undefined;
143
+ privateKey?: string | undefined;
144
+ decryptionPvk?: string | undefined;
145
+ additionalParams?: Record<string, any> | undefined;
146
+ mapping?: SAMLMapping | undefined;
144
147
  }
145
148
 
146
149
  export interface SSOProvider {
147
150
  issuer: string;
148
- oidcConfig?: OIDCConfig;
149
- samlConfig?: SAMLConfig;
151
+ oidcConfig?: OIDCConfig | undefined;
152
+ samlConfig?: SAMLConfig | undefined;
150
153
  userId: string;
151
154
  providerId: string;
152
- organizationId?: string;
155
+ organizationId?: string | undefined;
153
156
  }
154
157
 
155
158
  export interface SSOOptions {
156
159
  /**
157
160
  * custom function to provision a user when they sign in with an SSO provider.
158
161
  */
159
- provisionUser?: (data: {
160
- /**
161
- * The user object from the database
162
- */
163
- user: User & Record<string, any>;
164
- /**
165
- * The user info object from the provider
166
- */
167
- userInfo: Record<string, any>;
168
- /**
169
- * The OAuth2 tokens from the provider
170
- */
171
- token?: OAuth2Tokens;
172
- /**
173
- * The SSO provider
174
- */
175
- provider: SSOProvider;
176
- }) => Promise<void>;
162
+ provisionUser?:
163
+ | ((data: {
164
+ /**
165
+ * The user object from the database
166
+ */
167
+ user: User & Record<string, any>;
168
+ /**
169
+ * The user info object from the provider
170
+ */
171
+ userInfo: Record<string, any>;
172
+ /**
173
+ * The OAuth2 tokens from the provider
174
+ */
175
+ token?: OAuth2Tokens;
176
+ /**
177
+ * The SSO provider
178
+ */
179
+ provider: SSOProvider;
180
+ }) => Promise<void>)
181
+ | undefined;
177
182
  /**
178
183
  * Organization provisioning options
179
184
  */
180
- organizationProvisioning?: {
181
- disabled?: boolean;
182
- defaultRole?: "member" | "admin";
183
- getRole?: (data: {
184
- /**
185
- * The user object from the database
186
- */
187
- user: User & Record<string, any>;
188
- /**
189
- * The user info object from the provider
190
- */
191
- userInfo: Record<string, any>;
192
- /**
193
- * The OAuth2 tokens from the provider
194
- */
195
- token?: OAuth2Tokens;
196
- /**
197
- * The SSO provider
198
- */
199
- provider: SSOProvider;
200
- }) => Promise<"member" | "admin">;
201
- };
185
+ organizationProvisioning?:
186
+ | {
187
+ disabled?: boolean;
188
+ defaultRole?: "member" | "admin";
189
+ getRole?: (data: {
190
+ /**
191
+ * The user object from the database
192
+ */
193
+ user: User & Record<string, any>;
194
+ /**
195
+ * The user info object from the provider
196
+ */
197
+ userInfo: Record<string, any>;
198
+ /**
199
+ * The OAuth2 tokens from the provider
200
+ */
201
+ token?: OAuth2Tokens;
202
+ /**
203
+ * The SSO provider
204
+ */
205
+ provider: SSOProvider;
206
+ }) => Promise<"member" | "admin">;
207
+ }
208
+ | undefined;
202
209
  /**
203
210
  * Default SSO provider configurations for testing.
204
211
  * These will take the precedence over the database providers.
205
212
  */
206
- defaultSSO?: Array<{
207
- /**
208
- * The domain to match for this default provider.
209
- * This is only used to match incoming requests to this default provider.
210
- */
211
- domain: string;
212
- /**
213
- * The provider ID to use
214
- */
215
- providerId: string;
216
- /**
217
- * SAML configuration
218
- */
219
- samlConfig?: SAMLConfig;
220
- /**
221
- * OIDC configuration
222
- */
223
- oidcConfig?: OIDCConfig;
224
- }>;
213
+ defaultSSO?:
214
+ | Array<{
215
+ /**
216
+ * The domain to match for this default provider.
217
+ * This is only used to match incoming requests to this default provider.
218
+ */
219
+ domain: string;
220
+ /**
221
+ * The provider ID to use
222
+ */
223
+ providerId: string;
224
+ /**
225
+ * SAML configuration
226
+ */
227
+ samlConfig?: SAMLConfig;
228
+ /**
229
+ * OIDC configuration
230
+ */
231
+ oidcConfig?: OIDCConfig;
232
+ }>
233
+ | undefined;
225
234
  /**
226
235
  * Override user info with the provider info.
227
236
  * @default false
228
237
  */
229
- defaultOverrideUserInfo?: boolean;
238
+ defaultOverrideUserInfo?: boolean | undefined;
230
239
  /**
231
240
  * Disable implicit sign up for new users. When set to true for the provider,
232
241
  * sign-in need to be called with with requestSignUp as true to create new users.
233
242
  */
234
- disableImplicitSignUp?: boolean;
243
+ disableImplicitSignUp?: boolean | undefined;
235
244
  /**
236
245
  * Configure the maximum number of SSO providers a user can register.
237
246
  * You can also pass a function that returns a number.
@@ -246,15 +255,17 @@ export interface SSOOptions {
246
255
  * ```
247
256
  * @default 10
248
257
  */
249
- providersLimit?: number | ((user: User) => Promise<number> | number);
258
+ providersLimit?:
259
+ | (number | ((user: User) => Promise<number> | number))
260
+ | undefined;
250
261
  /**
251
262
  * Trust the email verified flag from the provider.
252
263
  * @default false
253
264
  */
254
- trustEmailVerified?: boolean;
265
+ trustEmailVerified?: boolean | undefined;
255
266
  }
256
267
 
257
- export const sso = (options?: SSOOptions) => {
268
+ export const sso = (options?: SSOOptions | undefined) => {
258
269
  return {
259
270
  id: "sso",
260
271
  endpoints: {
package/src/oidc.test.ts CHANGED
@@ -1,10 +1,10 @@
1
- import { afterAll, beforeAll, describe, expect, it } from "vitest";
2
- import { getTestInstanceMemory as getTestInstance } from "better-auth/test";
3
- import { sso } from ".";
4
- import { OAuth2Server } from "oauth2-mock-server";
5
1
  import { betterFetch } from "@better-fetch/fetch";
6
- import { organization } from "better-auth/plugins";
7
2
  import { createAuthClient } from "better-auth/client";
3
+ import { organization } from "better-auth/plugins";
4
+ import { getTestInstanceMemory as getTestInstance } from "better-auth/test";
5
+ import { OAuth2Server } from "oauth2-mock-server";
6
+ import { afterAll, beforeAll, describe, expect, it } from "vitest";
7
+ import { sso } from ".";
8
8
  import { ssoClient } from "./client";
9
9
 
10
10
  let server = new OAuth2Server();
package/src/saml.test.ts CHANGED
@@ -1,31 +1,31 @@
1
- import {
2
- afterAll,
3
- beforeAll,
4
- beforeEach,
5
- describe,
6
- expect,
7
- it,
8
- vi,
9
- } from "vitest";
1
+ import { betterFetch } from "@better-fetch/fetch";
10
2
  import { betterAuth } from "better-auth";
11
3
  import { memoryAdapter } from "better-auth/adapters/memory";
12
4
  import { createAuthClient } from "better-auth/client";
13
- import { betterFetch } from "@better-fetch/fetch";
14
5
  import { setCookieToHeader } from "better-auth/cookies";
15
6
  import { bearer } from "better-auth/plugins";
16
- import { sso } from ".";
17
- import { ssoClient } from "./client";
18
- import { createServer } from "http";
19
- import * as saml from "samlify";
7
+ import { getTestInstanceMemory } from "better-auth/test";
8
+ import bodyParser from "body-parser";
9
+ import { randomUUID } from "crypto";
20
10
  import type {
21
11
  Application as ExpressApp,
22
12
  Request as ExpressRequest,
23
13
  Response as ExpressResponse,
24
14
  } from "express";
25
15
  import express from "express";
26
- import bodyParser from "body-parser";
27
- import { randomUUID } from "crypto";
28
- import { getTestInstanceMemory } from "better-auth/test";
16
+ import { createServer } from "http";
17
+ import * as saml from "samlify";
18
+ import {
19
+ afterAll,
20
+ beforeAll,
21
+ beforeEach,
22
+ describe,
23
+ expect,
24
+ it,
25
+ vi,
26
+ } from "vitest";
27
+ import { sso } from ".";
28
+ import { ssoClient } from "./client";
29
29
 
30
30
  const spMetadata = `
31
31
  <md:EntityDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata" entityID="http://localhost:3001/api/sso/saml2/sp/metadata">