mirror of
https://github.com/better-auth/better-auth.git
synced 2026-08-01 10:50:40 -05:00
fix(mcp): issue with hardcoded baseURL in withMcpAuth (#2971)
* fix issue with hardcoded baseURL in withMcpAuth * chore: lint --------- Co-authored-by: ping-maxwell <maxwell.multinite@gmail.com>
This commit is contained in:
co-authored by
ping-maxwell
parent
d9a925b315
commit
6119db7a3d
@@ -18,10 +18,13 @@ import { generateRandomString } from "../../crypto";
|
||||
import { createHash } from "@better-auth/utils/hash";
|
||||
import { subtle } from "@better-auth/utils";
|
||||
import { SignJWT } from "jose";
|
||||
import type { GenericEndpointContext } from "../../types";
|
||||
import type { BetterAuthOptions, GenericEndpointContext } from "../../types";
|
||||
import { parseSetCookieHeader } from "../../cookies";
|
||||
import { schema } from "../oidc-provider/schema";
|
||||
import { authorizeMCPOAuth } from "./authorize";
|
||||
import { getBaseURL } from "../../utils/url";
|
||||
import { isProduction } from "../../utils/env";
|
||||
import { logger } from "../../utils";
|
||||
|
||||
interface MCPOptions {
|
||||
loginPage: string;
|
||||
@@ -866,6 +869,7 @@ export const withMcpAuth = <
|
||||
api: {
|
||||
getMcpSession: (...args: any) => Promise<OAuthAccessToken | null>;
|
||||
};
|
||||
options: BetterAuthOptions;
|
||||
},
|
||||
>(
|
||||
auth: Auth,
|
||||
@@ -875,11 +879,14 @@ export const withMcpAuth = <
|
||||
) => Response | Promise<Response>,
|
||||
) => {
|
||||
return async (req: Request) => {
|
||||
const baseURL = getBaseURL(auth.options.baseURL, auth.options.basePath);
|
||||
if (!baseURL && !isProduction) {
|
||||
logger.warn("Unable to get the baseURL, please check your config!");
|
||||
}
|
||||
const session = await auth.api.getMcpSession({
|
||||
headers: req.headers,
|
||||
});
|
||||
const wwwAuthenticateValue =
|
||||
"Bearer resource_metadata=http://localhost:3000/api/auth/.well-known/oauth-authorization-server";
|
||||
const wwwAuthenticateValue = `Bearer resource_metadata=${baseURL}/api/auth/.well-known/oauth-authorization-server`;
|
||||
if (!session) {
|
||||
return Response.json(
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user