@better-auth/sso 1.4.0-beta.19 → 1.4.0-beta.20

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/src/types.ts ADDED
@@ -0,0 +1,208 @@
1
+ import type { OAuth2Tokens, User } from "better-auth";
2
+
3
+ export interface OIDCMapping {
4
+ id?: string | undefined;
5
+ email?: string | undefined;
6
+ emailVerified?: string | undefined;
7
+ name?: string | undefined;
8
+ image?: string | undefined;
9
+ extraFields?: Record<string, string> | undefined;
10
+ }
11
+
12
+ export interface SAMLMapping {
13
+ id?: string | undefined;
14
+ email?: string | undefined;
15
+ emailVerified?: string | undefined;
16
+ name?: string | undefined;
17
+ firstName?: string | undefined;
18
+ lastName?: string | undefined;
19
+ extraFields?: Record<string, string> | undefined;
20
+ }
21
+
22
+ export interface OIDCConfig {
23
+ issuer: string;
24
+ pkce: boolean;
25
+ clientId: string;
26
+ clientSecret: string;
27
+ authorizationEndpoint?: string | undefined;
28
+ discoveryEndpoint: string;
29
+ userInfoEndpoint?: string | undefined;
30
+ scopes?: string[] | undefined;
31
+ overrideUserInfo?: boolean | undefined;
32
+ tokenEndpoint?: string | undefined;
33
+ tokenEndpointAuthentication?:
34
+ | ("client_secret_post" | "client_secret_basic")
35
+ | undefined;
36
+ jwksEndpoint?: string | undefined;
37
+ mapping?: OIDCMapping | undefined;
38
+ }
39
+
40
+ export interface SAMLConfig {
41
+ issuer: string;
42
+ entryPoint: string;
43
+ cert: string;
44
+ callbackUrl: string;
45
+ audience?: string | undefined;
46
+ idpMetadata?:
47
+ | {
48
+ metadata?: string;
49
+ entityID?: string;
50
+ entityURL?: string;
51
+ redirectURL?: string;
52
+ cert?: string;
53
+ privateKey?: string;
54
+ privateKeyPass?: string;
55
+ isAssertionEncrypted?: boolean;
56
+ encPrivateKey?: string;
57
+ encPrivateKeyPass?: string;
58
+ singleSignOnService?: Array<{
59
+ Binding: string;
60
+ Location: string;
61
+ }>;
62
+ }
63
+ | undefined;
64
+ spMetadata: {
65
+ metadata?: string | undefined;
66
+ entityID?: string | undefined;
67
+ binding?: string | undefined;
68
+ privateKey?: string | undefined;
69
+ privateKeyPass?: string | undefined;
70
+ isAssertionEncrypted?: boolean | undefined;
71
+ encPrivateKey?: string | undefined;
72
+ encPrivateKeyPass?: string | undefined;
73
+ };
74
+ wantAssertionsSigned?: boolean | undefined;
75
+ signatureAlgorithm?: string | undefined;
76
+ digestAlgorithm?: string | undefined;
77
+ identifierFormat?: string | undefined;
78
+ privateKey?: string | undefined;
79
+ decryptionPvk?: string | undefined;
80
+ additionalParams?: Record<string, any> | undefined;
81
+ mapping?: SAMLMapping | undefined;
82
+ }
83
+
84
+ export type SSOProvider = {
85
+ issuer: string;
86
+ oidcConfig?: OIDCConfig | undefined;
87
+ samlConfig?: SAMLConfig | undefined;
88
+ userId: string;
89
+ providerId: string;
90
+ organizationId?: string | undefined;
91
+ domain: string;
92
+ };
93
+
94
+ export interface SSOOptions {
95
+ /**
96
+ * custom function to provision a user when they sign in with an SSO provider.
97
+ */
98
+ provisionUser?:
99
+ | ((data: {
100
+ /**
101
+ * The user object from the database
102
+ */
103
+ user: User & Record<string, any>;
104
+ /**
105
+ * The user info object from the provider
106
+ */
107
+ userInfo: Record<string, any>;
108
+ /**
109
+ * The OAuth2 tokens from the provider
110
+ */
111
+ token?: OAuth2Tokens;
112
+ /**
113
+ * The SSO provider
114
+ */
115
+ provider: SSOProvider;
116
+ }) => Promise<void>)
117
+ | undefined;
118
+ /**
119
+ * Organization provisioning options
120
+ */
121
+ organizationProvisioning?:
122
+ | {
123
+ disabled?: boolean;
124
+ defaultRole?: "member" | "admin";
125
+ getRole?: (data: {
126
+ /**
127
+ * The user object from the database
128
+ */
129
+ user: User & Record<string, any>;
130
+ /**
131
+ * The user info object from the provider
132
+ */
133
+ userInfo: Record<string, any>;
134
+ /**
135
+ * The OAuth2 tokens from the provider
136
+ */
137
+ token?: OAuth2Tokens;
138
+ /**
139
+ * The SSO provider
140
+ */
141
+ provider: SSOProvider;
142
+ }) => Promise<"member" | "admin">;
143
+ }
144
+ | undefined;
145
+ /**
146
+ * Default SSO provider configurations for testing.
147
+ * These will take the precedence over the database providers.
148
+ */
149
+ defaultSSO?:
150
+ | Array<{
151
+ /**
152
+ * The domain to match for this default provider.
153
+ * This is only used to match incoming requests to this default provider.
154
+ */
155
+ domain: string;
156
+ /**
157
+ * The provider ID to use
158
+ */
159
+ providerId: string;
160
+ /**
161
+ * SAML configuration
162
+ */
163
+ samlConfig?: SAMLConfig;
164
+ /**
165
+ * OIDC configuration
166
+ */
167
+ oidcConfig?: OIDCConfig;
168
+ }>
169
+ | undefined;
170
+ /**
171
+ * Override user info with the provider info.
172
+ * @default false
173
+ */
174
+ defaultOverrideUserInfo?: boolean | undefined;
175
+ /**
176
+ * Disable implicit sign up for new users. When set to true for the provider,
177
+ * sign-in need to be called with with requestSignUp as true to create new users.
178
+ */
179
+ disableImplicitSignUp?: boolean | undefined;
180
+ /**
181
+ * Configure the maximum number of SSO providers a user can register.
182
+ * You can also pass a function that returns a number.
183
+ * Set to 0 to disable SSO provider registration.
184
+ *
185
+ * @example
186
+ * ```ts
187
+ * providersLimit: async (user) => {
188
+ * const plan = await getUserPlan(user);
189
+ * return plan.name === "pro" ? 10 : 1;
190
+ * }
191
+ * ```
192
+ * @default 10
193
+ */
194
+ providersLimit?:
195
+ | (number | ((user: User) => Promise<number> | number))
196
+ | undefined;
197
+ /**
198
+ * Trust the email verified flag from the provider.
199
+ *
200
+ * ⚠️ Use this with caution — it can lead to account takeover if misused. Only enable it if users **cannot freely register new providers**. You can
201
+ * prevent that by using `disabledPaths` or other safeguards to block provider registration from the client.
202
+ *
203
+ * If you want to allow account linking for specific trusted providers, enable the `accountLinking` option in your auth config and specify those
204
+ * providers in the `trustedProviders` list.
205
+ * @default false
206
+ */
207
+ trustEmailVerified?: boolean | undefined;
208
+ }