Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions apps/dokploy/pages/api/providers/gitlab/callback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,12 @@ 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.origin + gitlabUrl.pathname.replace(/\/$/, "");

const response = await fetch(`${url}/oauth/token`, {
method: "POST",
headers,
redirect: "manual",
body: new URLSearchParams({
client_id: gitlab.applicationId as string,
client_secret: gitlab.secret as string,
Expand All @@ -47,6 +41,12 @@ export default async function handler(
}),
});

if (!response.ok) {
return res.status(response.status).json({
error: `GitLab token exchange failed: ${response.statusText}`,
});
}

const result = await response.json();

if (!result.access_token || !result.refresh_token) {
Expand Down
4 changes: 3 additions & 1 deletion packages/server/src/utils/providers/gitlab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ export const refreshGitlabToken = async (gitlabProviderId: string) => {

// Use internal URL for token refresh when GitLab is on same instance as Dokploy
const baseUrl = gitlabProvider.gitlabInternalUrl || gitlabProvider.gitlabUrl;
const response = await fetch(`${baseUrl}/oauth/token`, {
const tokenUrl = new URL(baseUrl);
const response = await fetch(`${tokenUrl.origin}${tokenUrl.pathname.replace(/\/$/, "")}/oauth/token`, {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
redirect: "manual",
body: new URLSearchParams({
grant_type: "refresh_token",
refresh_token: gitlabProvider.refreshToken as string,
Expand Down