@better-auth/sso 1.6.11 → 1.6.12

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
@@ -1,4 +1,4 @@
1
- import { t as PACKAGE_VERSION } from "./version-D_ggtAOl.mjs";
1
+ import { t as PACKAGE_VERSION } from "./version-dnGn0OgM.mjs";
2
2
  //#region src/client.ts
3
3
  const ssoClient = (options) => {
4
4
  return {
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as PACKAGE_VERSION } from "./version-D_ggtAOl.mjs";
1
+ import { t as PACKAGE_VERSION } from "./version-dnGn0OgM.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 { X509Certificate } from "node:crypto";
@@ -8,6 +8,7 @@ import * as z from "zod";
8
8
  import { isPublicRoutableHost } from "@better-auth/core/utils/host";
9
9
  import { BetterFetchError, betterFetch } from "@better-fetch/fetch";
10
10
  import { base64 } from "@better-auth/utils/base64";
11
+ import { isAPIError } from "@better-auth/core/utils/is-api-error";
11
12
  import { HIDE_METADATA, createAuthorizationURL, generateGenericState, generateState, parseGenericState, parseState, validateAuthorizationCode, validateToken } from "better-auth";
12
13
  import { deleteSessionCookie, setSessionCookie } from "better-auth/cookies";
13
14
  import { handleOAuthUserInfo } from "better-auth/oauth2";
@@ -1809,23 +1810,35 @@ async function processSAMLResponse(ctx, params, options) {
1809
1810
  }
1810
1811
  const isTrustedProvider = ctx.context.trustedProviders.includes(providerId) || "domainVerified" in provider && !!provider.domainVerified && validateEmailDomain(userInfo.email, provider.domain);
1811
1812
  const callbackUrl = relayState?.callbackURL || parsedSamlConfig.callbackUrl || ctx.context.baseURL;
1812
- const result = await handleOAuthUserInfo(ctx, {
1813
- userInfo: {
1814
- email: userInfo.email,
1815
- name: userInfo.name || userInfo.email,
1816
- id: userInfo.id,
1817
- emailVerified: Boolean(userInfo.emailVerified)
1818
- },
1819
- account: {
1820
- providerId,
1821
- accountId: userInfo.id,
1822
- accessToken: "",
1823
- refreshToken: ""
1824
- },
1825
- callbackURL: callbackUrl,
1826
- disableSignUp: options?.disableImplicitSignUp,
1827
- isTrustedProvider
1828
- });
1813
+ const errorUrl = relayState?.errorURL || samlRedirectUrl;
1814
+ let result;
1815
+ try {
1816
+ result = await handleOAuthUserInfo(ctx, {
1817
+ userInfo: {
1818
+ email: userInfo.email,
1819
+ name: userInfo.name || userInfo.email,
1820
+ id: userInfo.id,
1821
+ emailVerified: Boolean(userInfo.emailVerified)
1822
+ },
1823
+ account: {
1824
+ providerId,
1825
+ accountId: userInfo.id,
1826
+ accessToken: "",
1827
+ refreshToken: ""
1828
+ },
1829
+ callbackURL: callbackUrl,
1830
+ disableSignUp: options?.disableImplicitSignUp,
1831
+ isTrustedProvider
1832
+ });
1833
+ } catch (e) {
1834
+ if (isAPIError(e) && e.body?.code) {
1835
+ const params = new URLSearchParams({ error: e.body.code });
1836
+ if (e.body.message) params.set("error_description", e.body.message);
1837
+ const sep = errorUrl.includes("?") ? "&" : "?";
1838
+ throw ctx.redirect(`${errorUrl}${sep}${params.toString()}`);
1839
+ }
1840
+ throw e;
1841
+ }
1829
1842
  if (result.error) throw ctx.redirect(`${callbackUrl}?error=${result.error.split(" ").join("_")}`);
1830
1843
  const { session, user } = result.data;
1831
1844
  if (options?.provisionUser && (result.isRegister || options.provisionUserOnEveryLogin)) await options.provisionUser({
@@ -2698,30 +2711,47 @@ async function handleOIDCCallback(ctx, options, providerId, stateData) {
2698
2711
  } else throw ctx.redirect(`${errorURL || callbackURL}?error=invalid_provider&error_description=user_info_endpoint_not_found`);
2699
2712
  if (!userInfo.email || !userInfo.id) throw ctx.redirect(`${errorURL || callbackURL}?error=invalid_provider&error_description=missing_user_info`);
2700
2713
  const isTrustedProvider = "domainVerified" in provider && provider.domainVerified === true && validateEmailDomain(userInfo.email, provider.domain);
2701
- const linked = await handleOAuthUserInfo(ctx, {
2702
- userInfo: {
2703
- email: userInfo.email,
2704
- name: userInfo.name || "",
2705
- id: userInfo.id,
2706
- image: userInfo.image,
2707
- emailVerified: options?.trustEmailVerified ? userInfo.emailVerified || false : false
2708
- },
2709
- account: {
2710
- idToken: tokenResponse.idToken,
2711
- accessToken: tokenResponse.accessToken,
2712
- refreshToken: tokenResponse.refreshToken,
2713
- accountId: userInfo.id,
2714
- providerId: provider.providerId,
2715
- accessTokenExpiresAt: tokenResponse.accessTokenExpiresAt,
2716
- refreshTokenExpiresAt: tokenResponse.refreshTokenExpiresAt,
2717
- scope: tokenResponse.scopes?.join(",")
2718
- },
2719
- callbackURL,
2720
- disableSignUp: options?.disableImplicitSignUp && !requestSignUp,
2721
- overrideUserInfo: config.overrideUserInfo,
2722
- isTrustedProvider
2723
- });
2724
- if (linked.error) throw ctx.redirect(`${errorURL || callbackURL}?error=${linked.error}`);
2714
+ let linked;
2715
+ try {
2716
+ linked = await handleOAuthUserInfo(ctx, {
2717
+ userInfo: {
2718
+ email: userInfo.email,
2719
+ name: userInfo.name || "",
2720
+ id: userInfo.id,
2721
+ image: userInfo.image,
2722
+ emailVerified: options?.trustEmailVerified ? userInfo.emailVerified || false : false
2723
+ },
2724
+ account: {
2725
+ idToken: tokenResponse.idToken,
2726
+ accessToken: tokenResponse.accessToken,
2727
+ refreshToken: tokenResponse.refreshToken,
2728
+ accountId: userInfo.id,
2729
+ providerId: provider.providerId,
2730
+ accessTokenExpiresAt: tokenResponse.accessTokenExpiresAt,
2731
+ refreshTokenExpiresAt: tokenResponse.refreshTokenExpiresAt,
2732
+ scope: tokenResponse.scopes?.join(",")
2733
+ },
2734
+ callbackURL,
2735
+ disableSignUp: options?.disableImplicitSignUp && !requestSignUp,
2736
+ overrideUserInfo: config.overrideUserInfo,
2737
+ isTrustedProvider
2738
+ });
2739
+ } catch (e) {
2740
+ if (isAPIError(e) && e.body?.code) {
2741
+ const baseURL = errorURL || callbackURL;
2742
+ const params = new URLSearchParams({ error: e.body.code });
2743
+ if (e.body.message) params.set("error_description", e.body.message);
2744
+ const sep = baseURL.includes("?") ? "&" : "?";
2745
+ throw ctx.redirect(`${baseURL}${sep}${params.toString()}`);
2746
+ }
2747
+ throw e;
2748
+ }
2749
+ if (linked.error) {
2750
+ const baseURL = errorURL || callbackURL;
2751
+ const params = new URLSearchParams({ error: linked.error });
2752
+ const sep = baseURL.includes("?") ? "&" : "?";
2753
+ throw ctx.redirect(`${baseURL}${sep}${params.toString()}`);
2754
+ }
2725
2755
  const { session, user } = linked.data;
2726
2756
  if (options?.provisionUser && (linked.isRegister || options.provisionUserOnEveryLogin)) await options.provisionUser({
2727
2757
  user,
@@ -1,5 +1,5 @@
1
1
  //#endregion
2
2
  //#region src/version.ts
3
- const PACKAGE_VERSION = "1.6.11";
3
+ const PACKAGE_VERSION = "1.6.12";
4
4
  //#endregion
5
5
  export { PACKAGE_VERSION as t };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@better-auth/sso",
3
- "version": "1.6.11",
3
+ "version": "1.6.12",
4
4
  "description": "SSO plugin for Better Auth",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -56,7 +56,7 @@
56
56
  }
57
57
  },
58
58
  "dependencies": {
59
- "fast-xml-parser": "^5.5.7",
59
+ "fast-xml-parser": "^5.8.0",
60
60
  "jose": "^6.1.3",
61
61
  "samlify": "~2.10.2",
62
62
  "tldts": "^6.1.0",
@@ -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.11",
74
- "better-auth": "1.6.11"
73
+ "@better-auth/core": "1.6.12",
74
+ "better-auth": "1.6.12"
75
75
  },
76
76
  "peerDependencies": {
77
- "@better-auth/utils": "0.4.0",
77
+ "@better-auth/utils": "0.4.1",
78
78
  "@better-fetch/fetch": "1.1.21",
79
79
  "better-call": "1.3.5",
80
- "@better-auth/core": "^1.6.11",
81
- "better-auth": "^1.6.11"
80
+ "@better-auth/core": "^1.6.12",
81
+ "better-auth": "^1.6.12"
82
82
  },
83
83
  "scripts": {
84
84
  "build": "tsdown",