@better-auth/oauth-provider 1.7.0-beta.0 → 1.7.0-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.
@@ -1,4 +1,4 @@
1
- import { a as getClient } from "./utils-CIbcUsZ5.mjs";
1
+ import { a as getClient } from "./utils-Cx_XnD9i.mjs";
2
2
  import { APIError } from "better-call";
3
3
  import { ASSERTION_SIGNING_ALGORITHMS, CLIENT_ASSERTION_TYPE } from "@better-auth/core/oauth2";
4
4
  import { createLocalJWKSet, decodeJwt, decodeProtectedHeader, jwtVerify } from "jose";
@@ -62,7 +62,7 @@ function isPrivateHostname(hostname) {
62
62
  if (host === "metadata.google.internal") return true;
63
63
  return false;
64
64
  }
65
- function validateJwksUri(ctx, jwksUri) {
65
+ function validateJwksUri(ctx, jwksUri, clientIdUrlOrigin) {
66
66
  const parsed = new URL(jwksUri);
67
67
  if (parsed.protocol !== "https:") throw new APIError("BAD_REQUEST", {
68
68
  error_description: "jwks_uri must use HTTPS",
@@ -72,11 +72,20 @@ function validateJwksUri(ctx, jwksUri) {
72
72
  error_description: "jwks_uri must not point to a private or reserved address",
73
73
  error: "invalid_client"
74
74
  });
75
+ if (clientIdUrlOrigin && parsed.origin === clientIdUrlOrigin) return;
75
76
  if (!ctx.context.isTrustedOrigin(parsed.href)) throw new APIError("BAD_REQUEST", {
76
77
  error_description: "client jwks_uri is not trusted",
77
78
  error: "invalid_client"
78
79
  });
79
80
  }
81
+ function urlClientIdOrigin(clientId) {
82
+ if (!clientId.startsWith("https://") && !clientId.startsWith("http://")) return;
83
+ try {
84
+ return new URL(clientId).origin;
85
+ } catch {
86
+ return;
87
+ }
88
+ }
80
89
  async function fetchJwksFromUri(jwksUri) {
81
90
  const controller = new AbortController();
82
91
  const timeout = setTimeout(() => controller.abort(), JWKS_FETCH_TIMEOUT_MS);
@@ -100,7 +109,7 @@ async function fetchClientJwks(ctx, client) {
100
109
  error_description: "client has no JWKS configured",
101
110
  error: "invalid_client"
102
111
  });
103
- validateJwksUri(ctx, client.jwksUri);
112
+ validateJwksUri(ctx, client.jwksUri, urlClientIdOrigin(client.clientId));
104
113
  const now = Date.now();
105
114
  const cached = jwksCache.get(client.jwksUri);
106
115
  if (cached && now - cached.fetchedAt < JWKS_CACHE_TTL_MS) return cached.jwks;
@@ -1,4 +1,4 @@
1
- import { a as ResourceServerMetadata } from "./oauth-C8aTlaAC.mjs";
1
+ import { o as ResourceServerMetadata } from "./oauth-CU79t-eG.mjs";
2
2
  import { JWTPayload, JWTVerifyOptions } from "jose";
3
3
  import { Auth } from "better-auth/types";
4
4
 
@@ -1,6 +1,6 @@
1
1
  import { t as handleMcpErrors } from "./mcp-CYnz-MXn.mjs";
2
- import { o as getJwtPlugin, s as getOAuthProviderPlugin } from "./utils-CIbcUsZ5.mjs";
3
- import { t as PACKAGE_VERSION } from "./version-BGWhjYBb.mjs";
2
+ import { o as getJwtPlugin, s as getOAuthProviderPlugin } from "./utils-Cx_XnD9i.mjs";
3
+ import { t as PACKAGE_VERSION } from "./version-CZxZ64qJ.mjs";
4
4
  import { verifyAccessToken } from "better-auth/oauth2";
5
5
  import { APIError } from "better-call";
6
6
  import { logger } from "@better-auth/core/env";
package/dist/client.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { n as oauthProvider } from "./oauth-Dh4YXCXY.mjs";
1
+ import { n as oauthProvider } from "./oauth-DJcZ8MMZ.mjs";
2
2
  import * as _better_fetch_fetch0 from "@better-fetch/fetch";
3
3
 
4
4
  //#region src/client.d.ts
package/dist/client.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as PACKAGE_VERSION } from "./version-BGWhjYBb.mjs";
1
+ import { t as PACKAGE_VERSION } from "./version-CZxZ64qJ.mjs";
2
2
  import { safeJSONParse } from "@better-auth/core/utils/json";
3
3
  //#region src/client.ts
4
4
  function parseSignedQuery(search) {
package/dist/index.d.mts CHANGED
@@ -1,9 +1,10 @@
1
- import { _ as Awaitable, a as ResourceServerMetadata, c as OAuthConsent, d as OAuthRefreshToken, f as Prompt, g as VerificationValue, h as StoreTokenType, i as OIDCMetadata, l as OAuthOpaqueAccessToken, m as Scope, n as GrantType, o as AuthorizePrompt, p as SchemaClient, r as OAuthClient, s as OAuthAuthorizationQuery, t as AuthServerMetadata, u as OAuthOptions } from "./oauth-C8aTlaAC.mjs";
2
- import { n as oauthProvider, t as getOAuthProviderState } from "./oauth-Dh4YXCXY.mjs";
1
+ import { _ as Scope, a as OIDCMetadata, b as Awaitable, c as AuthorizePrompt, d as OAuthConsent, f as OAuthOpaqueAccessToken, g as SchemaClient, h as Prompt, i as OAuthClient, l as ClientDiscovery, m as OAuthRefreshToken, n as AuthServerMetadata, o as ResourceServerMetadata, p as OAuthOptions, r as GrantType, s as TokenEndpointAuthMethod, t as AuthMethod, u as OAuthAuthorizationQuery, v as StoreTokenType, y as VerificationValue } from "./oauth-CU79t-eG.mjs";
2
+ import { a as OAuthErrorCode, c as OAuthRedirectOnError, i as OAuthEndpointRedirectContext, n as oauthProvider, o as OAuthFieldErrorCode, r as OAuthEndpointErrorResult, s as OAuthFieldErrorCodeMap, t as getOAuthProviderState } from "./oauth-DJcZ8MMZ.mjs";
3
3
  import { verifyAccessToken } from "better-auth/oauth2";
4
4
  import { JWSAlgorithms, JwtOptions } from "better-auth/plugins";
5
5
  import { JWTPayload } from "jose";
6
6
  import { GenericEndpointContext } from "@better-auth/core";
7
+ import * as better_auth0 from "better-auth";
7
8
 
8
9
  //#region src/mcp.d.ts
9
10
  /**
@@ -27,7 +28,37 @@ declare function authServerMetadata(ctx: GenericEndpointContext, opts?: JwtOptio
27
28
  }): AuthServerMetadata;
28
29
  declare function oidcServerMetadata(ctx: GenericEndpointContext, opts: OAuthOptions<Scope[]> & {
29
30
  claims?: string[];
30
- }): Omit<OIDCMetadata, "id_token_signing_alg_values_supported"> & {
31
+ }): {
32
+ jwks_uri?: string | undefined;
33
+ userinfo_endpoint: string;
34
+ acr_values_supported: string[];
35
+ subject_types_supported: ("public" | "pairwise")[];
36
+ claims_supported: string[];
37
+ end_session_endpoint: string;
38
+ prompt_values_supported: Prompt[];
39
+ issuer: string;
40
+ authorization_endpoint: string;
41
+ token_endpoint: string;
42
+ registration_endpoint: string;
43
+ scopes_supported?: string[] | undefined;
44
+ response_types_supported: "code"[];
45
+ response_modes_supported: "query"[];
46
+ grant_types_supported: GrantType[];
47
+ token_endpoint_auth_methods_supported?: TokenEndpointAuthMethod[] | undefined;
48
+ token_endpoint_auth_signing_alg_values_supported?: better_auth0.AssertionSigningAlgorithm[] | undefined;
49
+ service_documentation?: string | undefined;
50
+ ui_locales_supported?: string[] | undefined;
51
+ op_policy_uri?: string | undefined;
52
+ op_tos_uri?: string | undefined;
53
+ revocation_endpoint?: string | undefined;
54
+ revocation_endpoint_auth_methods_supported?: AuthMethod[] | undefined;
55
+ revocation_endpoint_auth_signing_alg_values_supported?: better_auth0.AssertionSigningAlgorithm[] | undefined;
56
+ introspection_endpoint?: string | undefined;
57
+ introspection_endpoint_auth_methods_supported?: AuthMethod[] | undefined;
58
+ introspection_endpoint_auth_signing_alg_values_supported?: better_auth0.AssertionSigningAlgorithm[] | undefined;
59
+ code_challenge_methods_supported: "S256"[];
60
+ authorization_response_iss_parameter_supported?: boolean | undefined;
61
+ client_id_metadata_document_supported?: boolean | undefined;
31
62
  id_token_signing_alg_values_supported: JWSAlgorithms[] | ["HS256"];
32
63
  };
33
64
  /**
@@ -44,7 +75,7 @@ declare const oauthProviderAuthServerMetadata: <Auth extends {
44
75
  };
45
76
  }>(auth: Auth, opts?: {
46
77
  headers?: HeadersInit;
47
- }) => (_request: Request) => Promise<Response>;
78
+ }) => (request: Request) => Promise<Response>;
48
79
  /**
49
80
  * Provides an exportable `/.well-known/openid-configuration`.
50
81
  *
@@ -59,6 +90,19 @@ declare const oauthProviderOpenIdConfigMetadata: <Auth extends {
59
90
  };
60
91
  }>(auth: Auth, opts?: {
61
92
  headers?: HeadersInit;
62
- }) => (_request: Request) => Promise<Response>;
93
+ }) => (request: Request) => Promise<Response>;
63
94
  //#endregion
64
- export { AuthServerMetadata, AuthorizePrompt, OAuthAuthorizationQuery, OAuthClient, OAuthConsent, OAuthOpaqueAccessToken, OAuthOptions, OAuthRefreshToken, OIDCMetadata, Prompt, ResourceServerMetadata, SchemaClient, Scope, StoreTokenType, VerificationValue, authServerMetadata, getOAuthProviderState, mcpHandler, oauthProvider, oauthProviderAuthServerMetadata, oauthProviderOpenIdConfigMetadata, oidcServerMetadata };
95
+ //#region src/register.d.ts
96
+ declare function checkOAuthClient(client: OAuthClient, opts: OAuthOptions<Scope[]>, settings?: {
97
+ isRegister?: boolean;
98
+ ctx?: GenericEndpointContext;
99
+ }): Promise<void>;
100
+ /**
101
+ * Converts an OAuth 2.0 Dynamic Client Schema to a Database Schema
102
+ *
103
+ * @param input
104
+ * @returns
105
+ */
106
+ declare function oauthToSchema(input: OAuthClient): SchemaClient<Scope[]>;
107
+ //#endregion
108
+ export { AuthServerMetadata, AuthorizePrompt, ClientDiscovery, OAuthAuthorizationQuery, OAuthClient, OAuthConsent, type OAuthEndpointErrorResult, type OAuthEndpointRedirectContext, type OAuthErrorCode, type OAuthFieldErrorCode, type OAuthFieldErrorCodeMap, OAuthOpaqueAccessToken, OAuthOptions, type OAuthRedirectOnError, OAuthRefreshToken, OIDCMetadata, Prompt, ResourceServerMetadata, SchemaClient, Scope, StoreTokenType, VerificationValue, authServerMetadata, checkOAuthClient, getOAuthProviderState, mcpHandler, oauthProvider, oauthProviderAuthServerMetadata, oauthProviderOpenIdConfigMetadata, oauthToSchema, oidcServerMetadata };