@better-auth/sso 1.5.1-beta.1 → 1.5.1-beta.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.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { t as SSOPlugin } from "./index-DHITQH_m.mjs";
1
+ import { t as SSOPlugin } from "./index-DoxMd-mL.mjs";
2
2
 
3
3
  //#region src/client.d.ts
4
4
  interface SSOClientOptions {
@@ -1,6 +1,5 @@
1
1
  import { APIError } from "better-auth/api";
2
- import * as z$1 from "zod/v4";
3
- import z from "zod/v4";
2
+ import * as z from "zod";
4
3
  import { Awaitable, BetterAuthPlugin, OAuth2Tokens, User } from "better-auth";
5
4
  import * as better_call0 from "better-call";
6
5
 
@@ -418,9 +417,9 @@ interface SSOOptions {
418
417
  //#region src/routes/domain-verification.d.ts
419
418
  declare const requestDomainVerification: (options: SSOOptions) => better_call0.StrictEndpoint<"/sso/request-domain-verification", {
420
419
  method: "POST";
421
- body: z$1.ZodObject<{
422
- providerId: z$1.ZodString;
423
- }, z$1.core.$strip>;
420
+ body: z.ZodObject<{
421
+ providerId: z.ZodString;
422
+ }, z.core.$strip>;
424
423
  metadata: {
425
424
  openapi: {
426
425
  summary: string;
@@ -466,9 +465,9 @@ declare const requestDomainVerification: (options: SSOOptions) => better_call0.S
466
465
  }>;
467
466
  declare const verifyDomain: (options: SSOOptions) => better_call0.StrictEndpoint<"/sso/verify-domain", {
468
467
  method: "POST";
469
- body: z$1.ZodObject<{
470
- providerId: z$1.ZodString;
471
- }, z$1.core.$strip>;
468
+ body: z.ZodObject<{
469
+ providerId: z.ZodString;
470
+ }, z.core.$strip>;
472
471
  metadata: {
473
472
  openapi: {
474
473
  summary: string;
@@ -1773,4 +1772,4 @@ declare function sso<O extends SSOOptions>(options?: O | undefined): {
1773
1772
  };
1774
1773
  //#endregion
1775
1774
  export { DataEncryptionAlgorithm as A, TimestampValidationOptions as C, SSOOptions as D, SAMLConfig as E, DigestAlgorithm as M, KeyEncryptionAlgorithm as N, SSOProvider as O, SignatureAlgorithm as P, SAMLConditions as S, OIDCConfig as T, REQUIRED_DISCOVERY_FIELDS as _, fetchDiscoveryDocument as a, DEFAULT_MAX_SAML_METADATA_SIZE as b, normalizeUrl as c, validateDiscoveryUrl as d, DiscoverOIDCConfigParams as f, OIDCDiscoveryDocument as g, HydratedOIDCConfig as h, discoverOIDCConfig as i, DeprecatedAlgorithmBehavior as j, AlgorithmValidationOptions as k, selectTokenEndpointAuthMethod as l, DiscoveryErrorCode as m, sso as n, needsRuntimeDiscovery as o, DiscoveryError as p, computeDiscoveryUrl as r, normalizeDiscoveryUrls as s, SSOPlugin as t, validateDiscoveryDocument as u, RequiredDiscoveryField as v, validateSAMLTimestamp as w, DEFAULT_MAX_SAML_RESPONSE_SIZE as x, DEFAULT_CLOCK_SKEW_MS as y };
1776
- //# sourceMappingURL=index-DHITQH_m.d.mts.map
1775
+ //# sourceMappingURL=index-DoxMd-mL.d.mts.map
package/dist/index.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { A as DataEncryptionAlgorithm, C as TimestampValidationOptions, D as SSOOptions, E as SAMLConfig, M as DigestAlgorithm, N as KeyEncryptionAlgorithm, O as SSOProvider, P as SignatureAlgorithm, S as SAMLConditions, T as OIDCConfig, _ as REQUIRED_DISCOVERY_FIELDS, a as fetchDiscoveryDocument, b as DEFAULT_MAX_SAML_METADATA_SIZE, c as normalizeUrl, d as validateDiscoveryUrl, f as DiscoverOIDCConfigParams, g as OIDCDiscoveryDocument, h as HydratedOIDCConfig, i as discoverOIDCConfig, j as DeprecatedAlgorithmBehavior, k as AlgorithmValidationOptions, l as selectTokenEndpointAuthMethod, m as DiscoveryErrorCode, n as sso, o as needsRuntimeDiscovery, p as DiscoveryError, r as computeDiscoveryUrl, s as normalizeDiscoveryUrls, t as SSOPlugin, u as validateDiscoveryDocument, v as RequiredDiscoveryField, w as validateSAMLTimestamp, x as DEFAULT_MAX_SAML_RESPONSE_SIZE, y as DEFAULT_CLOCK_SKEW_MS } from "./index-DHITQH_m.mjs";
1
+ import { A as DataEncryptionAlgorithm, C as TimestampValidationOptions, D as SSOOptions, E as SAMLConfig, M as DigestAlgorithm, N as KeyEncryptionAlgorithm, O as SSOProvider, P as SignatureAlgorithm, S as SAMLConditions, T as OIDCConfig, _ as REQUIRED_DISCOVERY_FIELDS, a as fetchDiscoveryDocument, b as DEFAULT_MAX_SAML_METADATA_SIZE, c as normalizeUrl, d as validateDiscoveryUrl, f as DiscoverOIDCConfigParams, g as OIDCDiscoveryDocument, h as HydratedOIDCConfig, i as discoverOIDCConfig, j as DeprecatedAlgorithmBehavior, k as AlgorithmValidationOptions, l as selectTokenEndpointAuthMethod, m as DiscoveryErrorCode, n as sso, o as needsRuntimeDiscovery, p as DiscoveryError, r as computeDiscoveryUrl, s as normalizeDiscoveryUrls, t as SSOPlugin, u as validateDiscoveryDocument, v as RequiredDiscoveryField, w as validateSAMLTimestamp, x as DEFAULT_MAX_SAML_RESPONSE_SIZE, y as DEFAULT_CLOCK_SKEW_MS } from "./index-DoxMd-mL.mjs";
2
2
  export { AlgorithmValidationOptions, DEFAULT_CLOCK_SKEW_MS, DEFAULT_MAX_SAML_METADATA_SIZE, DEFAULT_MAX_SAML_RESPONSE_SIZE, DataEncryptionAlgorithm, DeprecatedAlgorithmBehavior, DigestAlgorithm, DiscoverOIDCConfigParams, DiscoveryError, DiscoveryErrorCode, HydratedOIDCConfig, KeyEncryptionAlgorithm, OIDCConfig, OIDCDiscoveryDocument, REQUIRED_DISCOVERY_FIELDS, RequiredDiscoveryField, SAMLConditions, SAMLConfig, SSOOptions, SSOPlugin, SSOProvider, SignatureAlgorithm, TimestampValidationOptions, computeDiscoveryUrl, discoverOIDCConfig, fetchDiscoveryDocument, needsRuntimeDiscovery, normalizeDiscoveryUrls, normalizeUrl, selectTokenEndpointAuthMethod, sso, validateDiscoveryDocument, validateDiscoveryUrl, validateSAMLTimestamp };
package/dist/index.mjs CHANGED
@@ -3,8 +3,7 @@ import { XMLParser, XMLValidator } from "fast-xml-parser";
3
3
  import saml from "samlify";
4
4
  import { X509Certificate } from "node:crypto";
5
5
  import { generateRandomString } from "better-auth/crypto";
6
- import * as z$1 from "zod/v4";
7
- import z from "zod/v4";
6
+ import * as z from "zod";
8
7
  import { base64 } from "@better-auth/utils/base64";
9
8
  import { BetterFetchError, betterFetch } from "@better-fetch/fetch";
10
9
  import { HIDE_METADATA, createAuthorizationURL, generateGenericState, generateState, parseGenericState, parseState, validateAuthorizationCode, validateToken } from "better-auth";
@@ -218,7 +217,7 @@ async function assignOrganizationByDomain(ctx, options) {
218
217
  //#region src/routes/domain-verification.ts
219
218
  const DNS_LABEL_MAX_LENGTH = 63;
220
219
  const DEFAULT_TOKEN_PREFIX = "better-auth-token";
221
- const domainVerificationBodySchema = z$1.object({ providerId: z$1.string() });
220
+ const domainVerificationBodySchema = z.object({ providerId: z.string() });
222
221
  function getVerificationIdentifier(options, providerId) {
223
222
  return `_${options.domainVerification?.tokenPrefix || DEFAULT_TOKEN_PREFIX}-${providerId}`;
224
223
  }
@@ -2374,7 +2373,20 @@ async function handleOIDCCallback(ctx, options, providerId, stateData) {
2374
2373
  });
2375
2374
  if (!tokenResponse) throw ctx.redirect(`${errorURL || callbackURL}?error=invalid_provider&error_description=token_response_not_found`);
2376
2375
  let userInfo = null;
2377
- if (tokenResponse.idToken) {
2376
+ const mapping = config.mapping || {};
2377
+ if (config.userInfoEndpoint) {
2378
+ const userInfoResponse = await betterFetch(config.userInfoEndpoint, { headers: { Authorization: `Bearer ${tokenResponse.accessToken}` } });
2379
+ if (userInfoResponse.error) throw ctx.redirect(`${errorURL || callbackURL}?error=invalid_provider&error_description=${userInfoResponse.error.message}`);
2380
+ const rawUserInfo = userInfoResponse.data;
2381
+ userInfo = {
2382
+ ...Object.fromEntries(Object.entries(mapping.extraFields || {}).map(([key, value]) => [key, rawUserInfo[value]])),
2383
+ id: rawUserInfo[mapping.id || "sub"],
2384
+ email: rawUserInfo[mapping.email || "email"],
2385
+ emailVerified: options?.trustEmailVerified ? rawUserInfo[mapping.emailVerified || "email_verified"] : false,
2386
+ name: rawUserInfo[mapping.name || "name"],
2387
+ image: rawUserInfo[mapping.image || "picture"]
2388
+ };
2389
+ } else if (tokenResponse.idToken) {
2378
2390
  const idToken = decodeJwt(tokenResponse.idToken);
2379
2391
  if (!config.jwksEndpoint) throw ctx.redirect(`${errorURL || callbackURL}?error=invalid_provider&error_description=jwks_endpoint_not_found`);
2380
2392
  const verified = await validateToken(tokenResponse.idToken, config.jwksEndpoint, {
@@ -2385,7 +2397,6 @@ async function handleOIDCCallback(ctx, options, providerId, stateData) {
2385
2397
  return null;
2386
2398
  });
2387
2399
  if (!verified) throw ctx.redirect(`${errorURL || callbackURL}?error=invalid_provider&error_description=token_not_verified`);
2388
- const mapping = config.mapping || {};
2389
2400
  userInfo = {
2390
2401
  ...Object.fromEntries(Object.entries(mapping.extraFields || {}).map(([key, value]) => [key, verified.payload[value]])),
2391
2402
  id: idToken[mapping.id || "sub"],
@@ -2394,13 +2405,7 @@ async function handleOIDCCallback(ctx, options, providerId, stateData) {
2394
2405
  name: idToken[mapping.name || "name"],
2395
2406
  image: idToken[mapping.image || "picture"]
2396
2407
  };
2397
- }
2398
- if (!userInfo) {
2399
- if (!config.userInfoEndpoint) throw ctx.redirect(`${errorURL || callbackURL}?error=invalid_provider&error_description=user_info_endpoint_not_found`);
2400
- const userInfoResponse = await betterFetch(config.userInfoEndpoint, { headers: { Authorization: `Bearer ${tokenResponse.accessToken}` } });
2401
- if (userInfoResponse.error) throw ctx.redirect(`${errorURL || callbackURL}?error=invalid_provider&error_description=${userInfoResponse.error.message}`);
2402
- userInfo = userInfoResponse.data;
2403
- }
2408
+ } else throw ctx.redirect(`${errorURL || callbackURL}?error=invalid_provider&error_description=user_info_endpoint_not_found`);
2404
2409
  if (!userInfo.email || !userInfo.id) throw ctx.redirect(`${errorURL || callbackURL}?error=invalid_provider&error_description=missing_user_info`);
2405
2410
  const isTrustedProvider = "domainVerified" in provider && provider.domainVerified === true && validateEmailDomain(userInfo.email, provider.domain);
2406
2411
  const linked = await handleOAuthUserInfo(ctx, {