@better-auth/oauth-provider 1.5.6 → 1.6.0-beta.0

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.
@@ -5,6 +5,7 @@ import { Auth } from "better-auth/types";
5
5
  //#region src/client-resource.d.ts
6
6
  declare const oauthProviderResourceClient: <T extends Auth | undefined>(auth?: T) => {
7
7
  id: "oauth-provider-resource-client";
8
+ version: string;
8
9
  getActions(): {
9
10
  /**
10
11
  * Performs verification of an access token for your APIs. Can perform
@@ -75,5 +76,4 @@ type ProtectedResourceMetadataOutput<T> = T extends Auth ? (overrides?: Partial<
75
76
  externalScopes?: string[];
76
77
  }) => Promise<ResourceServerMetadata>;
77
78
  //#endregion
78
- export { VerifyAccessTokenRemote, oauthProviderResourceClient };
79
- //# sourceMappingURL=client-resource.d.mts.map
79
+ export { VerifyAccessTokenRemote, oauthProviderResourceClient };
@@ -1,9 +1,9 @@
1
- import { a as getJwtPlugin, g as handleMcpErrors, o as getOAuthProviderPlugin } from "./utils-BDSjyzic.mjs";
1
+ import { a as getJwtPlugin, o as getOAuthProviderPlugin, v as handleMcpErrors } from "./utils-sQ4gYeh3.mjs";
2
+ import { t as PACKAGE_VERSION } from "./version-DevbO3Yy.mjs";
2
3
  import { verifyAccessToken } from "better-auth/oauth2";
3
4
  import { APIError } from "better-call";
4
5
  import { logger } from "@better-auth/core/env";
5
6
  import { BetterAuthError } from "@better-auth/core/error";
6
-
7
7
  //#region src/client-resource.ts
8
8
  const oauthProviderResourceClient = (auth) => {
9
9
  let oauthProviderPlugin;
@@ -23,6 +23,7 @@ const oauthProviderResourceClient = (auth) => {
23
23
  const authServerBasePath = auth?.options.basePath;
24
24
  return {
25
25
  id: "oauth-provider-resource-client",
26
+ version: PACKAGE_VERSION,
26
27
  getActions() {
27
28
  return {
28
29
  verifyAccessToken: (async (token, opts) => {
@@ -83,7 +84,5 @@ const oauthProviderResourceClient = (auth) => {
83
84
  }
84
85
  };
85
86
  };
86
-
87
87
  //#endregion
88
88
  export { oauthProviderResourceClient };
89
- //# sourceMappingURL=client-resource.mjs.map
package/dist/client.d.mts CHANGED
@@ -1,9 +1,10 @@
1
- import { n as oauthProvider } from "./oauth-E89Dh-ZC.mjs";
1
+ import { n as oauthProvider } from "./oauth-CEoJtL3Y.mjs";
2
2
  import * as _better_fetch_fetch0 from "@better-fetch/fetch";
3
3
 
4
4
  //#region src/client.d.ts
5
5
  declare const oauthProviderClient: () => {
6
6
  id: "oauth-provider-client";
7
+ version: string;
7
8
  fetchPlugins: {
8
9
  id: string;
9
10
  name: string;
@@ -15,5 +16,4 @@ declare const oauthProviderClient: () => {
15
16
  $InferServerPlugin: ReturnType<typeof oauthProvider>;
16
17
  };
17
18
  //#endregion
18
- export { oauthProviderClient };
19
- //# sourceMappingURL=client.d.mts.map
19
+ export { oauthProviderClient };
package/dist/client.mjs CHANGED
@@ -1,5 +1,5 @@
1
+ import { t as PACKAGE_VERSION } from "./version-DevbO3Yy.mjs";
1
2
  import { safeJSONParse } from "@better-auth/core/utils/json";
2
-
3
3
  //#region src/client.ts
4
4
  function parseSignedQuery(search) {
5
5
  const params = new URLSearchParams(search);
@@ -15,6 +15,7 @@ function parseSignedQuery(search) {
15
15
  const oauthProviderClient = () => {
16
16
  return {
17
17
  id: "oauth-provider-client",
18
+ version: PACKAGE_VERSION,
18
19
  fetchPlugins: [{
19
20
  id: "oauth-provider-signin",
20
21
  name: "oauth-provider-signin",
@@ -32,7 +33,5 @@ const oauthProviderClient = () => {
32
33
  $InferServerPlugin: {}
33
34
  };
34
35
  };
35
-
36
36
  //#endregion
37
37
  export { oauthProviderClient };
38
- //# sourceMappingURL=client.mjs.map
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
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-4vgZlF-I.mjs";
2
- import { n as oauthProvider, t as getOAuthProviderState } from "./oauth-E89Dh-ZC.mjs";
2
+ import { n as oauthProvider, t as getOAuthProviderState } from "./oauth-CEoJtL3Y.mjs";
3
3
  import { verifyAccessToken } from "better-auth/oauth2";
4
4
  import { JWSAlgorithms, JwtOptions } from "better-auth/plugins";
5
5
  import { JWTPayload } from "jose";
@@ -61,5 +61,4 @@ declare const oauthProviderOpenIdConfigMetadata: <Auth extends {
61
61
  headers?: HeadersInit;
62
62
  }) => (_request: Request) => Promise<Response>;
63
63
  //#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 };
65
- //# sourceMappingURL=index.d.mts.map
64
+ export { AuthServerMetadata, AuthorizePrompt, OAuthAuthorizationQuery, OAuthClient, OAuthConsent, OAuthOpaqueAccessToken, OAuthOptions, OAuthRefreshToken, OIDCMetadata, Prompt, ResourceServerMetadata, SchemaClient, Scope, StoreTokenType, VerificationValue, authServerMetadata, getOAuthProviderState, mcpHandler, oauthProvider, oauthProviderAuthServerMetadata, oauthProviderOpenIdConfigMetadata, oidcServerMetadata };
package/dist/index.mjs CHANGED
@@ -1,4 +1,5 @@
1
- import { _ as mcpHandler, a as getJwtPlugin, c as isPKCERequired, d as resolveSubjectIdentifier, f as storeClientSecret, h as verifyOAuthQueryParams, i as getClient, l as parseClientMetadata, m as validateClientCredentials, n as decryptStoredClientSecret, p as storeToken, r as deleteFromPrompt, s as getStoredToken, t as basicToClientCredentials, u as parsePrompt } from "./utils-BDSjyzic.mjs";
1
+ import { _ as verifyOAuthQueryParams, a as getJwtPlugin, c as isPKCERequired, d as parsePrompt, f as resolveSessionAuthTime, g as validateClientCredentials, h as storeToken, i as getClient, l as normalizeTimestampValue, m as storeClientSecret, n as decryptStoredClientSecret, p as resolveSubjectIdentifier, r as deleteFromPrompt, s as getStoredToken, t as basicToClientCredentials, u as parseClientMetadata, y as mcpHandler } from "./utils-sQ4gYeh3.mjs";
2
+ import { t as PACKAGE_VERSION } from "./version-DevbO3Yy.mjs";
2
3
  import { APIError, createAuthEndpoint, createAuthMiddleware, getOAuthState, getSessionFromCtx, sessionMiddleware } from "better-auth/api";
3
4
  import { generateCodeChallenge, getJwks, verifyJwsAccessToken } from "better-auth/oauth2";
4
5
  import { APIError as APIError$1 } from "better-call";
@@ -12,7 +13,6 @@ import { mergeSchema } from "better-auth/db";
12
13
  import * as z from "zod";
13
14
  import { signJWT, toExpJWT } from "better-auth/plugins";
14
15
  import { SignJWT, compactVerify, createLocalJWKSet, decodeJwt } from "jose";
15
-
16
16
  //#region src/consent.ts
17
17
  async function consentEndpoint(ctx, opts) {
18
18
  const _query = (await oAuthState.get())?.query;
@@ -97,7 +97,6 @@ async function consentEndpoint(ctx, opts) {
97
97
  url
98
98
  };
99
99
  }
100
-
101
100
  //#endregion
102
101
  //#region src/continue.ts
103
102
  async function continueEndpoint(ctx, opts) {
@@ -129,7 +128,9 @@ async function created(ctx, opts) {
129
128
  error_description: "missing oauth query",
130
129
  error: "invalid_request"
131
130
  });
132
- ctx.query = deleteFromPrompt(new URLSearchParams(_query), "create");
131
+ const query = new URLSearchParams(_query);
132
+ ctx.headers?.set("accept", "application/json");
133
+ ctx.query = deleteFromPrompt(query, "create");
133
134
  const { url } = await authorizeEndpoint(ctx, opts);
134
135
  return {
135
136
  redirect: true,
@@ -151,7 +152,6 @@ async function postLogin(ctx, opts) {
151
152
  url
152
153
  };
153
154
  }
154
-
155
155
  //#endregion
156
156
  //#region src/userinfo.ts
157
157
  /**
@@ -224,7 +224,6 @@ async function userInfoEndpoint(ctx, opts) {
224
224
  ...additionalInfoUserClaims
225
225
  };
226
226
  }
227
-
228
227
  //#endregion
229
228
  //#region src/token.ts
230
229
  /**
@@ -296,9 +295,9 @@ async function createIdToken(ctx, opts, user, client, scopes, nonce, sessionId,
296
295
  const jwtPluginOptions = opts.disableJwtPlugin ? void 0 : getJwtPlugin(ctx.context).options;
297
296
  const payload = {
298
297
  ...userClaims,
299
- ...customClaims,
300
298
  auth_time: authTimeSec,
301
299
  acr,
300
+ ...customClaims,
302
301
  iss: jwtPluginOptions?.jwt?.issuer ?? ctx.context.baseURL,
303
302
  sub: resolvedSub,
304
303
  aud: client.clientId,
@@ -565,7 +564,7 @@ async function handleAuthorizationCodeGrant(ctx, opts) {
565
564
  error_description: "session no longer exists",
566
565
  error: "invalid_request"
567
566
  });
568
- const authTime = verificationValue.authTime != null ? new Date(verificationValue.authTime) : new Date(session.createdAt);
567
+ const authTime = verificationValue.authTime != null ? normalizeTimestampValue(verificationValue.authTime) : resolveSessionAuthTime(session);
569
568
  return createUserTokens(ctx, opts, client, verificationValue.query.scope?.split(" ") ?? [], user, verificationValue.referenceId, session.id, verificationValue.query?.nonce, void 0, authTime);
570
569
  }
571
570
  /**
@@ -720,10 +719,9 @@ async function handleRefreshTokenGrant(ctx, opts) {
720
719
  error_description: "user not found",
721
720
  error: "invalid_request"
722
721
  });
723
- const authTime = refreshToken.authTime != null ? new Date(refreshToken.authTime) : void 0;
722
+ const authTime = refreshToken.authTime != null ? normalizeTimestampValue(refreshToken.authTime) : void 0;
724
723
  return createUserTokens(ctx, opts, client, requestedScopes ?? scopes, user, refreshToken.referenceId, refreshToken.sessionId, void 0, { refreshToken }, authTime);
725
724
  }
726
-
727
725
  //#endregion
728
726
  //#region src/introspect.ts
729
727
  /**
@@ -984,7 +982,6 @@ async function introspectEndpoint(ctx, opts) {
984
982
  }
985
983
  }
986
984
  }
987
-
988
985
  //#endregion
989
986
  //#region src/logout.ts
990
987
  /**
@@ -1096,7 +1093,6 @@ async function rpInitiatedLogoutEndpoint(ctx, opts) {
1096
1093
  }
1097
1094
  }
1098
1095
  }
1099
-
1100
1096
  //#endregion
1101
1097
  //#region src/middleware/index.ts
1102
1098
  const publicSessionMiddleware = (opts) => createAuthMiddleware(async (ctx) => {
@@ -1104,7 +1100,6 @@ const publicSessionMiddleware = (opts) => createAuthMiddleware(async (ctx) => {
1104
1100
  const query = ctx.body.oauth_query;
1105
1101
  if (!await verifyOAuthQueryParams(query, ctx.context.secret)) throw new APIError("UNAUTHORIZED", { error: "invalid_signature" });
1106
1102
  });
1107
-
1108
1103
  //#endregion
1109
1104
  //#region src/register.ts
1110
1105
  async function registerEndpoint(ctx, opts) {
@@ -1313,7 +1308,6 @@ function schemaToOAuth(input) {
1313
1308
  reference_id: referenceId ?? void 0
1314
1309
  };
1315
1310
  }
1316
-
1317
1311
  //#endregion
1318
1312
  //#region src/types/zod.ts
1319
1313
  const DANGEROUS_SCHEMES = [
@@ -1354,7 +1348,6 @@ const SafeUrlSchema = z.url().superRefine((val, ctx) => {
1354
1348
  });
1355
1349
  }
1356
1350
  });
1357
-
1358
1351
  //#endregion
1359
1352
  //#region src/oauthClient/endpoints.ts
1360
1353
  async function getClientEndpoint(ctx, opts) {
@@ -1584,7 +1577,6 @@ async function rotateClientSecretEndpoint(ctx, opts) {
1584
1577
  clientSecret: (opts.prefix?.clientSecret ?? "") + clientSecret
1585
1578
  });
1586
1579
  }
1587
-
1588
1580
  //#endregion
1589
1581
  //#region src/oauthClient/index.ts
1590
1582
  const adminCreateOAuthClient = (opts) => createAuthEndpoint("/admin/oauth2/create-client", {
@@ -2066,7 +2058,6 @@ const deleteOAuthClient = (opts) => createAuthEndpoint("/oauth2/delete-client",
2066
2058
  }, async (ctx) => {
2067
2059
  return deleteClientEndpoint(ctx, opts);
2068
2060
  });
2069
-
2070
2061
  //#endregion
2071
2062
  //#region src/oauthConsent/endpoints.ts
2072
2063
  async function getConsent(ctx, opts, id) {
@@ -2166,7 +2157,6 @@ async function updateConsentEndpoint(ctx, opts) {
2166
2157
  }
2167
2158
  });
2168
2159
  }
2169
-
2170
2160
  //#endregion
2171
2161
  //#region src/oauthConsent/index.ts
2172
2162
  const getOAuthConsent = (opts) => createAuthEndpoint("/oauth2/get-consent", {
@@ -2203,7 +2193,6 @@ const deleteOAuthConsent = (opts) => createAuthEndpoint("/oauth2/delete-consent"
2203
2193
  }, async (ctx) => {
2204
2194
  return deleteConsentEndpoint(ctx, opts);
2205
2195
  });
2206
-
2207
2196
  //#endregion
2208
2197
  //#region src/revoke.ts
2209
2198
  /**
@@ -2401,7 +2390,6 @@ async function revokeEndpoint(ctx, opts) {
2401
2390
  }
2402
2391
  }
2403
2392
  }
2404
-
2405
2393
  //#endregion
2406
2394
  //#region src/schema.ts
2407
2395
  const schema = {
@@ -2665,7 +2653,6 @@ const schema = {
2665
2653
  }
2666
2654
  }
2667
2655
  };
2668
-
2669
2656
  //#endregion
2670
2657
  //#region src/oauth.ts
2671
2658
  const oAuthState = defineRequestState(() => null);
@@ -2736,12 +2723,21 @@ const oauthProvider = (options) => {
2736
2723
  if (!opts.disableJwtPlugin && (opts.storeClientSecret === "encrypted" || typeof opts.storeClientSecret === "object" && ("encrypt" in opts.storeClientSecret || "decrypt" in opts.storeClientSecret))) throw new BetterAuthError("encryption method not recommended, please use 'hashed' or the 'hash' function");
2737
2724
  return {
2738
2725
  id: "oauth-provider",
2726
+ version: PACKAGE_VERSION,
2739
2727
  options: opts,
2740
2728
  init: (ctx) => {
2741
- if (ctx.options.session && !ctx.options.session.storeSessionInDatabase) throw new BetterAuthError("OAuth Provider requires `session.storeSessionInDatabase: true` when using secondaryStorage");
2729
+ if (ctx.options.secondaryStorage && ctx.options.session?.storeSessionInDatabase !== true) throw new BetterAuthError("OAuth Provider requires `session.storeSessionInDatabase: true` when using secondaryStorage");
2742
2730
  if (!opts.disableJwtPlugin) {
2743
- const issuer = (getJwtPlugin(ctx)?.options)?.jwt?.issuer ?? ctx.baseURL;
2744
- const issuerPath = new URL(issuer).pathname;
2731
+ const jwtPluginOptions = getJwtPlugin(ctx)?.options;
2732
+ const issuer = jwtPluginOptions?.jwt?.issuer ?? ctx.baseURL;
2733
+ const isDynamicBaseURLInit = jwtPluginOptions?.jwt?.issuer == null && typeof ctx.options.baseURL === "object" && ctx.options.baseURL !== null && "allowedHosts" in ctx.options.baseURL;
2734
+ let issuerPath;
2735
+ try {
2736
+ issuerPath = new URL(issuer).pathname;
2737
+ } catch (error) {
2738
+ if (isDynamicBaseURLInit && issuer === "") return;
2739
+ throw error;
2740
+ }
2745
2741
  if (!opts.silenceWarnings?.oauthAuthServerConfig && !(ctx.options.basePath === "/" && issuerPath === "/")) logger.warn(`Please ensure '/.well-known/oauth-authorization-server${issuerPath === "/" ? "" : issuerPath}' exists. Upon completion, clear with silenceWarnings.oauthAuthServerConfig.`);
2746
2742
  if (!opts.silenceWarnings?.openidConfig && ctx.options.basePath !== issuerPath && opts.scopes?.includes("openid")) logger.warn(`Please ensure '${issuerPath}${issuerPath.endsWith("/") ? "" : "/"}.well-known/openid-configuration' exists. Upon completion, clear with silenceWarnings.openidConfig.`);
2747
2743
  }
@@ -2778,6 +2774,9 @@ const oauthProvider = (options) => {
2778
2774
  const session = await ctx.context.internalAdapter.findSession(sessionToken);
2779
2775
  if (!session) return;
2780
2776
  ctx.context.session = session;
2777
+ const secFetchMode = ctx.request?.headers?.get("sec-fetch-mode")?.toLowerCase();
2778
+ const acceptHeader = ctx.request?.headers?.get("accept")?.toLowerCase() ?? "";
2779
+ if (!(secFetchMode === "navigate" || !secFetchMode && (acceptHeader.includes("text/html") || acceptHeader.includes("application/xhtml+xml")))) ctx.headers?.set("accept", "application/json");
2781
2780
  ctx.query = deleteFromPrompt(query, "login");
2782
2781
  return await authorizeEndpoint(ctx, opts);
2783
2782
  })
@@ -3627,7 +3626,6 @@ const oauthProvider = (options) => {
3627
3626
  ]
3628
3627
  };
3629
3628
  };
3630
-
3631
3629
  //#endregion
3632
3630
  //#region src/authorize.ts
3633
3631
  /**
@@ -3702,23 +3700,23 @@ async function authorizeEndpoint(ctx, opts, settings) {
3702
3700
  });
3703
3701
  const query = ctx.query;
3704
3702
  await oAuthState.set({ query: query.toString() });
3705
- if (!query.client_id) throw ctx.redirect(getErrorURL(ctx, "invalid_client", "client_id is required"));
3706
- if (!query.response_type) throw ctx.redirect(getErrorURL(ctx, "invalid_request", "response_type is required"));
3703
+ if (!query.client_id) return handleRedirect(ctx, getErrorURL(ctx, "invalid_client", "client_id is required"));
3704
+ if (!query.response_type) return handleRedirect(ctx, getErrorURL(ctx, "invalid_request", "response_type is required"));
3707
3705
  const promptSet = ctx.query?.prompt ? parsePrompt(ctx.query?.prompt) : void 0;
3708
3706
  const promptNone = promptSet?.has("none") ?? false;
3709
- if (promptSet?.has("select_account") && !opts.selectAccount?.page) throw ctx.redirect(getErrorURL(ctx, `unsupported_prompt_select_account`, "unsupported prompt type"));
3710
- if (!(query.response_type === "code")) throw ctx.redirect(getErrorURL(ctx, "unsupported_response_type", "unsupported response type"));
3707
+ if (promptSet?.has("select_account") && !opts.selectAccount?.page) return handleRedirect(ctx, getErrorURL(ctx, `unsupported_prompt_select_account`, "unsupported prompt type"));
3708
+ if (!(query.response_type === "code")) return handleRedirect(ctx, getErrorURL(ctx, "unsupported_response_type", "unsupported response type"));
3711
3709
  const client = await getClient(ctx, opts, query.client_id);
3712
- if (!client) throw ctx.redirect(getErrorURL(ctx, "invalid_client", "client_id is required"));
3713
- if (client.disabled) throw ctx.redirect(getErrorURL(ctx, "client_disabled", "client is disabled"));
3714
- if (!client.redirectUris?.find((url) => url === query.redirect_uri) || !query.redirect_uri) throw ctx.redirect(getErrorURL(ctx, "invalid_redirect", "invalid redirect uri"));
3710
+ if (!client) return handleRedirect(ctx, getErrorURL(ctx, "invalid_client", "client_id is required"));
3711
+ if (client.disabled) return handleRedirect(ctx, getErrorURL(ctx, "client_disabled", "client is disabled"));
3712
+ if (!client.redirectUris?.find((url) => url === query.redirect_uri) || !query.redirect_uri) return handleRedirect(ctx, getErrorURL(ctx, "invalid_redirect", "invalid redirect uri"));
3715
3713
  let requestedScopes = query.scope?.split(" ").filter((s) => s);
3716
3714
  if (requestedScopes) {
3717
3715
  const validScopes = new Set(client.scopes ?? opts.scopes);
3718
3716
  const invalidScopes = requestedScopes.filter((scope) => {
3719
3717
  return !validScopes?.has(scope);
3720
3718
  });
3721
- if (invalidScopes.length) throw ctx.redirect(formatErrorURL(query.redirect_uri, "invalid_scope", `The following scopes are invalid: ${invalidScopes.join(", ")}`, query.state, getIssuer(ctx, opts)));
3719
+ if (invalidScopes.length) return handleRedirect(ctx, formatErrorURL(query.redirect_uri, "invalid_scope", `The following scopes are invalid: ${invalidScopes.join(", ")}`, query.state, getIssuer(ctx, opts)));
3722
3720
  }
3723
3721
  if (!requestedScopes) {
3724
3722
  requestedScopes = client.scopes ?? opts.scopes ?? [];
@@ -3726,11 +3724,11 @@ async function authorizeEndpoint(ctx, opts, settings) {
3726
3724
  }
3727
3725
  const pkceRequired = isPKCERequired(client, requestedScopes);
3728
3726
  if (pkceRequired) {
3729
- if (!query.code_challenge || !query.code_challenge_method) throw ctx.redirect(formatErrorURL(query.redirect_uri, "invalid_request", pkceRequired.valueOf(), query.state, getIssuer(ctx, opts)));
3727
+ if (!query.code_challenge || !query.code_challenge_method) return handleRedirect(ctx, formatErrorURL(query.redirect_uri, "invalid_request", pkceRequired.valueOf(), query.state, getIssuer(ctx, opts)));
3730
3728
  }
3731
3729
  if (query.code_challenge || query.code_challenge_method) {
3732
- if (!query.code_challenge || !query.code_challenge_method) throw ctx.redirect(formatErrorURL(query.redirect_uri, "invalid_request", "code_challenge and code_challenge_method must both be provided", query.state, getIssuer(ctx, opts)));
3733
- if (!["S256"].includes(query.code_challenge_method)) throw ctx.redirect(formatErrorURL(query.redirect_uri, "invalid_request", "invalid code_challenge method, only S256 is supported", query.state, getIssuer(ctx, opts)));
3730
+ if (!query.code_challenge || !query.code_challenge_method) return handleRedirect(ctx, formatErrorURL(query.redirect_uri, "invalid_request", "code_challenge and code_challenge_method must both be provided", query.state, getIssuer(ctx, opts)));
3731
+ if (!["S256"].includes(query.code_challenge_method)) return handleRedirect(ctx, formatErrorURL(query.redirect_uri, "invalid_request", "invalid code_challenge method, only S256 is supported", query.state, getIssuer(ctx, opts)));
3734
3732
  }
3735
3733
  const session = await getSessionFromCtx(ctx);
3736
3734
  if (!session || promptSet?.has("login") || promptSet?.has("create")) {
@@ -3862,7 +3860,6 @@ async function signParams(ctx, opts) {
3862
3860
  params.append("sig", signature);
3863
3861
  return params.toString();
3864
3862
  }
3865
-
3866
3863
  //#endregion
3867
3864
  //#region src/metadata.ts
3868
3865
  function authServerMetadata(ctx, opts, overrides) {
@@ -3961,7 +3958,5 @@ const oauthProviderOpenIdConfigMetadata = (auth, opts) => {
3961
3958
  });
3962
3959
  };
3963
3960
  };
3964
-
3965
3961
  //#endregion
3966
3962
  export { authServerMetadata, getOAuthProviderState, mcpHandler, oauthProvider, oauthProviderAuthServerMetadata, oauthProviderOpenIdConfigMetadata, oidcServerMetadata };
3967
- //# sourceMappingURL=index.mjs.map
@@ -1602,5 +1602,4 @@ interface ResourceServerMetadata {
1602
1602
  dpop_bound_access_tokens_required?: boolean;
1603
1603
  }
1604
1604
  //#endregion
1605
- export { Awaitable as _, ResourceServerMetadata as a, OAuthConsent as c, OAuthRefreshToken as d, Prompt as f, VerificationValue as g, StoreTokenType as h, OIDCMetadata as i, OAuthOpaqueAccessToken as l, Scope as m, GrantType as n, AuthorizePrompt as o, SchemaClient as p, OAuthClient as r, OAuthAuthorizationQuery as s, AuthServerMetadata as t, OAuthOptions as u };
1606
- //# sourceMappingURL=oauth-4vgZlF-I.d.mts.map
1605
+ export { Awaitable as _, ResourceServerMetadata as a, OAuthConsent as c, OAuthRefreshToken as d, Prompt as f, VerificationValue as g, StoreTokenType as h, OIDCMetadata as i, OAuthOpaqueAccessToken as l, Scope as m, GrantType as n, AuthorizePrompt as o, SchemaClient as p, OAuthClient as r, OAuthAuthorizationQuery as s, AuthServerMetadata as t, OAuthOptions as u };