Fixed the OAuth2 callback urls by constructing URL using x-forwarded-proto header
This commit is contained in:
@@ -1,17 +1,16 @@
|
||||
import * as Worker from "~/services/worker.server";
|
||||
import { PassThrough } from "stream";
|
||||
import { renderToPipeableStream } from "react-dom/server";
|
||||
import { RemixServer } from "@remix-run/react";
|
||||
import { Response } from "@remix-run/node"; // or cloudflare/deno
|
||||
import type { EntryContext, Headers } from "@remix-run/node"; // or cloudflare/deno
|
||||
import { Response } from "@remix-run/node"; // or cloudflare/deno
|
||||
import { RemixServer } from "@remix-run/react";
|
||||
import { parseAcceptLanguage } from "intl-parse-accept-language";
|
||||
import isbot from "isbot";
|
||||
import { renderToPipeableStream } from "react-dom/server";
|
||||
import { PassThrough } from "stream";
|
||||
import * as Worker from "~/services/worker.server";
|
||||
import { LocaleContextProvider } from "./components/primitives/LocaleProvider";
|
||||
import {
|
||||
OperatingSystemContextProvider,
|
||||
OperatingSystemPlatform,
|
||||
} from "./components/primitives/OperatingSystemProvider";
|
||||
import { logger } from "./services/logger.server";
|
||||
|
||||
const ABORT_DELAY = 30000;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { requestUrl } from "./utils";
|
||||
import { requestUrl } from "./utils/requestUrl.server";
|
||||
|
||||
export type TriggerFeatures = {
|
||||
isManagedCloud: boolean;
|
||||
|
||||
+2
-1
@@ -30,11 +30,12 @@ import {
|
||||
EnvironmentsPresenter,
|
||||
} from "~/presenters/EnvironmentsPresenter.server";
|
||||
import { requireUserId } from "~/services/session.server";
|
||||
import { formatDateTime, requestUrl } from "~/utils";
|
||||
import { formatDateTime } from "~/utils";
|
||||
import { Handle } from "~/utils/handle";
|
||||
import { ProjectParamSchema } from "~/utils/pathBuilder";
|
||||
import { RuntimeEnvironmentType } from "../../../../../packages/database/src";
|
||||
import { ConfigureEndpointSheet } from "./ConfigureEndpointSheet";
|
||||
import { requestUrl } from "~/utils/requestUrl.server";
|
||||
|
||||
export const loader = async ({ request, params }: LoaderArgs) => {
|
||||
const userId = await requireUserId(request);
|
||||
|
||||
@@ -20,7 +20,8 @@ import type { LoaderType as RootLoader } from "~/root";
|
||||
import { isGithubAuthSupported } from "~/services/auth.server";
|
||||
import { commitSession, setRedirectTo } from "~/services/redirectTo.server";
|
||||
import { getUserId } from "~/services/session.server";
|
||||
import { appEnvTitleTag, requestUrl } from "~/utils";
|
||||
import { appEnvTitleTag } from "~/utils";
|
||||
import { requestUrl } from "~/utils/requestUrl.server";
|
||||
|
||||
export const meta: TypedMetaFunction<typeof loader, { root: RootLoader }> = ({
|
||||
parentsData,
|
||||
|
||||
@@ -6,7 +6,7 @@ import { env } from "~/env.server";
|
||||
import { integrationAuthRepository } from "~/services/externalApis/integrationAuthRepository.server";
|
||||
import { OAuthClient, OAuthClientSchema } from "~/services/externalApis/types";
|
||||
import { getSecretStore } from "~/services/secrets/secretStore.server";
|
||||
import { requestUrl } from "~/utils";
|
||||
import { requestUrl } from "~/utils/requestUrl.server";
|
||||
|
||||
const ParamsSchema = z
|
||||
.object({
|
||||
|
||||
+3
-1
@@ -6,6 +6,7 @@ import z from "zod";
|
||||
import { prisma } from "~/db.server";
|
||||
import { integrationAuthRepository } from "~/services/externalApis/integrationAuthRepository.server";
|
||||
import { requireUserId } from "~/services/session.server";
|
||||
import { requestUrl } from "~/utils/requestUrl.server";
|
||||
|
||||
export const schema = z
|
||||
.object({
|
||||
@@ -98,7 +99,8 @@ export async function action({ request, params }: ActionArgs) {
|
||||
},
|
||||
});
|
||||
|
||||
const url = new URL(request.url);
|
||||
const url = requestUrl(request);
|
||||
|
||||
const redirectUrl =
|
||||
await integrationAuthRepository.populateMissingConnectionClientFields({
|
||||
id: integrationId,
|
||||
|
||||
@@ -6,6 +6,7 @@ import z from "zod";
|
||||
import { prisma } from "~/db.server";
|
||||
import { integrationAuthRepository } from "~/services/externalApis/integrationAuthRepository.server";
|
||||
import { requireUserId } from "~/services/session.server";
|
||||
import { requestUrl } from "~/utils/requestUrl.server";
|
||||
|
||||
export function createSchema(
|
||||
constraints: {
|
||||
@@ -176,7 +177,8 @@ export async function action({ request, params }: ActionArgs) {
|
||||
},
|
||||
});
|
||||
|
||||
const url = new URL(request.url);
|
||||
const url = requestUrl(request);
|
||||
|
||||
const redirectUrl = await integrationAuthRepository.createConnectionClient({
|
||||
id,
|
||||
slug,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { PrismaClient } from "~/db.server";
|
||||
import { prisma } from "~/db.server";
|
||||
import { workerQueue } from "../worker.server";
|
||||
import { requestUrl } from "~/utils";
|
||||
import { requestUrl } from "~/utils/requestUrl.server";
|
||||
|
||||
export class HandleHttpSourceService {
|
||||
#prismaClient: PrismaClient;
|
||||
|
||||
@@ -187,19 +187,6 @@ export const obfuscateApiKey = (apiKey: string) => {
|
||||
return `${prefix}_${slug}_${"*".repeat(secretPart.length)}`;
|
||||
};
|
||||
|
||||
// This will read the X-Forwarded-Proto header from the request, and make sure the
|
||||
// returned url has the matching proto if the request.url does not
|
||||
export function requestUrl(request: Request): URL {
|
||||
const url = new URL(request.url);
|
||||
const proto = request.headers.get("X-Forwarded-Proto");
|
||||
|
||||
if (proto && url.protocol !== proto) {
|
||||
url.protocol = proto;
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
export function appEnvTitleTag(
|
||||
appEnv: "test" | "production" | "development" | "staging"
|
||||
): string {
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
// Updates the protocol of the request url to match the request.headers x-forwarded-proto
|
||||
export function requestUrl(request: Request): URL {
|
||||
const url = new URL(request.url);
|
||||
|
||||
if (request.headers.get("x-forwarded-proto") === "https") {
|
||||
url.protocol = "https:";
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
Reference in New Issue
Block a user