fix: Always use IP address for webhooks

This commit is contained in:
Andras Bacsai
2022-04-29 23:02:58 +02:00
parent 8e42203b89
commit 880865f1f2
6 changed files with 39 additions and 16 deletions

View File

@@ -8,6 +8,7 @@
import { onMount } from 'svelte';
import { gitTokens } from '$lib/store';
import { t } from '$lib/translations';
import { getIP } from '$lib/components/common';
const { id } = $page.params;
const from = $page.url.searchParams.get('from');
@@ -113,6 +114,7 @@
}
onMount(async () => {
const ip = await getIP();
try {
if (!$gitTokens.githubToken) {
const { token } = await get(`/applications/${id}/configuration/githubToken.json`);
@@ -131,7 +133,7 @@
const left = screen.width / 2 - 1020 / 2;
const top = screen.height / 2 - 618 / 2;
const newWindow = open(
`${htmlUrl}/oauth/authorize?client_id=${application.gitSource.gitlabApp.appId}&redirect_uri=${window.location.origin}/webhooks/gitlab&response_type=code&scope=api+email+read_repository&state=${$page.params.id}`,
`${htmlUrl}/oauth/authorize?client_id=${application.gitSource.gitlabApp.appId}&redirect_uri=${ip}/webhooks/gitlab&response_type=code&scope=api+email+read_repository&state=${$page.params.id}`,
'GitLab',
'resizable=1, scrollbars=1, fullscreen=0, height=618, width=1020,top=' +
top +

View File

@@ -10,6 +10,7 @@
import { del, get, post, put } from '$lib/api';
import { gitTokens } from '$lib/store';
import { t } from '$lib/translations';
import { getIP } from '$lib/components/common';
const { id } = $page.params;
const from = $page.url.searchParams.get('from');
@@ -40,7 +41,7 @@
};
onMount(async () => {
if (!$gitTokens.gitlabToken) {
getGitlabToken();
await getGitlabToken();
} else {
loading.base = true;
try {
@@ -49,7 +50,7 @@
});
username = user.username;
} catch (error) {
return getGitlabToken();
return await getGitlabToken();
}
try {
groups = await get(`${apiUrl}/v4/groups?per_page=5000`, {
@@ -64,11 +65,12 @@
}
});
function getGitlabToken() {
async function getGitlabToken() {
const ip = await getIP();
const left = screen.width / 2 - 1020 / 2;
const top = screen.height / 2 - 618 / 2;
const newWindow = open(
`${htmlUrl}/oauth/authorize?client_id=${application.gitSource.gitlabApp.appId}&redirect_uri=${window.location.origin}/webhooks/gitlab&response_type=code&scope=api+email+read_repository&state=${$page.params.id}`,
`${htmlUrl}/oauth/authorize?client_id=${application.gitSource.gitlabApp.appId}&redirect_uri=${ip}/webhooks/gitlab&response_type=code&scope=api+email+read_repository&state=${$page.params.id}`,
'GitLab',
'resizable=1, scrollbars=1, fullscreen=0, height=618, width=1020,top=' +
top +
@@ -163,9 +165,10 @@
}
}
async function setWebhook(url, webhookToken) {
const ip = await getIP();
const host = dev
? 'https://webhook.site/0e5beb2c-4e9b-40e2-a89e-32295e570c21'
: `${window.location.origin}/webhooks/gitlab/events`;
: `${ip}/webhooks/gitlab/events`;
try {
await post(
url,

View File

@@ -37,6 +37,7 @@
import { gitTokens } from '$lib/store';
import { browser } from '$app/env';
import { t } from '$lib/translations';
import { getIP } from '$lib/components/common';
const { id } = $page.params;
@@ -174,11 +175,12 @@
error.message === '401 Unauthorized'
) {
if (application.gitSource.gitlabAppId) {
const ip = await getIP();
let htmlUrl = application.gitSource.htmlUrl;
const left = screen.width / 2 - 1020 / 2;
const top = screen.height / 2 - 618 / 2;
const newWindow = open(
`${htmlUrl}/oauth/authorize?client_id=${application.gitSource.gitlabApp.appId}&redirect_uri=${window.location.origin}/webhooks/gitlab&response_type=code&scope=api+email+read_repository&state=${$page.params.id}`,
`${htmlUrl}/oauth/authorize?client_id=${application.gitSource.gitlabApp.appId}&redirect_uri=${ip}/webhooks/gitlab&response_type=code&scope=api+email+read_repository&state=${$page.params.id}`,
'GitLab',
'resizable=1, scrollbars=1, fullscreen=0, height=618, width=1020,top=' +
top +