From 8184c21a803ac364ca50566d6cc2fb3765cb5e70 Mon Sep 17 00:00:00 2001 From: Eric Allam Date: Thu, 22 Jun 2023 21:54:01 +0100 Subject: [PATCH] Build the oauth2 callback url from the server (and use env.APP_ORIGIN) --- .../components/integrations/ConnectToIntegrationSheet.tsx | 6 ++++++ .../app/components/integrations/ConnectToOAuthForm.tsx | 7 +++---- .../app/components/integrations/SelectOAuthMethod.tsx | 3 +++ .../webapp/app/presenters/IntegrationsPresenter.server.ts | 1 + .../route.tsx | 8 ++++++-- 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/apps/webapp/app/components/integrations/ConnectToIntegrationSheet.tsx b/apps/webapp/app/components/integrations/ConnectToIntegrationSheet.tsx index 6d4e85cf7..a0d9104ac 100644 --- a/apps/webapp/app/components/integrations/ConnectToIntegrationSheet.tsx +++ b/apps/webapp/app/components/integrations/ConnectToIntegrationSheet.tsx @@ -26,10 +26,12 @@ export function ConnectToIntegrationSheet({ organizationId, button, className, + callbackUrl }: { integration: Integration; organizationId: string; button: React.ReactNode; + callbackUrl: string; className?: string; }) { const [integrationMethod, setIntegrationMethod] = useState< @@ -100,6 +102,7 @@ export function ConnectToIntegrationSheet({ integration={integration} organizationId={organizationId} method={integrationMethod} + callbackUrl={callbackUrl} /> )} @@ -112,10 +115,12 @@ function SelectedIntegrationMethod({ integration, organizationId, method, + callbackUrl }: { integration: Integration; organizationId: string; method: IntegrationMethod; + callbackUrl: string; }) { const authMethods = Object.values(integration.authenticationMethods); @@ -134,6 +139,7 @@ function SelectedIntegrationMethod({ ); case "custom": diff --git a/apps/webapp/app/components/integrations/ConnectToOAuthForm.tsx b/apps/webapp/app/components/integrations/ConnectToOAuthForm.tsx index 525122682..d6b2ad9bd 100644 --- a/apps/webapp/app/components/integrations/ConnectToOAuthForm.tsx +++ b/apps/webapp/app/components/integrations/ConnectToOAuthForm.tsx @@ -33,12 +33,14 @@ export function ConnectToOAuthForm({ authMethodKey, organizationId, clientType, + callbackUrl, }: { integration: Integration; authMethod: ApiAuthenticationMethodOAuth2; authMethodKey: string; organizationId: string; clientType: ConnectionType; + callbackUrl: string; }) { const [id] = useState(cuid()); const transition = useNavigation(); @@ -133,10 +135,7 @@ export function ConnectToOAuthForm({
Set the callback url to{" "} - +
diff --git a/apps/webapp/app/components/integrations/SelectOAuthMethod.tsx b/apps/webapp/app/components/integrations/SelectOAuthMethod.tsx index 737ee8acc..389d70012 100644 --- a/apps/webapp/app/components/integrations/SelectOAuthMethod.tsx +++ b/apps/webapp/app/components/integrations/SelectOAuthMethod.tsx @@ -12,9 +12,11 @@ import { Paragraph } from "../primitives/Paragraph"; export function SelectOAuthMethod({ integration, organizationId, + callbackUrl }: { integration: Integration; organizationId: string; + callbackUrl: string; }) { const oAuthMethods = Object.entries(integration.authenticationMethods).filter( (a): a is [string, ApiAuthenticationMethodOAuth2] => a[1].type === "oauth2" @@ -95,6 +97,7 @@ export function SelectOAuthMethod({ authMethodKey={oAuthKey} organizationId={organizationId} clientType={connectionType} + callbackUrl={callbackUrl} /> ) : ( <> diff --git a/apps/webapp/app/presenters/IntegrationsPresenter.server.ts b/apps/webapp/app/presenters/IntegrationsPresenter.server.ts index e01e6998d..7d1e3410d 100644 --- a/apps/webapp/app/presenters/IntegrationsPresenter.server.ts +++ b/apps/webapp/app/presenters/IntegrationsPresenter.server.ts @@ -162,6 +162,7 @@ export class IntegrationsPresenter { return { clients: clientsWithConnections, options, + callbackUrl: `${env.APP_ORIGIN}/oauth2/callback` }; } } diff --git a/apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.integrations/route.tsx b/apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.integrations/route.tsx index 7b9a39c27..e3f57cfcf 100644 --- a/apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.integrations/route.tsx +++ b/apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.integrations/route.tsx @@ -74,7 +74,7 @@ export const handle: Handle = { }; export default function Integrations() { - const { clients, options } = useTypedLoaderData(); + const { clients, options, callbackUrl } = useTypedLoaderData(); const organization = useOrganization(); const project = useProject(); @@ -104,6 +104,7 @@ export default function Integrations() { ; + return ; }