mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-06 22:27:22 +00:00
Continue progress on self-hosted gitlab integration
This commit is contained in:
@@ -0,0 +1,53 @@
|
|||||||
|
import crypto from "crypto";
|
||||||
|
|
||||||
|
import { useState } from "react";
|
||||||
|
import { faGoogle } from "@fortawesome/free-brands-svg-icons";
|
||||||
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
|
|
||||||
|
import { useGetCloudIntegrations } from "@app/hooks/api";
|
||||||
|
|
||||||
|
import { Button, Card, CardTitle, FormControl, Input } from "../../../components/v2";
|
||||||
|
|
||||||
|
export default function GitLabAuthorizeIntegrationPage() {
|
||||||
|
const { data: cloudIntegrations } = useGetCloudIntegrations();
|
||||||
|
|
||||||
|
const [gitLabURL, setGitLabURL] = useState("");
|
||||||
|
|
||||||
|
const handleIntegrateWithOAuth = () => {
|
||||||
|
if (!cloudIntegrations) return;
|
||||||
|
const integrationOption = cloudIntegrations.find((integration) => integration.slug === "gitlab");
|
||||||
|
|
||||||
|
if (!integrationOption) return;
|
||||||
|
|
||||||
|
const baseURL = gitLabURL.trim() === "" ? "https://gitlab.com" : gitLabURL.trim();
|
||||||
|
|
||||||
|
const csrfToken = crypto.randomBytes(16).toString("hex");
|
||||||
|
localStorage.setItem("latestCSRFToken", csrfToken);
|
||||||
|
|
||||||
|
const link = `${baseURL}/oauth/authorize?client_id=${integrationOption.clientId}&redirect_uri=${window.location.origin}/integrations/gitlab/oauth2/callback&response_type=code&state=${state}`;
|
||||||
|
window.location.assign(link);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex h-full w-full items-center justify-center">
|
||||||
|
<Card className="max-w-md rounded-md p-8">
|
||||||
|
<CardTitle className="text-center">GitLab Integration</CardTitle>
|
||||||
|
<FormControl label="Self-hosted URL (optional)">
|
||||||
|
<Input
|
||||||
|
placeholder="https://self-hosted-gitlab.com"
|
||||||
|
value={gitLabURL} onChange={(e) => setGitLabURL(e.target.value)}
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
<Button
|
||||||
|
onClick={handleIntegrateWithOAuth}
|
||||||
|
leftIcon={<FontAwesomeIcon icon={faGoogle} className="mr-2" />}
|
||||||
|
className="h-11 w-full mx-0 mt-4"
|
||||||
|
>
|
||||||
|
Continue with OAuth
|
||||||
|
</Button>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
GitLabAuthorizeIntegrationPage.requireAuth = true;
|
||||||
@@ -18,6 +18,7 @@ export default function GitLabOAuth2CallbackPage() {
|
|||||||
if (state !== localStorage.getItem("latestCSRFToken")) return;
|
if (state !== localStorage.getItem("latestCSRFToken")) return;
|
||||||
localStorage.removeItem("latestCSRFToken");
|
localStorage.removeItem("latestCSRFToken");
|
||||||
|
|
||||||
|
// TODO: self-hosted url somewhere here?
|
||||||
const integrationAuth = await mutateAsync({
|
const integrationAuth = await mutateAsync({
|
||||||
workspaceId: localStorage.getItem("projectData.id") as string,
|
workspaceId: localStorage.getItem("projectData.id") as string,
|
||||||
code: code as string,
|
code: code as string,
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ export const redirectForProviderAuth = (integrationOption: TCloudIntegration) =>
|
|||||||
link = `https://github.com/login/oauth/authorize?client_id=${integrationOption.clientId}&response_type=code&scope=repo&redirect_uri=${window.location.origin}/integrations/github/oauth2/callback&state=${state}`;
|
link = `https://github.com/login/oauth/authorize?client_id=${integrationOption.clientId}&response_type=code&scope=repo&redirect_uri=${window.location.origin}/integrations/github/oauth2/callback&state=${state}`;
|
||||||
break;
|
break;
|
||||||
case "gitlab":
|
case "gitlab":
|
||||||
link = `https://gitlab.com/oauth/authorize?client_id=${integrationOption.clientId}&redirect_uri=${window.location.origin}/integrations/gitlab/oauth2/callback&response_type=code&state=${state}`;
|
link = `${window.location.origin}/integrations/gitlab/authorize`;
|
||||||
break;
|
break;
|
||||||
case "render":
|
case "render":
|
||||||
link = `${window.location.origin}/integrations/render/authorize`;
|
link = `${window.location.origin}/integrations/render/authorize`;
|
||||||
|
|||||||
Reference in New Issue
Block a user