@better-auth/sso 1.3.13 → 1.3.14
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 +4 -4
- package/dist/index.cjs +528 -90
- package/dist/index.d.cts +186 -39
- package/dist/index.d.mts +186 -39
- package/dist/index.d.ts +186 -39
- package/dist/index.mjs +528 -90
- package/package.json +3 -3
- package/src/index.ts +767 -137
- package/src/oidc.test.ts +84 -21
- package/src/saml.test.ts +92 -0
- package/CHANGELOG.md +0 -20
package/src/oidc.test.ts
CHANGED
|
@@ -84,13 +84,13 @@ describe("SSO", async () => {
|
|
|
84
84
|
tokenEndpoint: `${server.issuer.url}/token`,
|
|
85
85
|
jwksEndpoint: `${server.issuer.url}/jwks`,
|
|
86
86
|
discoveryEndpoint: `${server.issuer.url}/.well-known/openid-configuration`,
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
87
|
+
mapping: {
|
|
88
|
+
id: "sub",
|
|
89
|
+
email: "email",
|
|
90
|
+
emailVerified: "email_verified",
|
|
91
|
+
name: "name",
|
|
92
|
+
image: "picture",
|
|
93
|
+
},
|
|
94
94
|
},
|
|
95
95
|
providerId: "test",
|
|
96
96
|
},
|
|
@@ -196,6 +196,67 @@ describe("SSO", async () => {
|
|
|
196
196
|
});
|
|
197
197
|
});
|
|
198
198
|
|
|
199
|
+
describe("SSO with defaultSSO array", async () => {
|
|
200
|
+
const { auth, signInWithTestUser, customFetchImpl } =
|
|
201
|
+
await getTestInstanceMemory({
|
|
202
|
+
plugins: [
|
|
203
|
+
sso({
|
|
204
|
+
defaultSSO: [
|
|
205
|
+
{
|
|
206
|
+
domain: "localhost.com",
|
|
207
|
+
providerId: "default-test",
|
|
208
|
+
oidcConfig: {
|
|
209
|
+
issuer: "http://localhost:8080",
|
|
210
|
+
clientId: "test",
|
|
211
|
+
clientSecret: "test",
|
|
212
|
+
authorizationEndpoint: "http://localhost:8080/authorize",
|
|
213
|
+
tokenEndpoint: "http://localhost:8080/token",
|
|
214
|
+
jwksEndpoint: "http://localhost:8080/jwks",
|
|
215
|
+
discoveryEndpoint:
|
|
216
|
+
"http://localhost:8080/.well-known/openid-configuration",
|
|
217
|
+
pkce: true,
|
|
218
|
+
mapping: {
|
|
219
|
+
id: "sub",
|
|
220
|
+
email: "email",
|
|
221
|
+
emailVerified: "email_verified",
|
|
222
|
+
name: "name",
|
|
223
|
+
image: "picture",
|
|
224
|
+
},
|
|
225
|
+
},
|
|
226
|
+
},
|
|
227
|
+
],
|
|
228
|
+
}),
|
|
229
|
+
organization(),
|
|
230
|
+
],
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it("should use default SSO provider from array when no provider found in database using providerId", async () => {
|
|
234
|
+
const res = await auth.api.signInSSO({
|
|
235
|
+
body: {
|
|
236
|
+
providerId: "default-test",
|
|
237
|
+
callbackURL: "/dashboard",
|
|
238
|
+
},
|
|
239
|
+
});
|
|
240
|
+
expect(res.url).toContain("http://localhost:8080/authorize");
|
|
241
|
+
expect(res.url).toContain(
|
|
242
|
+
"redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fapi%2Fauth%2Fsso%2Fcallback%2Fdefault-test",
|
|
243
|
+
);
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
it("should use default SSO provider from array when no provider found in database using domain fallback", async () => {
|
|
247
|
+
const res = await auth.api.signInSSO({
|
|
248
|
+
body: {
|
|
249
|
+
email: "test@localhost.com",
|
|
250
|
+
callbackURL: "/dashboard",
|
|
251
|
+
},
|
|
252
|
+
});
|
|
253
|
+
expect(res.url).toContain("http://localhost:8080/authorize");
|
|
254
|
+
expect(res.url).toContain(
|
|
255
|
+
"redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fapi%2Fauth%2Fsso%2Fcallback%2Fdefault-test",
|
|
256
|
+
);
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
|
|
199
260
|
describe("SSO disable implicit sign in", async () => {
|
|
200
261
|
const { auth, signInWithTestUser, customFetchImpl } =
|
|
201
262
|
await getTestInstanceMemory({
|
|
@@ -272,13 +333,14 @@ describe("SSO disable implicit sign in", async () => {
|
|
|
272
333
|
authorizationEndpoint: `${server.issuer.url}/authorize`,
|
|
273
334
|
tokenEndpoint: `${server.issuer.url}/token`,
|
|
274
335
|
jwksEndpoint: `${server.issuer.url}/jwks`,
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
336
|
+
discoveryEndpoint: `${server.issuer.url}/.well-known/openid-configuration`,
|
|
337
|
+
mapping: {
|
|
338
|
+
id: "sub",
|
|
339
|
+
email: "email",
|
|
340
|
+
emailVerified: "email_verified",
|
|
341
|
+
name: "name",
|
|
342
|
+
image: "picture",
|
|
343
|
+
},
|
|
282
344
|
},
|
|
283
345
|
providerId: "test",
|
|
284
346
|
},
|
|
@@ -526,13 +588,14 @@ describe("provisioning", async (ctx) => {
|
|
|
526
588
|
authorizationEndpoint: `${server.issuer.url}/authorize`,
|
|
527
589
|
tokenEndpoint: `${server.issuer.url}/token`,
|
|
528
590
|
jwksEndpoint: `${server.issuer.url}/jwks`,
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
591
|
+
discoveryEndpoint: `${server.issuer.url}/.well-known/openid-configuration`,
|
|
592
|
+
mapping: {
|
|
593
|
+
id: "sub",
|
|
594
|
+
email: "email",
|
|
595
|
+
emailVerified: "email_verified",
|
|
596
|
+
name: "name",
|
|
597
|
+
image: "picture",
|
|
598
|
+
},
|
|
536
599
|
},
|
|
537
600
|
providerId: "test2",
|
|
538
601
|
organizationId: organization?.id,
|
package/src/saml.test.ts
CHANGED
|
@@ -493,6 +493,98 @@ const createMockSAMLIdP = (port: number) => {
|
|
|
493
493
|
return { start, stop, metadataUrl };
|
|
494
494
|
};
|
|
495
495
|
|
|
496
|
+
describe("SAML SSO with defaultSSO array", async () => {
|
|
497
|
+
const data = {
|
|
498
|
+
user: [],
|
|
499
|
+
session: [],
|
|
500
|
+
verification: [],
|
|
501
|
+
account: [],
|
|
502
|
+
ssoProvider: [],
|
|
503
|
+
};
|
|
504
|
+
|
|
505
|
+
const memory = memoryAdapter(data);
|
|
506
|
+
const mockIdP = createMockSAMLIdP(8081); // Different port from your main app
|
|
507
|
+
|
|
508
|
+
const ssoOptions = {
|
|
509
|
+
defaultSSO: [
|
|
510
|
+
{
|
|
511
|
+
domain: "localhost:8081",
|
|
512
|
+
providerId: "default-saml",
|
|
513
|
+
samlConfig: {
|
|
514
|
+
issuer: "http://localhost:8081",
|
|
515
|
+
entryPoint: "http://localhost:8081/api/sso/saml2/idp/post",
|
|
516
|
+
cert: certificate,
|
|
517
|
+
callbackUrl: "http://localhost:8081/dashboard",
|
|
518
|
+
wantAssertionsSigned: false,
|
|
519
|
+
signatureAlgorithm: "sha256",
|
|
520
|
+
digestAlgorithm: "sha256",
|
|
521
|
+
idpMetadata: {
|
|
522
|
+
metadata: idpMetadata,
|
|
523
|
+
},
|
|
524
|
+
spMetadata: {
|
|
525
|
+
metadata: spMetadata,
|
|
526
|
+
},
|
|
527
|
+
identifierFormat:
|
|
528
|
+
"urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress",
|
|
529
|
+
},
|
|
530
|
+
},
|
|
531
|
+
],
|
|
532
|
+
provisionUser: vi
|
|
533
|
+
.fn()
|
|
534
|
+
.mockImplementation(async ({ user, userInfo, token, provider }) => {
|
|
535
|
+
return {
|
|
536
|
+
id: "provisioned-user-id",
|
|
537
|
+
email: userInfo.email,
|
|
538
|
+
name: userInfo.name,
|
|
539
|
+
attributes: userInfo.attributes,
|
|
540
|
+
};
|
|
541
|
+
}),
|
|
542
|
+
};
|
|
543
|
+
|
|
544
|
+
const auth = betterAuth({
|
|
545
|
+
database: memory,
|
|
546
|
+
baseURL: "http://localhost:3000",
|
|
547
|
+
emailAndPassword: {
|
|
548
|
+
enabled: true,
|
|
549
|
+
},
|
|
550
|
+
plugins: [sso(ssoOptions)],
|
|
551
|
+
});
|
|
552
|
+
|
|
553
|
+
const ctx = await auth.$context;
|
|
554
|
+
|
|
555
|
+
const authClient = createAuthClient({
|
|
556
|
+
baseURL: "http://localhost:3000",
|
|
557
|
+
plugins: [bearer(), ssoClient()],
|
|
558
|
+
fetchOptions: {
|
|
559
|
+
customFetchImpl: async (url, init) => {
|
|
560
|
+
return auth.handler(new Request(url, init));
|
|
561
|
+
},
|
|
562
|
+
},
|
|
563
|
+
});
|
|
564
|
+
|
|
565
|
+
beforeAll(async () => {
|
|
566
|
+
await mockIdP.start();
|
|
567
|
+
});
|
|
568
|
+
|
|
569
|
+
afterAll(async () => {
|
|
570
|
+
await mockIdP.stop();
|
|
571
|
+
});
|
|
572
|
+
|
|
573
|
+
it("should use default SAML SSO provider from array when no provider found in database", async () => {
|
|
574
|
+
const signInResponse = await auth.api.signInSSO({
|
|
575
|
+
body: {
|
|
576
|
+
providerId: "default-saml",
|
|
577
|
+
callbackURL: "http://localhost:3000/dashboard",
|
|
578
|
+
},
|
|
579
|
+
});
|
|
580
|
+
|
|
581
|
+
expect(signInResponse).toEqual({
|
|
582
|
+
url: expect.stringContaining("http://localhost:8081"),
|
|
583
|
+
redirect: true,
|
|
584
|
+
});
|
|
585
|
+
});
|
|
586
|
+
});
|
|
587
|
+
|
|
496
588
|
describe("SAML SSO", async () => {
|
|
497
589
|
const data = {
|
|
498
590
|
user: [],
|
package/CHANGELOG.md
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
# @better-auth/sso
|
|
2
|
-
|
|
3
|
-
## 1.3.4
|
|
4
|
-
|
|
5
|
-
### Patch Changes
|
|
6
|
-
|
|
7
|
-
- 2bd2fa9: Added support for listing organization members with pagination, sorting, and filtering, and improved client inference for additional organization fields. Also fixed date handling in rate limits and tokens, improved Notion OAuth user extraction, and ensured session is always set in context.
|
|
8
|
-
|
|
9
|
-
Organization
|
|
10
|
-
|
|
11
|
-
- Added listMembers API with pagination, sorting, and filtering.
|
|
12
|
-
- Added membersLimit param to getFullOrganization.
|
|
13
|
-
- Improved client inference for additional fields in organization schemas.
|
|
14
|
-
- Bug Fixes
|
|
15
|
-
- Fixed date handling by casting DB values to Date objects before using date methods.
|
|
16
|
-
- Fixed Notion OAuth to extract user info correctly.
|
|
17
|
-
- Ensured session is set in context when reading from cookie cach
|
|
18
|
-
|
|
19
|
-
- Updated dependencies [2bd2fa9]
|
|
20
|
-
- better-auth@1.3.4
|