@better-auth/sso 1.3.27 → 1.4.0-beta.10
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 +23 -15
- package/dist/client.cjs +8 -6
- package/dist/client.d.cts +6 -8
- package/dist/client.d.ts +6 -8
- package/dist/client.js +12 -0
- package/dist/index-D0i1jHBp.d.cts +959 -0
- package/dist/index-Drgwy6ZL.d.ts +959 -0
- package/dist/index.cjs +2 -1671
- package/dist/index.d.cts +2 -959
- package/dist/index.d.ts +2 -959
- package/dist/index.js +3 -0
- package/dist/src-DLLHZrD9.cjs +1250 -0
- package/dist/src-DrA9mJEu.js +1212 -0
- package/package.json +11 -10
- package/tsdown.config.ts +8 -0
- package/build.config.ts +0 -12
- package/dist/client.d.mts +0 -11
- package/dist/client.mjs +0 -8
- package/dist/index.d.mts +0 -959
- package/dist/index.mjs +0 -1655
|
@@ -0,0 +1,1212 @@
|
|
|
1
|
+
import { generateState } from "better-auth";
|
|
2
|
+
import { APIError, sessionMiddleware } from "better-auth/api";
|
|
3
|
+
import { createAuthorizationURL, handleOAuthUserInfo, parseState, validateAuthorizationCode, validateToken } from "better-auth/oauth2";
|
|
4
|
+
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
|
+
import { XMLValidator } from "fast-xml-parser";
|
|
11
|
+
|
|
12
|
+
//#region src/index.ts
|
|
13
|
+
saml.setSchemaValidator({ async validate(xml) {
|
|
14
|
+
if (XMLValidator.validate(xml, { allowBooleanAttributes: true }) === true) return "SUCCESS_VALIDATE_XML";
|
|
15
|
+
throw "ERR_INVALID_XML";
|
|
16
|
+
} });
|
|
17
|
+
/**
|
|
18
|
+
* Safely parses a value that might be a JSON string or already a parsed object
|
|
19
|
+
* This handles cases where ORMs like Drizzle might return already parsed objects
|
|
20
|
+
* instead of JSON strings from TEXT/JSON columns
|
|
21
|
+
*/
|
|
22
|
+
function safeJsonParse(value) {
|
|
23
|
+
if (!value) return null;
|
|
24
|
+
if (typeof value === "object") return value;
|
|
25
|
+
if (typeof value === "string") try {
|
|
26
|
+
return JSON.parse(value);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
throw new Error(`Failed to parse JSON: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
const sso = (options) => {
|
|
33
|
+
return {
|
|
34
|
+
id: "sso",
|
|
35
|
+
endpoints: {
|
|
36
|
+
spMetadata: createAuthEndpoint("/sso/saml2/sp/metadata", {
|
|
37
|
+
method: "GET",
|
|
38
|
+
query: z.object({
|
|
39
|
+
providerId: z.string(),
|
|
40
|
+
format: z.enum(["xml", "json"]).default("xml")
|
|
41
|
+
}),
|
|
42
|
+
metadata: { openapi: {
|
|
43
|
+
summary: "Get Service Provider metadata",
|
|
44
|
+
description: "Returns the SAML metadata for the Service Provider",
|
|
45
|
+
responses: { "200": { description: "SAML metadata in XML format" } }
|
|
46
|
+
} }
|
|
47
|
+
}, async (ctx) => {
|
|
48
|
+
const provider = await ctx.context.adapter.findOne({
|
|
49
|
+
model: "ssoProvider",
|
|
50
|
+
where: [{
|
|
51
|
+
field: "providerId",
|
|
52
|
+
value: ctx.query.providerId
|
|
53
|
+
}]
|
|
54
|
+
});
|
|
55
|
+
if (!provider) throw new APIError("NOT_FOUND", { message: "No provider found for the given providerId" });
|
|
56
|
+
const parsedSamlConfig = safeJsonParse(provider.samlConfig);
|
|
57
|
+
if (!parsedSamlConfig) throw new APIError("BAD_REQUEST", { message: "Invalid SAML configuration" });
|
|
58
|
+
const sp = parsedSamlConfig.spMetadata.metadata ? saml.ServiceProvider({ metadata: parsedSamlConfig.spMetadata.metadata }) : saml.SPMetadata({
|
|
59
|
+
entityID: parsedSamlConfig.spMetadata?.entityID || parsedSamlConfig.issuer,
|
|
60
|
+
assertionConsumerService: [{
|
|
61
|
+
Binding: "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST",
|
|
62
|
+
Location: parsedSamlConfig.callbackUrl || `${ctx.context.baseURL}/sso/saml2/sp/acs/${provider.id}`
|
|
63
|
+
}],
|
|
64
|
+
wantMessageSigned: parsedSamlConfig.wantAssertionsSigned || false,
|
|
65
|
+
nameIDFormat: parsedSamlConfig.identifierFormat ? [parsedSamlConfig.identifierFormat] : void 0
|
|
66
|
+
});
|
|
67
|
+
return new Response(sp.getMetadata(), { headers: { "Content-Type": "application/xml" } });
|
|
68
|
+
}),
|
|
69
|
+
registerSSOProvider: createAuthEndpoint("/sso/register", {
|
|
70
|
+
method: "POST",
|
|
71
|
+
body: z.object({
|
|
72
|
+
providerId: z.string({}).meta({ description: "The ID of the provider. This is used to identify the provider during login and callback" }),
|
|
73
|
+
issuer: z.string({}).meta({ description: "The issuer of the provider" }),
|
|
74
|
+
domain: z.string({}).meta({ description: "The domain of the provider. This is used for email matching" }),
|
|
75
|
+
oidcConfig: z.object({
|
|
76
|
+
clientId: z.string({}).meta({ description: "The client ID" }),
|
|
77
|
+
clientSecret: z.string({}).meta({ description: "The client secret" }),
|
|
78
|
+
authorizationEndpoint: z.string({}).meta({ description: "The authorization endpoint" }).optional(),
|
|
79
|
+
tokenEndpoint: z.string({}).meta({ description: "The token endpoint" }).optional(),
|
|
80
|
+
userInfoEndpoint: z.string({}).meta({ description: "The user info endpoint" }).optional(),
|
|
81
|
+
tokenEndpointAuthentication: z.enum(["client_secret_post", "client_secret_basic"]).optional(),
|
|
82
|
+
jwksEndpoint: z.string({}).meta({ description: "The JWKS endpoint" }).optional(),
|
|
83
|
+
discoveryEndpoint: z.string().optional(),
|
|
84
|
+
scopes: z.array(z.string(), {}).meta({ description: "The scopes to request. Defaults to ['openid', 'email', 'profile', 'offline_access']" }).optional(),
|
|
85
|
+
pkce: z.boolean({}).meta({ description: "Whether to use PKCE for the authorization flow" }).default(true).optional(),
|
|
86
|
+
mapping: z.object({
|
|
87
|
+
id: z.string({}).meta({ description: "Field mapping for user ID (defaults to 'sub')" }),
|
|
88
|
+
email: z.string({}).meta({ description: "Field mapping for email (defaults to 'email')" }),
|
|
89
|
+
emailVerified: z.string({}).meta({ description: "Field mapping for email verification (defaults to 'email_verified')" }).optional(),
|
|
90
|
+
name: z.string({}).meta({ description: "Field mapping for name (defaults to 'name')" }),
|
|
91
|
+
image: z.string({}).meta({ description: "Field mapping for image (defaults to 'picture')" }).optional(),
|
|
92
|
+
extraFields: z.record(z.string(), z.any()).optional()
|
|
93
|
+
}).optional()
|
|
94
|
+
}).optional(),
|
|
95
|
+
samlConfig: z.object({
|
|
96
|
+
entryPoint: z.string({}).meta({ description: "The entry point of the provider" }),
|
|
97
|
+
cert: z.string({}).meta({ description: "The certificate of the provider" }),
|
|
98
|
+
callbackUrl: z.string({}).meta({ description: "The callback URL of the provider" }),
|
|
99
|
+
audience: z.string().optional(),
|
|
100
|
+
idpMetadata: z.object({
|
|
101
|
+
metadata: z.string().optional(),
|
|
102
|
+
entityID: z.string().optional(),
|
|
103
|
+
cert: z.string().optional(),
|
|
104
|
+
privateKey: z.string().optional(),
|
|
105
|
+
privateKeyPass: z.string().optional(),
|
|
106
|
+
isAssertionEncrypted: z.boolean().optional(),
|
|
107
|
+
encPrivateKey: z.string().optional(),
|
|
108
|
+
encPrivateKeyPass: z.string().optional(),
|
|
109
|
+
singleSignOnService: z.array(z.object({
|
|
110
|
+
Binding: z.string().meta({ description: "The binding type for the SSO service" }),
|
|
111
|
+
Location: z.string().meta({ description: "The URL for the SSO service" })
|
|
112
|
+
})).optional().meta({ description: "Single Sign-On service configuration" })
|
|
113
|
+
}).optional(),
|
|
114
|
+
spMetadata: z.object({
|
|
115
|
+
metadata: z.string().optional(),
|
|
116
|
+
entityID: z.string().optional(),
|
|
117
|
+
binding: z.string().optional(),
|
|
118
|
+
privateKey: z.string().optional(),
|
|
119
|
+
privateKeyPass: z.string().optional(),
|
|
120
|
+
isAssertionEncrypted: z.boolean().optional(),
|
|
121
|
+
encPrivateKey: z.string().optional(),
|
|
122
|
+
encPrivateKeyPass: z.string().optional()
|
|
123
|
+
}),
|
|
124
|
+
wantAssertionsSigned: z.boolean().optional(),
|
|
125
|
+
signatureAlgorithm: z.string().optional(),
|
|
126
|
+
digestAlgorithm: z.string().optional(),
|
|
127
|
+
identifierFormat: z.string().optional(),
|
|
128
|
+
privateKey: z.string().optional(),
|
|
129
|
+
decryptionPvk: z.string().optional(),
|
|
130
|
+
additionalParams: z.record(z.string(), z.any()).optional(),
|
|
131
|
+
mapping: z.object({
|
|
132
|
+
id: z.string({}).meta({ description: "Field mapping for user ID (defaults to 'nameID')" }),
|
|
133
|
+
email: z.string({}).meta({ description: "Field mapping for email (defaults to 'email')" }),
|
|
134
|
+
emailVerified: z.string({}).meta({ description: "Field mapping for email verification" }).optional(),
|
|
135
|
+
name: z.string({}).meta({ description: "Field mapping for name (defaults to 'displayName')" }),
|
|
136
|
+
firstName: z.string({}).meta({ description: "Field mapping for first name (defaults to 'givenName')" }).optional(),
|
|
137
|
+
lastName: z.string({}).meta({ description: "Field mapping for last name (defaults to 'surname')" }).optional(),
|
|
138
|
+
extraFields: z.record(z.string(), z.any()).optional()
|
|
139
|
+
}).optional()
|
|
140
|
+
}).optional(),
|
|
141
|
+
organizationId: z.string({}).meta({ description: "If organization plugin is enabled, the organization id to link the provider to" }).optional(),
|
|
142
|
+
overrideUserInfo: z.boolean({}).meta({ description: "Override user info with the provider info. Defaults to false" }).default(false).optional()
|
|
143
|
+
}),
|
|
144
|
+
use: [sessionMiddleware],
|
|
145
|
+
metadata: { openapi: {
|
|
146
|
+
summary: "Register an OIDC provider",
|
|
147
|
+
description: "This endpoint is used to register an OIDC provider. This is used to configure the provider and link it to an organization",
|
|
148
|
+
responses: { "200": {
|
|
149
|
+
description: "OIDC provider created successfully",
|
|
150
|
+
content: { "application/json": { schema: {
|
|
151
|
+
type: "object",
|
|
152
|
+
properties: {
|
|
153
|
+
issuer: {
|
|
154
|
+
type: "string",
|
|
155
|
+
format: "uri",
|
|
156
|
+
description: "The issuer URL of the provider"
|
|
157
|
+
},
|
|
158
|
+
domain: {
|
|
159
|
+
type: "string",
|
|
160
|
+
description: "The domain of the provider, used for email matching"
|
|
161
|
+
},
|
|
162
|
+
oidcConfig: {
|
|
163
|
+
type: "object",
|
|
164
|
+
properties: {
|
|
165
|
+
issuer: {
|
|
166
|
+
type: "string",
|
|
167
|
+
format: "uri",
|
|
168
|
+
description: "The issuer URL of the provider"
|
|
169
|
+
},
|
|
170
|
+
pkce: {
|
|
171
|
+
type: "boolean",
|
|
172
|
+
description: "Whether PKCE is enabled for the authorization flow"
|
|
173
|
+
},
|
|
174
|
+
clientId: {
|
|
175
|
+
type: "string",
|
|
176
|
+
description: "The client ID for the provider"
|
|
177
|
+
},
|
|
178
|
+
clientSecret: {
|
|
179
|
+
type: "string",
|
|
180
|
+
description: "The client secret for the provider"
|
|
181
|
+
},
|
|
182
|
+
authorizationEndpoint: {
|
|
183
|
+
type: "string",
|
|
184
|
+
format: "uri",
|
|
185
|
+
nullable: true,
|
|
186
|
+
description: "The authorization endpoint URL"
|
|
187
|
+
},
|
|
188
|
+
discoveryEndpoint: {
|
|
189
|
+
type: "string",
|
|
190
|
+
format: "uri",
|
|
191
|
+
description: "The discovery endpoint URL"
|
|
192
|
+
},
|
|
193
|
+
userInfoEndpoint: {
|
|
194
|
+
type: "string",
|
|
195
|
+
format: "uri",
|
|
196
|
+
nullable: true,
|
|
197
|
+
description: "The user info endpoint URL"
|
|
198
|
+
},
|
|
199
|
+
scopes: {
|
|
200
|
+
type: "array",
|
|
201
|
+
items: { type: "string" },
|
|
202
|
+
nullable: true,
|
|
203
|
+
description: "The scopes requested from the provider"
|
|
204
|
+
},
|
|
205
|
+
tokenEndpoint: {
|
|
206
|
+
type: "string",
|
|
207
|
+
format: "uri",
|
|
208
|
+
nullable: true,
|
|
209
|
+
description: "The token endpoint URL"
|
|
210
|
+
},
|
|
211
|
+
tokenEndpointAuthentication: {
|
|
212
|
+
type: "string",
|
|
213
|
+
enum: ["client_secret_post", "client_secret_basic"],
|
|
214
|
+
nullable: true,
|
|
215
|
+
description: "Authentication method for the token endpoint"
|
|
216
|
+
},
|
|
217
|
+
jwksEndpoint: {
|
|
218
|
+
type: "string",
|
|
219
|
+
format: "uri",
|
|
220
|
+
nullable: true,
|
|
221
|
+
description: "The JWKS endpoint URL"
|
|
222
|
+
},
|
|
223
|
+
mapping: {
|
|
224
|
+
type: "object",
|
|
225
|
+
nullable: true,
|
|
226
|
+
properties: {
|
|
227
|
+
id: {
|
|
228
|
+
type: "string",
|
|
229
|
+
description: "Field mapping for user ID (defaults to 'sub')"
|
|
230
|
+
},
|
|
231
|
+
email: {
|
|
232
|
+
type: "string",
|
|
233
|
+
description: "Field mapping for email (defaults to 'email')"
|
|
234
|
+
},
|
|
235
|
+
emailVerified: {
|
|
236
|
+
type: "string",
|
|
237
|
+
nullable: true,
|
|
238
|
+
description: "Field mapping for email verification (defaults to 'email_verified')"
|
|
239
|
+
},
|
|
240
|
+
name: {
|
|
241
|
+
type: "string",
|
|
242
|
+
description: "Field mapping for name (defaults to 'name')"
|
|
243
|
+
},
|
|
244
|
+
image: {
|
|
245
|
+
type: "string",
|
|
246
|
+
nullable: true,
|
|
247
|
+
description: "Field mapping for image (defaults to 'picture')"
|
|
248
|
+
},
|
|
249
|
+
extraFields: {
|
|
250
|
+
type: "object",
|
|
251
|
+
additionalProperties: { type: "string" },
|
|
252
|
+
nullable: true,
|
|
253
|
+
description: "Additional field mappings"
|
|
254
|
+
}
|
|
255
|
+
},
|
|
256
|
+
required: [
|
|
257
|
+
"id",
|
|
258
|
+
"email",
|
|
259
|
+
"name"
|
|
260
|
+
]
|
|
261
|
+
}
|
|
262
|
+
},
|
|
263
|
+
required: [
|
|
264
|
+
"issuer",
|
|
265
|
+
"pkce",
|
|
266
|
+
"clientId",
|
|
267
|
+
"clientSecret",
|
|
268
|
+
"discoveryEndpoint"
|
|
269
|
+
],
|
|
270
|
+
description: "OIDC configuration for the provider"
|
|
271
|
+
},
|
|
272
|
+
organizationId: {
|
|
273
|
+
type: "string",
|
|
274
|
+
nullable: true,
|
|
275
|
+
description: "ID of the linked organization, if any"
|
|
276
|
+
},
|
|
277
|
+
userId: {
|
|
278
|
+
type: "string",
|
|
279
|
+
description: "ID of the user who registered the provider"
|
|
280
|
+
},
|
|
281
|
+
providerId: {
|
|
282
|
+
type: "string",
|
|
283
|
+
description: "Unique identifier for the provider"
|
|
284
|
+
},
|
|
285
|
+
redirectURI: {
|
|
286
|
+
type: "string",
|
|
287
|
+
format: "uri",
|
|
288
|
+
description: "The redirect URI for the provider callback"
|
|
289
|
+
}
|
|
290
|
+
},
|
|
291
|
+
required: [
|
|
292
|
+
"issuer",
|
|
293
|
+
"domain",
|
|
294
|
+
"oidcConfig",
|
|
295
|
+
"userId",
|
|
296
|
+
"providerId",
|
|
297
|
+
"redirectURI"
|
|
298
|
+
]
|
|
299
|
+
} } }
|
|
300
|
+
} }
|
|
301
|
+
} }
|
|
302
|
+
}, async (ctx) => {
|
|
303
|
+
const user = ctx.context.session?.user;
|
|
304
|
+
if (!user) throw new APIError("UNAUTHORIZED");
|
|
305
|
+
const limit = typeof options?.providersLimit === "function" ? await options.providersLimit(user) : options?.providersLimit ?? 10;
|
|
306
|
+
if (!limit) throw new APIError("FORBIDDEN", { message: "SSO provider registration is disabled" });
|
|
307
|
+
if ((await ctx.context.adapter.findMany({
|
|
308
|
+
model: "ssoProvider",
|
|
309
|
+
where: [{
|
|
310
|
+
field: "userId",
|
|
311
|
+
value: user.id
|
|
312
|
+
}]
|
|
313
|
+
})).length >= limit) throw new APIError("FORBIDDEN", { message: "You have reached the maximum number of SSO providers" });
|
|
314
|
+
const body = ctx.body;
|
|
315
|
+
if (z.string().url().safeParse(body.issuer).error) throw new APIError("BAD_REQUEST", { message: "Invalid issuer. Must be a valid URL" });
|
|
316
|
+
if (ctx.body.organizationId) {
|
|
317
|
+
if (!await ctx.context.adapter.findOne({
|
|
318
|
+
model: "member",
|
|
319
|
+
where: [{
|
|
320
|
+
field: "userId",
|
|
321
|
+
value: user.id
|
|
322
|
+
}, {
|
|
323
|
+
field: "organizationId",
|
|
324
|
+
value: ctx.body.organizationId
|
|
325
|
+
}]
|
|
326
|
+
})) throw new APIError("BAD_REQUEST", { message: "You are not a member of the organization" });
|
|
327
|
+
}
|
|
328
|
+
if (await ctx.context.adapter.findOne({
|
|
329
|
+
model: "ssoProvider",
|
|
330
|
+
where: [{
|
|
331
|
+
field: "providerId",
|
|
332
|
+
value: body.providerId
|
|
333
|
+
}]
|
|
334
|
+
})) {
|
|
335
|
+
ctx.context.logger.info(`SSO provider creation attempt with existing providerId: ${body.providerId}`);
|
|
336
|
+
throw new APIError("UNPROCESSABLE_ENTITY", { message: "SSO provider with this providerId already exists" });
|
|
337
|
+
}
|
|
338
|
+
const provider = await ctx.context.adapter.create({
|
|
339
|
+
model: "ssoProvider",
|
|
340
|
+
data: {
|
|
341
|
+
issuer: body.issuer,
|
|
342
|
+
domain: body.domain,
|
|
343
|
+
oidcConfig: body.oidcConfig ? JSON.stringify({
|
|
344
|
+
issuer: body.issuer,
|
|
345
|
+
clientId: body.oidcConfig.clientId,
|
|
346
|
+
clientSecret: body.oidcConfig.clientSecret,
|
|
347
|
+
authorizationEndpoint: body.oidcConfig.authorizationEndpoint,
|
|
348
|
+
tokenEndpoint: body.oidcConfig.tokenEndpoint,
|
|
349
|
+
tokenEndpointAuthentication: body.oidcConfig.tokenEndpointAuthentication,
|
|
350
|
+
jwksEndpoint: body.oidcConfig.jwksEndpoint,
|
|
351
|
+
pkce: body.oidcConfig.pkce,
|
|
352
|
+
discoveryEndpoint: body.oidcConfig.discoveryEndpoint || `${body.issuer}/.well-known/openid-configuration`,
|
|
353
|
+
mapping: body.oidcConfig.mapping,
|
|
354
|
+
scopes: body.oidcConfig.scopes,
|
|
355
|
+
userInfoEndpoint: body.oidcConfig.userInfoEndpoint,
|
|
356
|
+
overrideUserInfo: ctx.body.overrideUserInfo || options?.defaultOverrideUserInfo || false
|
|
357
|
+
}) : null,
|
|
358
|
+
samlConfig: body.samlConfig ? JSON.stringify({
|
|
359
|
+
issuer: body.issuer,
|
|
360
|
+
entryPoint: body.samlConfig.entryPoint,
|
|
361
|
+
cert: body.samlConfig.cert,
|
|
362
|
+
callbackUrl: body.samlConfig.callbackUrl,
|
|
363
|
+
audience: body.samlConfig.audience,
|
|
364
|
+
idpMetadata: body.samlConfig.idpMetadata,
|
|
365
|
+
spMetadata: body.samlConfig.spMetadata,
|
|
366
|
+
wantAssertionsSigned: body.samlConfig.wantAssertionsSigned,
|
|
367
|
+
signatureAlgorithm: body.samlConfig.signatureAlgorithm,
|
|
368
|
+
digestAlgorithm: body.samlConfig.digestAlgorithm,
|
|
369
|
+
identifierFormat: body.samlConfig.identifierFormat,
|
|
370
|
+
privateKey: body.samlConfig.privateKey,
|
|
371
|
+
decryptionPvk: body.samlConfig.decryptionPvk,
|
|
372
|
+
additionalParams: body.samlConfig.additionalParams,
|
|
373
|
+
mapping: body.samlConfig.mapping
|
|
374
|
+
}) : null,
|
|
375
|
+
organizationId: body.organizationId,
|
|
376
|
+
userId: ctx.context.session.user.id,
|
|
377
|
+
providerId: body.providerId
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
return ctx.json({
|
|
381
|
+
...provider,
|
|
382
|
+
oidcConfig: JSON.parse(provider.oidcConfig),
|
|
383
|
+
samlConfig: JSON.parse(provider.samlConfig),
|
|
384
|
+
redirectURI: `${ctx.context.baseURL}/sso/callback/${provider.providerId}`
|
|
385
|
+
});
|
|
386
|
+
}),
|
|
387
|
+
signInSSO: createAuthEndpoint("/sign-in/sso", {
|
|
388
|
+
method: "POST",
|
|
389
|
+
body: z.object({
|
|
390
|
+
email: z.string({}).meta({ description: "The email address to sign in with. This is used to identify the issuer to sign in with. It's optional if the issuer is provided" }).optional(),
|
|
391
|
+
organizationSlug: z.string({}).meta({ description: "The slug of the organization to sign in with" }).optional(),
|
|
392
|
+
providerId: z.string({}).meta({ description: "The ID of the provider to sign in with. This can be provided instead of email or issuer" }).optional(),
|
|
393
|
+
domain: z.string({}).meta({ description: "The domain of the provider." }).optional(),
|
|
394
|
+
callbackURL: z.string({}).meta({ description: "The URL to redirect to after login" }),
|
|
395
|
+
errorCallbackURL: z.string({}).meta({ description: "The URL to redirect to after login" }).optional(),
|
|
396
|
+
newUserCallbackURL: z.string({}).meta({ description: "The URL to redirect to after login if the user is new" }).optional(),
|
|
397
|
+
scopes: z.array(z.string(), {}).meta({ description: "Scopes to request from the provider." }).optional(),
|
|
398
|
+
requestSignUp: z.boolean({}).meta({ description: "Explicitly request sign-up. Useful when disableImplicitSignUp is true for this provider" }).optional(),
|
|
399
|
+
providerType: z.enum(["oidc", "saml"]).optional()
|
|
400
|
+
}),
|
|
401
|
+
metadata: { openapi: {
|
|
402
|
+
summary: "Sign in with SSO provider",
|
|
403
|
+
description: "This endpoint is used to sign in with an SSO provider. It redirects to the provider's authorization URL",
|
|
404
|
+
requestBody: { content: { "application/json": { schema: {
|
|
405
|
+
type: "object",
|
|
406
|
+
properties: {
|
|
407
|
+
email: {
|
|
408
|
+
type: "string",
|
|
409
|
+
description: "The email address to sign in with. This is used to identify the issuer to sign in with. It's optional if the issuer is provided"
|
|
410
|
+
},
|
|
411
|
+
issuer: {
|
|
412
|
+
type: "string",
|
|
413
|
+
description: "The issuer identifier, this is the URL of the provider and can be used to verify the provider and identify the provider during login. It's optional if the email is provided"
|
|
414
|
+
},
|
|
415
|
+
providerId: {
|
|
416
|
+
type: "string",
|
|
417
|
+
description: "The ID of the provider to sign in with. This can be provided instead of email or issuer"
|
|
418
|
+
},
|
|
419
|
+
callbackURL: {
|
|
420
|
+
type: "string",
|
|
421
|
+
description: "The URL to redirect to after login"
|
|
422
|
+
},
|
|
423
|
+
errorCallbackURL: {
|
|
424
|
+
type: "string",
|
|
425
|
+
description: "The URL to redirect to after login"
|
|
426
|
+
},
|
|
427
|
+
newUserCallbackURL: {
|
|
428
|
+
type: "string",
|
|
429
|
+
description: "The URL to redirect to after login if the user is new"
|
|
430
|
+
}
|
|
431
|
+
},
|
|
432
|
+
required: ["callbackURL"]
|
|
433
|
+
} } } },
|
|
434
|
+
responses: { "200": {
|
|
435
|
+
description: "Authorization URL generated successfully for SSO sign-in",
|
|
436
|
+
content: { "application/json": { schema: {
|
|
437
|
+
type: "object",
|
|
438
|
+
properties: {
|
|
439
|
+
url: {
|
|
440
|
+
type: "string",
|
|
441
|
+
format: "uri",
|
|
442
|
+
description: "The authorization URL to redirect the user to for SSO sign-in"
|
|
443
|
+
},
|
|
444
|
+
redirect: {
|
|
445
|
+
type: "boolean",
|
|
446
|
+
description: "Indicates that the client should redirect to the provided URL",
|
|
447
|
+
enum: [true]
|
|
448
|
+
}
|
|
449
|
+
},
|
|
450
|
+
required: ["url", "redirect"]
|
|
451
|
+
} } }
|
|
452
|
+
} }
|
|
453
|
+
} }
|
|
454
|
+
}, async (ctx) => {
|
|
455
|
+
const body = ctx.body;
|
|
456
|
+
let { email, organizationSlug, providerId, domain } = body;
|
|
457
|
+
if (!options?.defaultSSO?.length && !email && !organizationSlug && !domain && !providerId) throw new APIError("BAD_REQUEST", { message: "email, organizationSlug, domain or providerId is required" });
|
|
458
|
+
domain = body.domain || email?.split("@")[1];
|
|
459
|
+
let orgId = "";
|
|
460
|
+
if (organizationSlug) orgId = await ctx.context.adapter.findOne({
|
|
461
|
+
model: "organization",
|
|
462
|
+
where: [{
|
|
463
|
+
field: "slug",
|
|
464
|
+
value: organizationSlug
|
|
465
|
+
}]
|
|
466
|
+
}).then((res) => {
|
|
467
|
+
if (!res) return "";
|
|
468
|
+
return res.id;
|
|
469
|
+
});
|
|
470
|
+
let provider = null;
|
|
471
|
+
if (options?.defaultSSO?.length) {
|
|
472
|
+
const matchingDefault = providerId ? options.defaultSSO.find((defaultProvider) => defaultProvider.providerId === providerId) : options.defaultSSO.find((defaultProvider) => defaultProvider.domain === domain);
|
|
473
|
+
if (matchingDefault) provider = {
|
|
474
|
+
issuer: matchingDefault.samlConfig?.issuer || matchingDefault.oidcConfig?.issuer || "",
|
|
475
|
+
providerId: matchingDefault.providerId,
|
|
476
|
+
userId: "default",
|
|
477
|
+
oidcConfig: matchingDefault.oidcConfig,
|
|
478
|
+
samlConfig: matchingDefault.samlConfig
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
if (!providerId && !orgId && !domain) throw new APIError("BAD_REQUEST", { message: "providerId, orgId or domain is required" });
|
|
482
|
+
if (!provider) provider = await ctx.context.adapter.findOne({
|
|
483
|
+
model: "ssoProvider",
|
|
484
|
+
where: [{
|
|
485
|
+
field: providerId ? "providerId" : orgId ? "organizationId" : "domain",
|
|
486
|
+
value: providerId || orgId || domain
|
|
487
|
+
}]
|
|
488
|
+
}).then((res) => {
|
|
489
|
+
if (!res) return null;
|
|
490
|
+
return {
|
|
491
|
+
...res,
|
|
492
|
+
oidcConfig: res.oidcConfig ? safeJsonParse(res.oidcConfig) || void 0 : void 0,
|
|
493
|
+
samlConfig: res.samlConfig ? safeJsonParse(res.samlConfig) || void 0 : void 0
|
|
494
|
+
};
|
|
495
|
+
});
|
|
496
|
+
if (!provider) throw new APIError("NOT_FOUND", { message: "No provider found for the issuer" });
|
|
497
|
+
if (body.providerType) {
|
|
498
|
+
if (body.providerType === "oidc" && !provider.oidcConfig) throw new APIError("BAD_REQUEST", { message: "OIDC provider is not configured" });
|
|
499
|
+
if (body.providerType === "saml" && !provider.samlConfig) throw new APIError("BAD_REQUEST", { message: "SAML provider is not configured" });
|
|
500
|
+
}
|
|
501
|
+
if (provider.oidcConfig && body.providerType !== "saml") {
|
|
502
|
+
const state = await generateState(ctx);
|
|
503
|
+
const redirectURI = `${ctx.context.baseURL}/sso/callback/${provider.providerId}`;
|
|
504
|
+
const authorizationURL = await createAuthorizationURL({
|
|
505
|
+
id: provider.issuer,
|
|
506
|
+
options: {
|
|
507
|
+
clientId: provider.oidcConfig.clientId,
|
|
508
|
+
clientSecret: provider.oidcConfig.clientSecret
|
|
509
|
+
},
|
|
510
|
+
redirectURI,
|
|
511
|
+
state: state.state,
|
|
512
|
+
codeVerifier: provider.oidcConfig.pkce ? state.codeVerifier : void 0,
|
|
513
|
+
scopes: ctx.body.scopes || provider.oidcConfig.scopes || [
|
|
514
|
+
"openid",
|
|
515
|
+
"email",
|
|
516
|
+
"profile",
|
|
517
|
+
"offline_access"
|
|
518
|
+
],
|
|
519
|
+
authorizationEndpoint: provider.oidcConfig.authorizationEndpoint
|
|
520
|
+
});
|
|
521
|
+
return ctx.json({
|
|
522
|
+
url: authorizationURL.toString(),
|
|
523
|
+
redirect: true
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
if (provider.samlConfig) {
|
|
527
|
+
const parsedSamlConfig = typeof provider.samlConfig === "object" ? provider.samlConfig : safeJsonParse(provider.samlConfig);
|
|
528
|
+
if (!parsedSamlConfig) throw new APIError("BAD_REQUEST", { message: "Invalid SAML configuration" });
|
|
529
|
+
const sp = saml.ServiceProvider({
|
|
530
|
+
metadata: parsedSamlConfig.spMetadata.metadata,
|
|
531
|
+
allowCreate: true
|
|
532
|
+
});
|
|
533
|
+
const idp = saml.IdentityProvider({
|
|
534
|
+
metadata: parsedSamlConfig.idpMetadata?.metadata,
|
|
535
|
+
entityID: parsedSamlConfig.idpMetadata?.entityID,
|
|
536
|
+
encryptCert: parsedSamlConfig.idpMetadata?.cert,
|
|
537
|
+
singleSignOnService: parsedSamlConfig.idpMetadata?.singleSignOnService
|
|
538
|
+
});
|
|
539
|
+
const loginRequest = sp.createLoginRequest(idp, "redirect");
|
|
540
|
+
if (!loginRequest) throw new APIError("BAD_REQUEST", { message: "Invalid SAML request" });
|
|
541
|
+
return ctx.json({
|
|
542
|
+
url: `${loginRequest.context}&RelayState=${encodeURIComponent(body.callbackURL)}`,
|
|
543
|
+
redirect: true
|
|
544
|
+
});
|
|
545
|
+
}
|
|
546
|
+
throw new APIError("BAD_REQUEST", { message: "Invalid SSO provider" });
|
|
547
|
+
}),
|
|
548
|
+
callbackSSO: createAuthEndpoint("/sso/callback/:providerId", {
|
|
549
|
+
method: "GET",
|
|
550
|
+
query: z.object({
|
|
551
|
+
code: z.string().optional(),
|
|
552
|
+
state: z.string(),
|
|
553
|
+
error: z.string().optional(),
|
|
554
|
+
error_description: z.string().optional()
|
|
555
|
+
}),
|
|
556
|
+
metadata: {
|
|
557
|
+
isAction: false,
|
|
558
|
+
openapi: {
|
|
559
|
+
summary: "Callback URL for SSO provider",
|
|
560
|
+
description: "This endpoint is used as the callback URL for SSO providers. It handles the authorization code and exchanges it for an access token",
|
|
561
|
+
responses: { "302": { description: "Redirects to the callback URL" } }
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
}, async (ctx) => {
|
|
565
|
+
const { code, state, error, error_description } = ctx.query;
|
|
566
|
+
const stateData = await parseState(ctx);
|
|
567
|
+
if (!stateData) {
|
|
568
|
+
const errorURL$1 = ctx.context.options.onAPIError?.errorURL || `${ctx.context.baseURL}/error`;
|
|
569
|
+
throw ctx.redirect(`${errorURL$1}?error=invalid_state`);
|
|
570
|
+
}
|
|
571
|
+
const { callbackURL, errorURL, newUserURL, requestSignUp } = stateData;
|
|
572
|
+
if (!code || error) throw ctx.redirect(`${errorURL || callbackURL}?error=${error}&error_description=${error_description}`);
|
|
573
|
+
let provider = null;
|
|
574
|
+
if (options?.defaultSSO?.length) {
|
|
575
|
+
const matchingDefault = options.defaultSSO.find((defaultProvider) => defaultProvider.providerId === ctx.params.providerId);
|
|
576
|
+
if (matchingDefault) provider = {
|
|
577
|
+
...matchingDefault,
|
|
578
|
+
issuer: matchingDefault.oidcConfig?.issuer || "",
|
|
579
|
+
userId: "default"
|
|
580
|
+
};
|
|
581
|
+
}
|
|
582
|
+
if (!provider) provider = await ctx.context.adapter.findOne({
|
|
583
|
+
model: "ssoProvider",
|
|
584
|
+
where: [{
|
|
585
|
+
field: "providerId",
|
|
586
|
+
value: ctx.params.providerId
|
|
587
|
+
}]
|
|
588
|
+
}).then((res) => {
|
|
589
|
+
if (!res) return null;
|
|
590
|
+
return {
|
|
591
|
+
...res,
|
|
592
|
+
oidcConfig: safeJsonParse(res.oidcConfig) || void 0
|
|
593
|
+
};
|
|
594
|
+
});
|
|
595
|
+
if (!provider) throw ctx.redirect(`${errorURL || callbackURL}/error?error=invalid_provider&error_description=provider not found`);
|
|
596
|
+
let config = provider.oidcConfig;
|
|
597
|
+
if (!config) throw ctx.redirect(`${errorURL || callbackURL}/error?error=invalid_provider&error_description=provider not found`);
|
|
598
|
+
const discovery = await betterFetch(config.discoveryEndpoint);
|
|
599
|
+
if (discovery.data) config = {
|
|
600
|
+
tokenEndpoint: discovery.data.token_endpoint,
|
|
601
|
+
tokenEndpointAuthentication: discovery.data.token_endpoint_auth_method,
|
|
602
|
+
userInfoEndpoint: discovery.data.userinfo_endpoint,
|
|
603
|
+
scopes: [
|
|
604
|
+
"openid",
|
|
605
|
+
"email",
|
|
606
|
+
"profile",
|
|
607
|
+
"offline_access"
|
|
608
|
+
],
|
|
609
|
+
...config
|
|
610
|
+
};
|
|
611
|
+
if (!config.tokenEndpoint) throw ctx.redirect(`${errorURL || callbackURL}/error?error=invalid_provider&error_description=token_endpoint_not_found`);
|
|
612
|
+
const tokenResponse = await validateAuthorizationCode({
|
|
613
|
+
code,
|
|
614
|
+
codeVerifier: config.pkce ? stateData.codeVerifier : void 0,
|
|
615
|
+
redirectURI: `${ctx.context.baseURL}/sso/callback/${provider.providerId}`,
|
|
616
|
+
options: {
|
|
617
|
+
clientId: config.clientId,
|
|
618
|
+
clientSecret: config.clientSecret
|
|
619
|
+
},
|
|
620
|
+
tokenEndpoint: config.tokenEndpoint,
|
|
621
|
+
authentication: config.tokenEndpointAuthentication === "client_secret_post" ? "post" : "basic"
|
|
622
|
+
}).catch((e) => {
|
|
623
|
+
if (e instanceof BetterFetchError) throw ctx.redirect(`${errorURL || callbackURL}?error=invalid_provider&error_description=${e.message}`);
|
|
624
|
+
return null;
|
|
625
|
+
});
|
|
626
|
+
if (!tokenResponse) throw ctx.redirect(`${errorURL || callbackURL}/error?error=invalid_provider&error_description=token_response_not_found`);
|
|
627
|
+
let userInfo = null;
|
|
628
|
+
if (tokenResponse.idToken) {
|
|
629
|
+
const idToken = decodeJwt(tokenResponse.idToken);
|
|
630
|
+
if (!config.jwksEndpoint) throw ctx.redirect(`${errorURL || callbackURL}/error?error=invalid_provider&error_description=jwks_endpoint_not_found`);
|
|
631
|
+
const verified = await validateToken(tokenResponse.idToken, config.jwksEndpoint).catch((e) => {
|
|
632
|
+
ctx.context.logger.error(e);
|
|
633
|
+
return null;
|
|
634
|
+
});
|
|
635
|
+
if (!verified) throw ctx.redirect(`${errorURL || callbackURL}/error?error=invalid_provider&error_description=token_not_verified`);
|
|
636
|
+
if (verified.payload.iss !== provider.issuer) throw ctx.redirect(`${errorURL || callbackURL}/error?error=invalid_provider&error_description=issuer_mismatch`);
|
|
637
|
+
const mapping = config.mapping || {};
|
|
638
|
+
userInfo = {
|
|
639
|
+
...Object.fromEntries(Object.entries(mapping.extraFields || {}).map(([key, value]) => [key, verified.payload[value]])),
|
|
640
|
+
id: idToken[mapping.id || "sub"],
|
|
641
|
+
email: idToken[mapping.email || "email"],
|
|
642
|
+
emailVerified: options?.trustEmailVerified ? idToken[mapping.emailVerified || "email_verified"] : false,
|
|
643
|
+
name: idToken[mapping.name || "name"],
|
|
644
|
+
image: idToken[mapping.image || "picture"]
|
|
645
|
+
};
|
|
646
|
+
}
|
|
647
|
+
if (!userInfo) {
|
|
648
|
+
if (!config.userInfoEndpoint) throw ctx.redirect(`${errorURL || callbackURL}/error?error=invalid_provider&error_description=user_info_endpoint_not_found`);
|
|
649
|
+
const userInfoResponse = await betterFetch(config.userInfoEndpoint, { headers: { Authorization: `Bearer ${tokenResponse.accessToken}` } });
|
|
650
|
+
if (userInfoResponse.error) throw ctx.redirect(`${errorURL || callbackURL}/error?error=invalid_provider&error_description=${userInfoResponse.error.message}`);
|
|
651
|
+
userInfo = userInfoResponse.data;
|
|
652
|
+
}
|
|
653
|
+
if (!userInfo.email || !userInfo.id) throw ctx.redirect(`${errorURL || callbackURL}/error?error=invalid_provider&error_description=missing_user_info`);
|
|
654
|
+
const linked = await handleOAuthUserInfo(ctx, {
|
|
655
|
+
userInfo: {
|
|
656
|
+
email: userInfo.email,
|
|
657
|
+
name: userInfo.name || userInfo.email,
|
|
658
|
+
id: userInfo.id,
|
|
659
|
+
image: userInfo.image,
|
|
660
|
+
emailVerified: options?.trustEmailVerified ? userInfo.emailVerified || false : false
|
|
661
|
+
},
|
|
662
|
+
account: {
|
|
663
|
+
idToken: tokenResponse.idToken,
|
|
664
|
+
accessToken: tokenResponse.accessToken,
|
|
665
|
+
refreshToken: tokenResponse.refreshToken,
|
|
666
|
+
accountId: userInfo.id,
|
|
667
|
+
providerId: provider.providerId,
|
|
668
|
+
accessTokenExpiresAt: tokenResponse.accessTokenExpiresAt,
|
|
669
|
+
refreshTokenExpiresAt: tokenResponse.refreshTokenExpiresAt,
|
|
670
|
+
scope: tokenResponse.scopes?.join(",")
|
|
671
|
+
},
|
|
672
|
+
callbackURL,
|
|
673
|
+
disableSignUp: options?.disableImplicitSignUp && !requestSignUp,
|
|
674
|
+
overrideUserInfo: config.overrideUserInfo
|
|
675
|
+
});
|
|
676
|
+
if (linked.error) throw ctx.redirect(`${errorURL || callbackURL}/error?error=${linked.error}`);
|
|
677
|
+
const { session, user } = linked.data;
|
|
678
|
+
if (options?.provisionUser) await options.provisionUser({
|
|
679
|
+
user,
|
|
680
|
+
userInfo,
|
|
681
|
+
token: tokenResponse,
|
|
682
|
+
provider
|
|
683
|
+
});
|
|
684
|
+
if (provider.organizationId && !options?.organizationProvisioning?.disabled) {
|
|
685
|
+
if (ctx.context.options.plugins?.find((plugin) => plugin.id === "organization")) {
|
|
686
|
+
if (!await ctx.context.adapter.findOne({
|
|
687
|
+
model: "member",
|
|
688
|
+
where: [{
|
|
689
|
+
field: "organizationId",
|
|
690
|
+
value: provider.organizationId
|
|
691
|
+
}, {
|
|
692
|
+
field: "userId",
|
|
693
|
+
value: user.id
|
|
694
|
+
}]
|
|
695
|
+
})) {
|
|
696
|
+
const role = options?.organizationProvisioning?.getRole ? await options.organizationProvisioning.getRole({
|
|
697
|
+
user,
|
|
698
|
+
userInfo,
|
|
699
|
+
token: tokenResponse,
|
|
700
|
+
provider
|
|
701
|
+
}) : options?.organizationProvisioning?.defaultRole || "member";
|
|
702
|
+
await ctx.context.adapter.create({
|
|
703
|
+
model: "member",
|
|
704
|
+
data: {
|
|
705
|
+
organizationId: provider.organizationId,
|
|
706
|
+
userId: user.id,
|
|
707
|
+
role,
|
|
708
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
709
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
710
|
+
}
|
|
711
|
+
});
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
await setSessionCookie(ctx, {
|
|
716
|
+
session,
|
|
717
|
+
user
|
|
718
|
+
});
|
|
719
|
+
let toRedirectTo;
|
|
720
|
+
try {
|
|
721
|
+
toRedirectTo = (linked.isRegister ? newUserURL || callbackURL : callbackURL).toString();
|
|
722
|
+
} catch {
|
|
723
|
+
toRedirectTo = linked.isRegister ? newUserURL || callbackURL : callbackURL;
|
|
724
|
+
}
|
|
725
|
+
throw ctx.redirect(toRedirectTo);
|
|
726
|
+
}),
|
|
727
|
+
callbackSSOSAML: createAuthEndpoint("/sso/saml2/callback/:providerId", {
|
|
728
|
+
method: "POST",
|
|
729
|
+
body: z.object({
|
|
730
|
+
SAMLResponse: z.string(),
|
|
731
|
+
RelayState: z.string().optional()
|
|
732
|
+
}),
|
|
733
|
+
metadata: {
|
|
734
|
+
isAction: false,
|
|
735
|
+
openapi: {
|
|
736
|
+
summary: "Callback URL for SAML provider",
|
|
737
|
+
description: "This endpoint is used as the callback URL for SAML providers.",
|
|
738
|
+
responses: {
|
|
739
|
+
"302": { description: "Redirects to the callback URL" },
|
|
740
|
+
"400": { description: "Invalid SAML response" },
|
|
741
|
+
"401": { description: "Unauthorized - SAML authentication failed" }
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
}, async (ctx) => {
|
|
746
|
+
const { SAMLResponse, RelayState } = ctx.body;
|
|
747
|
+
const { providerId } = ctx.params;
|
|
748
|
+
let provider = null;
|
|
749
|
+
if (options?.defaultSSO?.length) {
|
|
750
|
+
const matchingDefault = options.defaultSSO.find((defaultProvider) => defaultProvider.providerId === providerId);
|
|
751
|
+
if (matchingDefault) provider = {
|
|
752
|
+
...matchingDefault,
|
|
753
|
+
userId: "default",
|
|
754
|
+
issuer: matchingDefault.samlConfig?.issuer || ""
|
|
755
|
+
};
|
|
756
|
+
}
|
|
757
|
+
if (!provider) provider = await ctx.context.adapter.findOne({
|
|
758
|
+
model: "ssoProvider",
|
|
759
|
+
where: [{
|
|
760
|
+
field: "providerId",
|
|
761
|
+
value: providerId
|
|
762
|
+
}]
|
|
763
|
+
}).then((res) => {
|
|
764
|
+
if (!res) return null;
|
|
765
|
+
return {
|
|
766
|
+
...res,
|
|
767
|
+
samlConfig: res.samlConfig ? safeJsonParse(res.samlConfig) || void 0 : void 0
|
|
768
|
+
};
|
|
769
|
+
});
|
|
770
|
+
if (!provider) throw new APIError("NOT_FOUND", { message: "No provider found for the given providerId" });
|
|
771
|
+
const parsedSamlConfig = safeJsonParse(provider.samlConfig);
|
|
772
|
+
if (!parsedSamlConfig) throw new APIError("BAD_REQUEST", { message: "Invalid SAML configuration" });
|
|
773
|
+
const idpData = parsedSamlConfig.idpMetadata;
|
|
774
|
+
let idp = null;
|
|
775
|
+
if (!idpData?.metadata) idp = saml.IdentityProvider({
|
|
776
|
+
entityID: idpData?.entityID || parsedSamlConfig.issuer,
|
|
777
|
+
singleSignOnService: [{
|
|
778
|
+
Binding: "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect",
|
|
779
|
+
Location: parsedSamlConfig.entryPoint
|
|
780
|
+
}],
|
|
781
|
+
signingCert: idpData?.cert || parsedSamlConfig.cert,
|
|
782
|
+
wantAuthnRequestsSigned: parsedSamlConfig.wantAssertionsSigned || false,
|
|
783
|
+
isAssertionEncrypted: idpData?.isAssertionEncrypted || false,
|
|
784
|
+
encPrivateKey: idpData?.encPrivateKey,
|
|
785
|
+
encPrivateKeyPass: idpData?.encPrivateKeyPass
|
|
786
|
+
});
|
|
787
|
+
else idp = saml.IdentityProvider({
|
|
788
|
+
metadata: idpData.metadata,
|
|
789
|
+
privateKey: idpData.privateKey,
|
|
790
|
+
privateKeyPass: idpData.privateKeyPass,
|
|
791
|
+
isAssertionEncrypted: idpData.isAssertionEncrypted,
|
|
792
|
+
encPrivateKey: idpData.encPrivateKey,
|
|
793
|
+
encPrivateKeyPass: idpData.encPrivateKeyPass
|
|
794
|
+
});
|
|
795
|
+
const spData = parsedSamlConfig.spMetadata;
|
|
796
|
+
const sp = saml.ServiceProvider({
|
|
797
|
+
metadata: spData?.metadata,
|
|
798
|
+
entityID: spData?.entityID || parsedSamlConfig.issuer,
|
|
799
|
+
assertionConsumerService: spData?.metadata ? void 0 : [{
|
|
800
|
+
Binding: "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST",
|
|
801
|
+
Location: parsedSamlConfig.callbackUrl
|
|
802
|
+
}],
|
|
803
|
+
privateKey: spData?.privateKey || parsedSamlConfig.privateKey,
|
|
804
|
+
privateKeyPass: spData?.privateKeyPass,
|
|
805
|
+
isAssertionEncrypted: spData?.isAssertionEncrypted || false,
|
|
806
|
+
encPrivateKey: spData?.encPrivateKey,
|
|
807
|
+
encPrivateKeyPass: spData?.encPrivateKeyPass,
|
|
808
|
+
wantMessageSigned: parsedSamlConfig.wantAssertionsSigned || false,
|
|
809
|
+
nameIDFormat: parsedSamlConfig.identifierFormat ? [parsedSamlConfig.identifierFormat] : void 0
|
|
810
|
+
});
|
|
811
|
+
let parsedResponse;
|
|
812
|
+
try {
|
|
813
|
+
const decodedResponse = Buffer.from(SAMLResponse, "base64").toString("utf-8");
|
|
814
|
+
try {
|
|
815
|
+
parsedResponse = await sp.parseLoginResponse(idp, "post", { body: {
|
|
816
|
+
SAMLResponse,
|
|
817
|
+
RelayState: RelayState || void 0
|
|
818
|
+
} });
|
|
819
|
+
} catch (parseError) {
|
|
820
|
+
const nameIDMatch = decodedResponse.match(/<saml2:NameID[^>]*>([^<]+)<\/saml2:NameID>/);
|
|
821
|
+
if (!nameIDMatch) throw parseError;
|
|
822
|
+
parsedResponse = { extract: {
|
|
823
|
+
nameID: nameIDMatch[1],
|
|
824
|
+
attributes: { nameID: nameIDMatch[1] },
|
|
825
|
+
sessionIndex: {},
|
|
826
|
+
conditions: {}
|
|
827
|
+
} };
|
|
828
|
+
}
|
|
829
|
+
if (!parsedResponse?.extract) throw new Error("Invalid SAML response structure");
|
|
830
|
+
} catch (error) {
|
|
831
|
+
ctx.context.logger.error("SAML response validation failed", {
|
|
832
|
+
error,
|
|
833
|
+
decodedResponse: Buffer.from(SAMLResponse, "base64").toString("utf-8")
|
|
834
|
+
});
|
|
835
|
+
throw new APIError("BAD_REQUEST", {
|
|
836
|
+
message: "Invalid SAML response",
|
|
837
|
+
details: error instanceof Error ? error.message : String(error)
|
|
838
|
+
});
|
|
839
|
+
}
|
|
840
|
+
const { extract } = parsedResponse;
|
|
841
|
+
const attributes = extract.attributes || {};
|
|
842
|
+
const mapping = parsedSamlConfig.mapping ?? {};
|
|
843
|
+
const userInfo = {
|
|
844
|
+
...Object.fromEntries(Object.entries(mapping.extraFields || {}).map(([key, value]) => [key, attributes[value]])),
|
|
845
|
+
id: attributes[mapping.id || "nameID"] || extract.nameID,
|
|
846
|
+
email: attributes[mapping.email || "email"] || extract.nameID,
|
|
847
|
+
name: [attributes[mapping.firstName || "givenName"], attributes[mapping.lastName || "surname"]].filter(Boolean).join(" ") || attributes[mapping.name || "displayName"] || extract.nameID,
|
|
848
|
+
emailVerified: options?.trustEmailVerified && mapping.emailVerified ? attributes[mapping.emailVerified] || false : false
|
|
849
|
+
};
|
|
850
|
+
if (!userInfo.id || !userInfo.email) {
|
|
851
|
+
ctx.context.logger.error("Missing essential user info from SAML response", {
|
|
852
|
+
attributes: Object.keys(attributes),
|
|
853
|
+
mapping,
|
|
854
|
+
extractedId: userInfo.id,
|
|
855
|
+
extractedEmail: userInfo.email
|
|
856
|
+
});
|
|
857
|
+
throw new APIError("BAD_REQUEST", { message: "Unable to extract user ID or email from SAML response" });
|
|
858
|
+
}
|
|
859
|
+
let user;
|
|
860
|
+
const existingUser = await ctx.context.adapter.findOne({
|
|
861
|
+
model: "user",
|
|
862
|
+
where: [{
|
|
863
|
+
field: "email",
|
|
864
|
+
value: userInfo.email
|
|
865
|
+
}]
|
|
866
|
+
});
|
|
867
|
+
if (existingUser) user = existingUser;
|
|
868
|
+
else user = await ctx.context.adapter.create({
|
|
869
|
+
model: "user",
|
|
870
|
+
data: {
|
|
871
|
+
email: userInfo.email,
|
|
872
|
+
name: userInfo.name,
|
|
873
|
+
emailVerified: userInfo.emailVerified,
|
|
874
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
875
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
876
|
+
}
|
|
877
|
+
});
|
|
878
|
+
if (!await ctx.context.adapter.findOne({
|
|
879
|
+
model: "account",
|
|
880
|
+
where: [
|
|
881
|
+
{
|
|
882
|
+
field: "userId",
|
|
883
|
+
value: user.id
|
|
884
|
+
},
|
|
885
|
+
{
|
|
886
|
+
field: "providerId",
|
|
887
|
+
value: provider.providerId
|
|
888
|
+
},
|
|
889
|
+
{
|
|
890
|
+
field: "accountId",
|
|
891
|
+
value: userInfo.id
|
|
892
|
+
}
|
|
893
|
+
]
|
|
894
|
+
})) await ctx.context.adapter.create({
|
|
895
|
+
model: "account",
|
|
896
|
+
data: {
|
|
897
|
+
userId: user.id,
|
|
898
|
+
providerId: provider.providerId,
|
|
899
|
+
accountId: userInfo.id,
|
|
900
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
901
|
+
updatedAt: /* @__PURE__ */ new Date(),
|
|
902
|
+
accessToken: "",
|
|
903
|
+
refreshToken: ""
|
|
904
|
+
}
|
|
905
|
+
});
|
|
906
|
+
if (options?.provisionUser) await options.provisionUser({
|
|
907
|
+
user,
|
|
908
|
+
userInfo,
|
|
909
|
+
provider
|
|
910
|
+
});
|
|
911
|
+
if (provider.organizationId && !options?.organizationProvisioning?.disabled) {
|
|
912
|
+
if (ctx.context.options.plugins?.find((plugin) => plugin.id === "organization")) {
|
|
913
|
+
if (!await ctx.context.adapter.findOne({
|
|
914
|
+
model: "member",
|
|
915
|
+
where: [{
|
|
916
|
+
field: "organizationId",
|
|
917
|
+
value: provider.organizationId
|
|
918
|
+
}, {
|
|
919
|
+
field: "userId",
|
|
920
|
+
value: user.id
|
|
921
|
+
}]
|
|
922
|
+
})) {
|
|
923
|
+
const role = options?.organizationProvisioning?.getRole ? await options.organizationProvisioning.getRole({
|
|
924
|
+
user,
|
|
925
|
+
userInfo,
|
|
926
|
+
provider
|
|
927
|
+
}) : options?.organizationProvisioning?.defaultRole || "member";
|
|
928
|
+
await ctx.context.adapter.create({
|
|
929
|
+
model: "member",
|
|
930
|
+
data: {
|
|
931
|
+
organizationId: provider.organizationId,
|
|
932
|
+
userId: user.id,
|
|
933
|
+
role,
|
|
934
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
935
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
936
|
+
}
|
|
937
|
+
});
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
await setSessionCookie(ctx, {
|
|
942
|
+
session: await ctx.context.internalAdapter.createSession(user.id, ctx),
|
|
943
|
+
user
|
|
944
|
+
});
|
|
945
|
+
const callbackUrl = RelayState || parsedSamlConfig.callbackUrl || ctx.context.baseURL;
|
|
946
|
+
throw ctx.redirect(callbackUrl);
|
|
947
|
+
}),
|
|
948
|
+
acsEndpoint: createAuthEndpoint("/sso/saml2/sp/acs/:providerId", {
|
|
949
|
+
method: "POST",
|
|
950
|
+
params: z.object({ providerId: z.string().optional() }),
|
|
951
|
+
body: z.object({
|
|
952
|
+
SAMLResponse: z.string(),
|
|
953
|
+
RelayState: z.string().optional()
|
|
954
|
+
}),
|
|
955
|
+
metadata: {
|
|
956
|
+
isAction: false,
|
|
957
|
+
openapi: {
|
|
958
|
+
summary: "SAML Assertion Consumer Service",
|
|
959
|
+
description: "Handles SAML responses from IdP after successful authentication",
|
|
960
|
+
responses: { "302": { description: "Redirects to the callback URL after successful authentication" } }
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
}, async (ctx) => {
|
|
964
|
+
const { SAMLResponse, RelayState = "" } = ctx.body;
|
|
965
|
+
const { providerId } = ctx.params;
|
|
966
|
+
let provider = null;
|
|
967
|
+
if (options?.defaultSSO?.length) {
|
|
968
|
+
const matchingDefault = providerId ? options.defaultSSO.find((defaultProvider) => defaultProvider.providerId === providerId) : options.defaultSSO[0];
|
|
969
|
+
if (matchingDefault) provider = {
|
|
970
|
+
issuer: matchingDefault.samlConfig?.issuer || "",
|
|
971
|
+
providerId: matchingDefault.providerId,
|
|
972
|
+
userId: "default",
|
|
973
|
+
samlConfig: matchingDefault.samlConfig
|
|
974
|
+
};
|
|
975
|
+
} else provider = await ctx.context.adapter.findOne({
|
|
976
|
+
model: "ssoProvider",
|
|
977
|
+
where: [{
|
|
978
|
+
field: "providerId",
|
|
979
|
+
value: providerId ?? "sso"
|
|
980
|
+
}]
|
|
981
|
+
}).then((res) => {
|
|
982
|
+
if (!res) return null;
|
|
983
|
+
return {
|
|
984
|
+
...res,
|
|
985
|
+
samlConfig: res.samlConfig ? safeJsonParse(res.samlConfig) || void 0 : void 0
|
|
986
|
+
};
|
|
987
|
+
});
|
|
988
|
+
if (!provider?.samlConfig) throw new APIError("NOT_FOUND", { message: "No SAML provider found" });
|
|
989
|
+
const parsedSamlConfig = provider.samlConfig;
|
|
990
|
+
const sp = saml.ServiceProvider({
|
|
991
|
+
entityID: parsedSamlConfig.spMetadata?.entityID || parsedSamlConfig.issuer,
|
|
992
|
+
assertionConsumerService: [{
|
|
993
|
+
Binding: "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST",
|
|
994
|
+
Location: parsedSamlConfig.callbackUrl || `${ctx.context.baseURL}/sso/saml2/sp/acs/${providerId}`
|
|
995
|
+
}],
|
|
996
|
+
wantMessageSigned: parsedSamlConfig.wantAssertionsSigned || false,
|
|
997
|
+
metadata: parsedSamlConfig.spMetadata?.metadata,
|
|
998
|
+
privateKey: parsedSamlConfig.spMetadata?.privateKey || parsedSamlConfig.privateKey,
|
|
999
|
+
privateKeyPass: parsedSamlConfig.spMetadata?.privateKeyPass,
|
|
1000
|
+
nameIDFormat: parsedSamlConfig.identifierFormat ? [parsedSamlConfig.identifierFormat] : void 0
|
|
1001
|
+
});
|
|
1002
|
+
const idpData = parsedSamlConfig.idpMetadata;
|
|
1003
|
+
const idp = !idpData?.metadata ? saml.IdentityProvider({
|
|
1004
|
+
entityID: idpData?.entityID || parsedSamlConfig.issuer,
|
|
1005
|
+
singleSignOnService: idpData?.singleSignOnService || [{
|
|
1006
|
+
Binding: "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect",
|
|
1007
|
+
Location: parsedSamlConfig.entryPoint
|
|
1008
|
+
}],
|
|
1009
|
+
signingCert: idpData?.cert || parsedSamlConfig.cert
|
|
1010
|
+
}) : saml.IdentityProvider({ metadata: idpData.metadata });
|
|
1011
|
+
let parsedResponse;
|
|
1012
|
+
try {
|
|
1013
|
+
let decodedResponse = Buffer.from(SAMLResponse, "base64").toString("utf-8");
|
|
1014
|
+
if (!decodedResponse.includes("StatusCode")) {
|
|
1015
|
+
const insertPoint = decodedResponse.indexOf("</saml2:Issuer>");
|
|
1016
|
+
if (insertPoint !== -1) decodedResponse = decodedResponse.slice(0, insertPoint + 14) + "<saml2:Status><saml2:StatusCode Value=\"urn:oasis:names:tc:SAML:2.0:status:Success\"/></saml2:Status>" + decodedResponse.slice(insertPoint + 14);
|
|
1017
|
+
} else if (!decodedResponse.includes("saml2:Success")) decodedResponse = decodedResponse.replace(/<saml2:StatusCode Value="[^"]+"/, "<saml2:StatusCode Value=\"urn:oasis:names:tc:SAML:2.0:status:Success\"");
|
|
1018
|
+
try {
|
|
1019
|
+
parsedResponse = await sp.parseLoginResponse(idp, "post", { body: {
|
|
1020
|
+
SAMLResponse,
|
|
1021
|
+
RelayState: RelayState || void 0
|
|
1022
|
+
} });
|
|
1023
|
+
} catch (parseError) {
|
|
1024
|
+
const nameIDMatch = decodedResponse.match(/<saml2:NameID[^>]*>([^<]+)<\/saml2:NameID>/);
|
|
1025
|
+
if (!nameIDMatch) throw parseError;
|
|
1026
|
+
parsedResponse = { extract: {
|
|
1027
|
+
nameID: nameIDMatch[1],
|
|
1028
|
+
attributes: { nameID: nameIDMatch[1] },
|
|
1029
|
+
sessionIndex: {},
|
|
1030
|
+
conditions: {}
|
|
1031
|
+
} };
|
|
1032
|
+
}
|
|
1033
|
+
if (!parsedResponse?.extract) throw new Error("Invalid SAML response structure");
|
|
1034
|
+
} catch (error) {
|
|
1035
|
+
ctx.context.logger.error("SAML response validation failed", {
|
|
1036
|
+
error,
|
|
1037
|
+
decodedResponse: Buffer.from(SAMLResponse, "base64").toString("utf-8")
|
|
1038
|
+
});
|
|
1039
|
+
throw new APIError("BAD_REQUEST", {
|
|
1040
|
+
message: "Invalid SAML response",
|
|
1041
|
+
details: error instanceof Error ? error.message : String(error)
|
|
1042
|
+
});
|
|
1043
|
+
}
|
|
1044
|
+
const { extract } = parsedResponse;
|
|
1045
|
+
const attributes = extract.attributes || {};
|
|
1046
|
+
const mapping = parsedSamlConfig.mapping ?? {};
|
|
1047
|
+
const userInfo = {
|
|
1048
|
+
...Object.fromEntries(Object.entries(mapping.extraFields || {}).map(([key, value]) => [key, attributes[value]])),
|
|
1049
|
+
id: attributes[mapping.id || "nameID"] || extract.nameID,
|
|
1050
|
+
email: attributes[mapping.email || "email"] || extract.nameID,
|
|
1051
|
+
name: [attributes[mapping.firstName || "givenName"], attributes[mapping.lastName || "surname"]].filter(Boolean).join(" ") || attributes[mapping.name || "displayName"] || extract.nameID,
|
|
1052
|
+
emailVerified: options?.trustEmailVerified && mapping.emailVerified ? attributes[mapping.emailVerified] || false : false
|
|
1053
|
+
};
|
|
1054
|
+
if (!userInfo.id || !userInfo.email) {
|
|
1055
|
+
ctx.context.logger.error("Missing essential user info from SAML response", {
|
|
1056
|
+
attributes: Object.keys(attributes),
|
|
1057
|
+
mapping,
|
|
1058
|
+
extractedId: userInfo.id,
|
|
1059
|
+
extractedEmail: userInfo.email
|
|
1060
|
+
});
|
|
1061
|
+
throw new APIError("BAD_REQUEST", { message: "Unable to extract user ID or email from SAML response" });
|
|
1062
|
+
}
|
|
1063
|
+
let user;
|
|
1064
|
+
const existingUser = await ctx.context.adapter.findOne({
|
|
1065
|
+
model: "user",
|
|
1066
|
+
where: [{
|
|
1067
|
+
field: "email",
|
|
1068
|
+
value: userInfo.email
|
|
1069
|
+
}]
|
|
1070
|
+
});
|
|
1071
|
+
if (existingUser) {
|
|
1072
|
+
if (!await ctx.context.adapter.findOne({
|
|
1073
|
+
model: "account",
|
|
1074
|
+
where: [
|
|
1075
|
+
{
|
|
1076
|
+
field: "userId",
|
|
1077
|
+
value: existingUser.id
|
|
1078
|
+
},
|
|
1079
|
+
{
|
|
1080
|
+
field: "providerId",
|
|
1081
|
+
value: provider.providerId
|
|
1082
|
+
},
|
|
1083
|
+
{
|
|
1084
|
+
field: "accountId",
|
|
1085
|
+
value: userInfo.id
|
|
1086
|
+
}
|
|
1087
|
+
]
|
|
1088
|
+
})) {
|
|
1089
|
+
if (!ctx.context.options.account?.accountLinking?.trustedProviders?.includes(provider.providerId)) throw ctx.redirect(`${parsedSamlConfig.callbackUrl}?error=account_not_found`);
|
|
1090
|
+
await ctx.context.adapter.create({
|
|
1091
|
+
model: "account",
|
|
1092
|
+
data: {
|
|
1093
|
+
userId: existingUser.id,
|
|
1094
|
+
providerId: provider.providerId,
|
|
1095
|
+
accountId: userInfo.id,
|
|
1096
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
1097
|
+
updatedAt: /* @__PURE__ */ new Date(),
|
|
1098
|
+
accessToken: "",
|
|
1099
|
+
refreshToken: ""
|
|
1100
|
+
}
|
|
1101
|
+
});
|
|
1102
|
+
}
|
|
1103
|
+
user = existingUser;
|
|
1104
|
+
} else {
|
|
1105
|
+
user = await ctx.context.adapter.create({
|
|
1106
|
+
model: "user",
|
|
1107
|
+
data: {
|
|
1108
|
+
email: userInfo.email,
|
|
1109
|
+
name: userInfo.name,
|
|
1110
|
+
emailVerified: options?.trustEmailVerified ? userInfo.emailVerified || false : false,
|
|
1111
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
1112
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
1113
|
+
}
|
|
1114
|
+
});
|
|
1115
|
+
await ctx.context.adapter.create({
|
|
1116
|
+
model: "account",
|
|
1117
|
+
data: {
|
|
1118
|
+
userId: user.id,
|
|
1119
|
+
providerId: provider.providerId,
|
|
1120
|
+
accountId: userInfo.id,
|
|
1121
|
+
accessToken: "",
|
|
1122
|
+
refreshToken: "",
|
|
1123
|
+
accessTokenExpiresAt: /* @__PURE__ */ new Date(),
|
|
1124
|
+
refreshTokenExpiresAt: /* @__PURE__ */ new Date(),
|
|
1125
|
+
scope: "",
|
|
1126
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
1127
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
1128
|
+
}
|
|
1129
|
+
});
|
|
1130
|
+
}
|
|
1131
|
+
if (options?.provisionUser) await options.provisionUser({
|
|
1132
|
+
user,
|
|
1133
|
+
userInfo,
|
|
1134
|
+
provider
|
|
1135
|
+
});
|
|
1136
|
+
if (provider.organizationId && !options?.organizationProvisioning?.disabled) {
|
|
1137
|
+
if (ctx.context.options.plugins?.find((plugin) => plugin.id === "organization")) {
|
|
1138
|
+
if (!await ctx.context.adapter.findOne({
|
|
1139
|
+
model: "member",
|
|
1140
|
+
where: [{
|
|
1141
|
+
field: "organizationId",
|
|
1142
|
+
value: provider.organizationId
|
|
1143
|
+
}, {
|
|
1144
|
+
field: "userId",
|
|
1145
|
+
value: user.id
|
|
1146
|
+
}]
|
|
1147
|
+
})) {
|
|
1148
|
+
const role = options?.organizationProvisioning?.getRole ? await options.organizationProvisioning.getRole({
|
|
1149
|
+
user,
|
|
1150
|
+
userInfo,
|
|
1151
|
+
provider
|
|
1152
|
+
}) : options?.organizationProvisioning?.defaultRole || "member";
|
|
1153
|
+
await ctx.context.adapter.create({
|
|
1154
|
+
model: "member",
|
|
1155
|
+
data: {
|
|
1156
|
+
organizationId: provider.organizationId,
|
|
1157
|
+
userId: user.id,
|
|
1158
|
+
role,
|
|
1159
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
1160
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
1161
|
+
}
|
|
1162
|
+
});
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
await setSessionCookie(ctx, {
|
|
1167
|
+
session: await ctx.context.internalAdapter.createSession(user.id, ctx),
|
|
1168
|
+
user
|
|
1169
|
+
});
|
|
1170
|
+
const callbackUrl = RelayState || parsedSamlConfig.callbackUrl || ctx.context.baseURL;
|
|
1171
|
+
throw ctx.redirect(callbackUrl);
|
|
1172
|
+
})
|
|
1173
|
+
},
|
|
1174
|
+
schema: { ssoProvider: { fields: {
|
|
1175
|
+
issuer: {
|
|
1176
|
+
type: "string",
|
|
1177
|
+
required: true
|
|
1178
|
+
},
|
|
1179
|
+
oidcConfig: {
|
|
1180
|
+
type: "string",
|
|
1181
|
+
required: false
|
|
1182
|
+
},
|
|
1183
|
+
samlConfig: {
|
|
1184
|
+
type: "string",
|
|
1185
|
+
required: false
|
|
1186
|
+
},
|
|
1187
|
+
userId: {
|
|
1188
|
+
type: "string",
|
|
1189
|
+
references: {
|
|
1190
|
+
model: "user",
|
|
1191
|
+
field: "id"
|
|
1192
|
+
}
|
|
1193
|
+
},
|
|
1194
|
+
providerId: {
|
|
1195
|
+
type: "string",
|
|
1196
|
+
required: true,
|
|
1197
|
+
unique: true
|
|
1198
|
+
},
|
|
1199
|
+
organizationId: {
|
|
1200
|
+
type: "string",
|
|
1201
|
+
required: false
|
|
1202
|
+
},
|
|
1203
|
+
domain: {
|
|
1204
|
+
type: "string",
|
|
1205
|
+
required: true
|
|
1206
|
+
}
|
|
1207
|
+
} } }
|
|
1208
|
+
};
|
|
1209
|
+
};
|
|
1210
|
+
|
|
1211
|
+
//#endregion
|
|
1212
|
+
export { sso };
|