From 89e3ad2f08c91956fe6d5cbf820bf485fd0884ca Mon Sep 17 00:00:00 2001 From: talboren Date: Wed, 14 Feb 2024 11:30:58 +0200 Subject: [PATCH] fix(ui): oauth2 datadog from different domains (#830) --- keep-ui/app/providers/provider-form.tsx | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/keep-ui/app/providers/provider-form.tsx b/keep-ui/app/providers/provider-form.tsx index a8f12b9d0..64cc4e36b 100644 --- a/keep-ui/app/providers/provider-form.tsx +++ b/keep-ui/app/providers/provider-form.tsx @@ -34,6 +34,7 @@ import { ProviderSemiAutomated } from "./provider-semi-automated"; import ProviderFormScopes from "./provider-form-scopes"; import Link from "next/link"; import cookieCutter from "@boiseitguru/cookie-cutter"; +import { useSearchParams } from "next/navigation"; type ProviderFormProps = { provider: Provider; @@ -92,6 +93,7 @@ const ProviderForm = ({ isLocalhost, }: ProviderFormProps) => { console.log("Loading the ProviderForm component"); + const searchParams = useSearchParams(); const initialData = { provider_id: provider.id, // Include the provider ID in formValues ...formData, @@ -106,7 +108,6 @@ const ProviderForm = ({ const [inputErrors, setInputErrors] = useState<{ [key: string]: boolean }>( {} ); - const [isModalOpen, setIsModalOpen] = useState(false); // Related to scopes const [providerValidatedScopes, setProviderValidatedScopes] = useState<{ [key: string]: boolean | string; @@ -132,8 +133,18 @@ const ProviderForm = ({ const verifier = generateRandomString(); cookieCutter.set("verifier", verifier); const verifierChallenge = base64urlencode(await sha256(verifier)); + + let oauth2Url = provider.oauth2_url; + if (searchParams?.get("domain")) { + // TODO: this is a hack for Datadog OAuth2 since it can be initated from different domains + oauth2Url = oauth2Url?.replace( + "datadoghq.com", + searchParams.get("domain") + ); + } + window.location.assign( - `${provider.oauth2_url}&redirect_uri=${window.location.origin}/providers/oauth2/${provider.type}&code_challenge=${verifierChallenge}&code_challenge_method=S256` + `${oauth2Url}&redirect_uri=${window.location.origin}/providers/oauth2/${provider.type}&code_challenge=${verifierChallenge}&code_challenge_method=S256` ); }