From f0278f354b7346f84e79d9573a909063531a8cc1 Mon Sep 17 00:00:00 2001 From: Alex Renoki Date: Mon, 11 Aug 2025 09:56:49 +0300 Subject: [PATCH 1/2] Added support for Basic Auth present in the GitLab URLs --- .../pages/api/providers/gitlab/callback.ts | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/apps/dokploy/pages/api/providers/gitlab/callback.ts b/apps/dokploy/pages/api/providers/gitlab/callback.ts index e32e0a7ad..cb51da9d2 100644 --- a/apps/dokploy/pages/api/providers/gitlab/callback.ts +++ b/apps/dokploy/pages/api/providers/gitlab/callback.ts @@ -12,12 +12,29 @@ export default async function handler( } const gitlab = await findGitlabById(gitlabId as string); + const gitlabUrl = new URL(gitlab.gitlabUrl) - const response = await fetch(`${gitlab.gitlabUrl}/oauth/token`, { + const headers: HeadersInit = { + "Content-Type": "application/x-www-form-urlencoded" + } + + // In case of basic auth being present in the URL, we need to remove it from the URL + // and add it to the Authorization header. + if (gitlabUrl.username && gitlabUrl.password) { + headers.Authorization = `Basic ${Buffer.from(`${gitlabUrl.username}:${gitlabUrl.password}`).toString("base64")}`; + } + + const url = (gitlabUrl.username && gitlabUrl.password) + ? new URL(gitlabUrl, { + ...gitlabUrl, + username: "", + password: "", + }).toString() + : gitlabUrl.toString(); + + const response = await fetch(`${url}/oauth/token`, { method: "POST", - headers: { - "Content-Type": "application/x-www-form-urlencoded", - }, + headers, body: new URLSearchParams({ client_id: gitlab.applicationId as string, client_secret: gitlab.secret as string, From 81ab71ba23e391cfae7002d314e7b06908c1ba6a Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Sun, 17 Aug 2025 01:33:47 +0000 Subject: [PATCH 2/2] [autofix.ci] apply automated fixes --- .../pages/api/providers/gitlab/callback.ts | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/apps/dokploy/pages/api/providers/gitlab/callback.ts b/apps/dokploy/pages/api/providers/gitlab/callback.ts index cb51da9d2..008873511 100644 --- a/apps/dokploy/pages/api/providers/gitlab/callback.ts +++ b/apps/dokploy/pages/api/providers/gitlab/callback.ts @@ -12,11 +12,11 @@ export default async function handler( } const gitlab = await findGitlabById(gitlabId as string); - const gitlabUrl = new URL(gitlab.gitlabUrl) + const gitlabUrl = new URL(gitlab.gitlabUrl); const headers: HeadersInit = { - "Content-Type": "application/x-www-form-urlencoded" - } + "Content-Type": "application/x-www-form-urlencoded", + }; // In case of basic auth being present in the URL, we need to remove it from the URL // and add it to the Authorization header. @@ -24,13 +24,14 @@ export default async function handler( headers.Authorization = `Basic ${Buffer.from(`${gitlabUrl.username}:${gitlabUrl.password}`).toString("base64")}`; } - const url = (gitlabUrl.username && gitlabUrl.password) - ? new URL(gitlabUrl, { - ...gitlabUrl, - username: "", - password: "", - }).toString() - : gitlabUrl.toString(); + const url = + gitlabUrl.username && gitlabUrl.password + ? new URL(gitlabUrl, { + ...gitlabUrl, + username: "", + password: "", + }).toString() + : gitlabUrl.toString(); const response = await fetch(`${url}/oauth/token`, { method: "POST",