mirror of
https://github.com/andwati/dokploy.git
synced 2026-12-02 15:58:46 +00:00
Added support for Basic Auth present in the GitLab URLs
This commit is contained in:
@@ -12,12 +12,29 @@ export default async function handler(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const gitlab = await findGitlabById(gitlabId as string);
|
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",
|
method: "POST",
|
||||||
headers: {
|
headers,
|
||||||
"Content-Type": "application/x-www-form-urlencoded",
|
|
||||||
},
|
|
||||||
body: new URLSearchParams({
|
body: new URLSearchParams({
|
||||||
client_id: gitlab.applicationId as string,
|
client_id: gitlab.applicationId as string,
|
||||||
client_secret: gitlab.secret as string,
|
client_secret: gitlab.secret as string,
|
||||||
|
|||||||
Reference in New Issue
Block a user