@better-auth/sso 1.6.0 → 1.6.2
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/dist/client.mjs
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as PACKAGE_VERSION } from "./version-
|
|
1
|
+
import { t as PACKAGE_VERSION } from "./version-BVfKiZvw.mjs";
|
|
2
2
|
import { APIError, createAuthEndpoint, createAuthMiddleware, getSessionFromCtx, sessionMiddleware } from "better-auth/api";
|
|
3
3
|
import { XMLParser, XMLValidator } from "fast-xml-parser";
|
|
4
4
|
import * as saml from "samlify";
|
|
@@ -606,7 +606,7 @@ function countAssertions(xml) {
|
|
|
606
606
|
function validateSingleAssertion(samlResponse) {
|
|
607
607
|
let xml;
|
|
608
608
|
try {
|
|
609
|
-
xml = new TextDecoder().decode(base64.decode(samlResponse));
|
|
609
|
+
xml = new TextDecoder().decode(base64.decode(samlResponse.replace(/\s+/g, "")));
|
|
610
610
|
if (!xml.includes("<")) throw new Error("Not XML");
|
|
611
611
|
} catch {
|
|
612
612
|
throw new APIError("BAD_REQUEST", {
|
|
@@ -2181,7 +2181,8 @@ const signInSSO = (options) => {
|
|
|
2181
2181
|
if (provider.samlConfig) {
|
|
2182
2182
|
const parsedSamlConfig = typeof provider.samlConfig === "object" ? provider.samlConfig : safeJsonParse(provider.samlConfig);
|
|
2183
2183
|
if (!parsedSamlConfig) throw new APIError("BAD_REQUEST", { message: "Invalid SAML configuration" });
|
|
2184
|
-
if (parsedSamlConfig.authnRequestsSigned && !parsedSamlConfig.spMetadata?.privateKey && !parsedSamlConfig.privateKey)
|
|
2184
|
+
if (parsedSamlConfig.authnRequestsSigned && !parsedSamlConfig.spMetadata?.privateKey && !parsedSamlConfig.privateKey) throw new APIError("BAD_REQUEST", { message: "authnRequestsSigned is enabled but no privateKey provided in spMetadata or samlConfig" });
|
|
2185
|
+
const { state: relayState } = await generateRelayState(ctx, void 0, false);
|
|
2185
2186
|
let metadata = parsedSamlConfig.spMetadata.metadata;
|
|
2186
2187
|
if (!metadata) metadata = saml.SPMetadata({
|
|
2187
2188
|
entityID: parsedSamlConfig.spMetadata?.entityID || parsedSamlConfig.issuer,
|
|
@@ -2197,7 +2198,8 @@ const signInSSO = (options) => {
|
|
|
2197
2198
|
metadata,
|
|
2198
2199
|
allowCreate: true,
|
|
2199
2200
|
privateKey: parsedSamlConfig.spMetadata?.privateKey || parsedSamlConfig.privateKey,
|
|
2200
|
-
privateKeyPass: parsedSamlConfig.spMetadata?.privateKeyPass
|
|
2201
|
+
privateKeyPass: parsedSamlConfig.spMetadata?.privateKeyPass,
|
|
2202
|
+
relayState
|
|
2201
2203
|
});
|
|
2202
2204
|
const idpData = parsedSamlConfig.idpMetadata;
|
|
2203
2205
|
let idp;
|
|
@@ -2223,7 +2225,6 @@ const signInSSO = (options) => {
|
|
|
2223
2225
|
});
|
|
2224
2226
|
const loginRequest = sp.createLoginRequest(idp, "redirect");
|
|
2225
2227
|
if (!loginRequest) throw new APIError("BAD_REQUEST", { message: "Invalid SAML request" });
|
|
2226
|
-
const { state: relayState } = await generateRelayState(ctx, void 0, false);
|
|
2227
2228
|
if (loginRequest.id && options?.saml?.enableInResponseToValidation !== false) {
|
|
2228
2229
|
const ttl = options?.saml?.requestTTL ?? 3e5;
|
|
2229
2230
|
const record = {
|
|
@@ -2239,7 +2240,7 @@ const signInSSO = (options) => {
|
|
|
2239
2240
|
});
|
|
2240
2241
|
}
|
|
2241
2242
|
return ctx.json({
|
|
2242
|
-
url:
|
|
2243
|
+
url: loginRequest.context,
|
|
2243
2244
|
redirect: true
|
|
2244
2245
|
});
|
|
2245
2246
|
}
|
|
@@ -2534,9 +2535,9 @@ const callbackSSOSAML = (options) => {
|
|
|
2534
2535
|
throw ctx.redirect(safeRedirectUrl);
|
|
2535
2536
|
}
|
|
2536
2537
|
if (!ctx.body?.SAMLResponse) throw new APIError("BAD_REQUEST", { message: "SAMLResponse is required for POST requests" });
|
|
2537
|
-
const { SAMLResponse } = ctx.body;
|
|
2538
2538
|
const maxResponseSize = options?.saml?.maxResponseSize ?? 262144;
|
|
2539
|
-
if (new TextEncoder().encode(SAMLResponse).length > maxResponseSize) throw new APIError("BAD_REQUEST", { message: `SAML response exceeds maximum allowed size (${maxResponseSize} bytes)` });
|
|
2539
|
+
if (new TextEncoder().encode(ctx.body.SAMLResponse).length > maxResponseSize) throw new APIError("BAD_REQUEST", { message: `SAML response exceeds maximum allowed size (${maxResponseSize} bytes)` });
|
|
2540
|
+
const SAMLResponse = ctx.body.SAMLResponse.replace(/\s+/g, "");
|
|
2540
2541
|
let relayState = null;
|
|
2541
2542
|
if (ctx.body.RelayState) try {
|
|
2542
2543
|
relayState = await parseRelayState(ctx);
|
|
@@ -2811,12 +2812,12 @@ const acsEndpoint = (options) => {
|
|
|
2811
2812
|
}
|
|
2812
2813
|
}
|
|
2813
2814
|
}, async (ctx) => {
|
|
2814
|
-
const { SAMLResponse } = ctx.body;
|
|
2815
2815
|
const { providerId } = ctx.params;
|
|
2816
2816
|
const currentCallbackPath = `${ctx.context.baseURL}/sso/saml2/sp/acs/${providerId}`;
|
|
2817
2817
|
const appOrigin = new URL(ctx.context.baseURL).origin;
|
|
2818
2818
|
const maxResponseSize = options?.saml?.maxResponseSize ?? 262144;
|
|
2819
|
-
if (new TextEncoder().encode(SAMLResponse).length > maxResponseSize) throw new APIError("BAD_REQUEST", { message: `SAML response exceeds maximum allowed size (${maxResponseSize} bytes)` });
|
|
2819
|
+
if (new TextEncoder().encode(ctx.body.SAMLResponse).length > maxResponseSize) throw new APIError("BAD_REQUEST", { message: `SAML response exceeds maximum allowed size (${maxResponseSize} bytes)` });
|
|
2820
|
+
const SAMLResponse = ctx.body.SAMLResponse.replace(/\s+/g, "");
|
|
2820
2821
|
let relayState = null;
|
|
2821
2822
|
if (ctx.body.RelayState) try {
|
|
2822
2823
|
relayState = await parseRelayState(ctx);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@better-auth/sso",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.2",
|
|
4
4
|
"description": "SSO plugin for Better Auth",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -70,15 +70,15 @@
|
|
|
70
70
|
"express": "^5.2.1",
|
|
71
71
|
"oauth2-mock-server": "^8.2.2",
|
|
72
72
|
"tsdown": "0.21.1",
|
|
73
|
-
"@better-auth/core": "1.6.
|
|
74
|
-
"better-auth": "1.6.
|
|
73
|
+
"@better-auth/core": "1.6.2",
|
|
74
|
+
"better-auth": "1.6.2"
|
|
75
75
|
},
|
|
76
76
|
"peerDependencies": {
|
|
77
77
|
"@better-auth/utils": "0.4.0",
|
|
78
78
|
"@better-fetch/fetch": "1.1.21",
|
|
79
79
|
"better-call": "1.3.5",
|
|
80
|
-
"@better-auth/core": "^1.6.
|
|
81
|
-
"better-auth": "^1.6.
|
|
80
|
+
"@better-auth/core": "^1.6.2",
|
|
81
|
+
"better-auth": "^1.6.2"
|
|
82
82
|
},
|
|
83
83
|
"scripts": {
|
|
84
84
|
"build": "tsdown",
|