mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-11 18:29:06 +00:00
Begin Netlify integration
This commit is contained in:
@@ -21,6 +21,8 @@ const {
|
||||
} = require('../../components/utilities/cryptography/crypto');
|
||||
const crypto = require("crypto");
|
||||
|
||||
import axios from "axios";
|
||||
|
||||
export default function Integrations() {
|
||||
const [integrationAuths, setIntegrationAuths] = useState([]);
|
||||
const [integrations, setIntegrations] = useState([]);
|
||||
@@ -115,20 +117,41 @@ export default function Integrations() {
|
||||
const handleIntegrationOption = async ({ integrationOption }) => {
|
||||
// TODO: modularize and handle switch by slug
|
||||
|
||||
console.log('handle', integrationOption);
|
||||
|
||||
// generate CSRF token for OAuth2 code-token exchange integrations
|
||||
const csrfToken = crypto.randomBytes(16).toString("hex");
|
||||
localStorage.setItem('latestCSRFToken', csrfToken);
|
||||
const state = crypto.randomBytes(16).toString("hex");
|
||||
localStorage.setItem('latestCSRFToken', state);
|
||||
|
||||
switch (integrationOption.name) {
|
||||
case 'Heroku':
|
||||
// console.log('Heroku integration ', integrationOption);
|
||||
window.location = `https://id.heroku.com/oauth/authorize?client_id=${integrationOption.clientId}&response_type=code&scope=write-protected&state=${csrfToken}`;
|
||||
window.location = `https://id.heroku.com/oauth/authorize?client_id=${integrationOption.clientId}&response_type=code&scope=write-protected&state=${state}`;
|
||||
break;
|
||||
case 'Vercel':
|
||||
window.location = `https://vercel.com/integrations/infisical/new?state=${csrfToken}`;
|
||||
window.location = `https://vercel.com/integrations/infisical/new?state=${state}`;
|
||||
break;
|
||||
case 'Netlify':
|
||||
console.log('netlifyyy');
|
||||
// window.location = `https://app.netlify.com/authorize?client_id=${integrationOption.clientId}&response_type=token&redirect_uri=${integrationOption.redirectURL}&state=${state}`;
|
||||
window.location = `https://app.netlify.com/authorize?client_id=${integrationOption.clientId}&response_type=code&redirect_uri=${integrationOption.redirectURL}&state=${state}`;
|
||||
// const res = await axios.post('https://api.netlify.com/api/v1/oauth/tickets' + '?client_id=' + integrationOption.clientId);
|
||||
|
||||
// window.location = `https://app.netlify.com/authorize?client_id=${integrationOption.clientId}&response_type=ticket&redirect_uri=${integrationOption.redirectURL}&state=${state}&ticket=${res.data.id}`;
|
||||
// `https://app.netlify.com/authorize?response_type=ticket&ticket=${ticket.id}`
|
||||
try {
|
||||
// const res = await axios.post('https://api.netlify.com/api/v1/oauth/tickets' + '?client_id=' + integrationOption.clientId);
|
||||
// console.log('res response', res);
|
||||
// const res2 = await axios.get('https://api.netlify.com/api/v1/oauth/tickets/' + res.data.id);
|
||||
// console.log('res2 response', res2);
|
||||
// console.log('ticket_id', res.data.id);
|
||||
// // exchange ticket:
|
||||
// const res3 = await axios.get(`https://api.netlify.com/api/v1/oauth/tickets/${res.data.id}/exchange`);
|
||||
// console.log('res3 response', res3);
|
||||
|
||||
} catch (err) {
|
||||
console.error('Netlify ', err);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ import AuthorizeIntegration from "./api/integrations/authorizeIntegration";
|
||||
export default function Netlify() {
|
||||
const router = useRouter();
|
||||
const parsedUrl = queryString.parse(router.asPath.split("?")[1]);
|
||||
const code = parsedUrl.code;
|
||||
const state = parsedUrl.state;
|
||||
// modify comment here
|
||||
|
||||
/**
|
||||
@@ -14,16 +16,19 @@ export default function Netlify() {
|
||||
*/
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
useEffect(async () => {
|
||||
console.log('AA');
|
||||
if (state === localStorage.getItem('latestCSRFToken')) {
|
||||
localStorage.removeItem('latestCSRFToken');
|
||||
|
||||
console.log('Netlify', parsedUrl);
|
||||
// http://localhost:8080/netlify?code=qnG0g_krhklWDpdUqfhU-t1sLeZzYI3gF2d6QVnL-Gc&state=3a78cd3154a9a99ddd4eb5d99dbb3289
|
||||
// http://localhost:8080/netlify#access_token=d-78qUAnnSzvlgfG9Y_oUV6_4TQBxLbofImiBbKAjzE&token_type=Bearer&state=5da34fa49e301e9fa1a6e40925694b77
|
||||
|
||||
// await AuthorizeIntegration({
|
||||
// workspaceId: localStorage.getItem('projectData.id'),
|
||||
// code,
|
||||
// integration: "vercel"
|
||||
// });
|
||||
await AuthorizeIntegration({
|
||||
workspaceId: localStorage.getItem('projectData.id'),
|
||||
code,
|
||||
integration: "netlify"
|
||||
});
|
||||
|
||||
// router.push("/integrations/" + localStorage.getItem("projectData.id"));
|
||||
}
|
||||
|
||||
@@ -21,7 +21,8 @@
|
||||
"image": "Netlify",
|
||||
"isAvailable": true,
|
||||
"type": "oauth2",
|
||||
"clientId": ""
|
||||
"clientId": "frGheMeEzVEUgM5yHLcPeTj9kYJhYvqkR5IkSexOS50",
|
||||
"redirectURL": "http://localhost:8080/netlify"
|
||||
},
|
||||
{
|
||||
"name": "Google Cloud Platform",
|
||||
|
||||
Reference in New Issue
Block a user