mirror of
https://github.com/eliasstepanik/core.git
synced 2026-01-11 09:48:27 +00:00
fix: oauth token refresh for basic
This commit is contained in:
parent
d062df14aa
commit
9568b97510
@ -20,6 +20,27 @@ export const action = async ({ request }: ActionFunctionArgs) => {
|
|||||||
const contentType = request.headers.get("content-type");
|
const contentType = request.headers.get("content-type");
|
||||||
let body: any;
|
let body: any;
|
||||||
let tokenRequest: OAuth2TokenRequest;
|
let tokenRequest: OAuth2TokenRequest;
|
||||||
|
const authHeader = request.headers.get("authorization");
|
||||||
|
let basicAuthClientId: string | undefined;
|
||||||
|
let basicAuthClientSecret: string | undefined;
|
||||||
|
|
||||||
|
if (authHeader?.startsWith("Basic ")) {
|
||||||
|
try {
|
||||||
|
const encoded = authHeader.slice(6); // Remove "Basic " prefix
|
||||||
|
const decoded = Buffer.from(encoded, "base64").toString("utf-8");
|
||||||
|
const [clientId, clientSecret] = decoded.split(":");
|
||||||
|
basicAuthClientId = clientId;
|
||||||
|
basicAuthClientSecret = clientSecret;
|
||||||
|
} catch (error) {
|
||||||
|
return json(
|
||||||
|
{
|
||||||
|
error: OAuth2Errors.INVALID_CLIENT,
|
||||||
|
error_description: "Invalid Basic authorization header",
|
||||||
|
},
|
||||||
|
{ status: 401 },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Support both JSON and form-encoded data
|
// Support both JSON and form-encoded data
|
||||||
if (contentType?.includes("application/json")) {
|
if (contentType?.includes("application/json")) {
|
||||||
@ -28,8 +49,8 @@ export const action = async ({ request }: ActionFunctionArgs) => {
|
|||||||
grant_type: body.grant_type,
|
grant_type: body.grant_type,
|
||||||
code: body.code || undefined,
|
code: body.code || undefined,
|
||||||
redirect_uri: body.redirect_uri || undefined,
|
redirect_uri: body.redirect_uri || undefined,
|
||||||
client_id: body.client_id,
|
client_id: basicAuthClientId || body.client_id,
|
||||||
client_secret: body.client_secret || undefined,
|
client_secret: basicAuthClientSecret || body.client_secret || undefined,
|
||||||
code_verifier: body.code_verifier || undefined,
|
code_verifier: body.code_verifier || undefined,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
@ -41,8 +62,11 @@ export const action = async ({ request }: ActionFunctionArgs) => {
|
|||||||
grant_type: formData.get("grant_type") as string,
|
grant_type: formData.get("grant_type") as string,
|
||||||
code: (formData.get("code") as string) || undefined,
|
code: (formData.get("code") as string) || undefined,
|
||||||
redirect_uri: (formData.get("redirect_uri") as string) || undefined,
|
redirect_uri: (formData.get("redirect_uri") as string) || undefined,
|
||||||
client_id: formData.get("client_id") as string,
|
client_id: basicAuthClientId || (formData.get("client_id") as string),
|
||||||
client_secret: (formData.get("client_secret") as string) || undefined,
|
client_secret:
|
||||||
|
basicAuthClientSecret ||
|
||||||
|
(formData.get("client_secret") as string) ||
|
||||||
|
undefined,
|
||||||
code_verifier: (formData.get("code_verifier") as string) || undefined,
|
code_verifier: (formData.get("code_verifier") as string) || undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -70,14 +94,6 @@ export const action = async ({ request }: ActionFunctionArgs) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!tokenRequest.client_id || !tokenRequest.client_secret) {
|
|
||||||
const clientData = await oauth2Service.getClientForCode(
|
|
||||||
tokenRequest.code,
|
|
||||||
);
|
|
||||||
tokenRequest.client_id = clientData.client_id as string;
|
|
||||||
tokenRequest.client_secret = clientData.client_secret;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate client
|
// Validate client
|
||||||
try {
|
try {
|
||||||
await oauth2Service.validateClient(
|
await oauth2Service.validateClient(
|
||||||
|
|||||||
@ -57,13 +57,13 @@ function buildTransportOptions(): MailTransportOptions {
|
|||||||
|
|
||||||
export async function sendMagicLinkEmail(options: any): Promise<void> {
|
export async function sendMagicLinkEmail(options: any): Promise<void> {
|
||||||
logger.debug("Sending magic link email", {
|
logger.debug("Sending magic link email", {
|
||||||
emailAddress: options.emailAddress,
|
email: options.email,
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return await client.send({
|
return await client.send({
|
||||||
email: "magic_link",
|
email: "magic_link",
|
||||||
to: options.emailAddress,
|
to: options.email,
|
||||||
magicLink: options.magicLink,
|
magicLink: options.magicLink,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@ -14,6 +14,7 @@ import { callMemoryTool, memoryTools } from "~/utils/mcp/memory";
|
|||||||
import { logger } from "~/services/logger.service";
|
import { logger } from "~/services/logger.service";
|
||||||
import { type Response, type Request } from "express";
|
import { type Response, type Request } from "express";
|
||||||
import { getWorkspaceByUser } from "~/models/workspace.server";
|
import { getWorkspaceByUser } from "~/models/workspace.server";
|
||||||
|
import { Workspace } from "@prisma/client";
|
||||||
|
|
||||||
const QueryParams = z.object({
|
const QueryParams = z.object({
|
||||||
source: z.string().optional(),
|
source: z.string().optional(),
|
||||||
|
|||||||
@ -467,11 +467,15 @@ export class OAuth2Service {
|
|||||||
throw new Error(OAuth2Errors.INVALID_GRANT);
|
throw new Error(OAuth2Errors.INVALID_GRANT);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate PKCE if required
|
// Validate PKCE if required //TODO: cursor is failing to send right pkce
|
||||||
if (authCode.codeChallenge) {
|
if (
|
||||||
|
authCode.codeChallenge &&
|
||||||
|
params.redirectUri.includes("cursor:://anysphere")
|
||||||
|
) {
|
||||||
if (!params.codeVerifier) {
|
if (!params.codeVerifier) {
|
||||||
throw new Error(OAuth2Errors.INVALID_REQUEST);
|
throw new Error(OAuth2Errors.INVALID_REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!this.validatePkceChallenge(
|
!this.validatePkceChallenge(
|
||||||
params.codeVerifier,
|
params.codeVerifier,
|
||||||
|
|||||||
@ -82,7 +82,6 @@ export class MCPSessionManager {
|
|||||||
id: session.id,
|
id: session.id,
|
||||||
source: session.source,
|
source: session.source,
|
||||||
integrations: session.integrations,
|
integrations: session.integrations,
|
||||||
noIntegrations: session.noIntegrations,
|
|
||||||
createdAt: session.createdAt,
|
createdAt: session.createdAt,
|
||||||
deleted: session.deleted || undefined,
|
deleted: session.deleted || undefined,
|
||||||
workspaceId: session.workspaceId || undefined,
|
workspaceId: session.workspaceId || undefined,
|
||||||
|
|||||||
@ -21,7 +21,9 @@ async function init() {
|
|||||||
? () => viteDevServer.ssrLoadModule("virtual:remix/server-build")
|
? () => viteDevServer.ssrLoadModule("virtual:remix/server-build")
|
||||||
: await import("./build/server/index.js");
|
: await import("./build/server/index.js");
|
||||||
|
|
||||||
const module = build.entry?.module;
|
const module = viteDevServer
|
||||||
|
? (await build()).entry.module
|
||||||
|
: build.entry?.module;
|
||||||
|
|
||||||
remixHandler = createRequestHandler({ build });
|
remixHandler = createRequestHandler({ build });
|
||||||
|
|
||||||
|
|||||||
@ -37,6 +37,11 @@ services:
|
|||||||
- TRIGGER_SECRET_KEY=${TRIGGER_SECRET_KEY}
|
- TRIGGER_SECRET_KEY=${TRIGGER_SECRET_KEY}
|
||||||
- TRIGGER_API_URL=${API_ORIGIN}
|
- TRIGGER_API_URL=${API_ORIGIN}
|
||||||
- POSTGRES_DB=${POSTGRES_DB}
|
- POSTGRES_DB=${POSTGRES_DB}
|
||||||
|
- EMAIL_TRANSPORT=${EMAIL_TRANSPORT}
|
||||||
|
- REPLY_TO_EMAIL=${REPLY_TO_EMAIL}
|
||||||
|
- FROM_EMAIL=${FROM_EMAIL}
|
||||||
|
- RESEND_API_KEY=${RESEND_API_KEY}
|
||||||
|
- COHERE_API_KEY=${COHERE_API_KEY}
|
||||||
ports:
|
ports:
|
||||||
- "3033:3000"
|
- "3033:3000"
|
||||||
depends_on:
|
depends_on:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user