From bbb830d90b684ecc1f9285c19abef3cb3accd13f Mon Sep 17 00:00:00 2001 From: Tobias Heinze Date: Mon, 29 Sep 2025 09:41:57 +0000 Subject: [PATCH 1/2] Updated Gitlab Provider to support baseURL for self hosted Instances --- .../getting-started/providers/gitlab.mdx | 38 +++++++++++++++++-- packages/core/src/providers/gitlab.ts | 27 ++++++++++--- 2 files changed, 55 insertions(+), 10 deletions(-) diff --git a/docs/pages/getting-started/providers/gitlab.mdx b/docs/pages/getting-started/providers/gitlab.mdx index 85a6f7207a..040d1f97df 100644 --- a/docs/pages/getting-started/providers/gitlab.mdx +++ b/docs/pages/getting-started/providers/gitlab.mdx @@ -54,7 +54,16 @@ import NextAuth from "next-auth" import GitLab from "next-auth/providers/gitlab" export const { handlers, auth, signIn, signOut } = NextAuth({ - providers: [GitLab], + providers: [ + // Default (gitlab.com) + GitLab, + // Self-hosted example + GitLab({ + instance: { + baseUrl: "https://gitlab.example.com" + } + }) + ], }) ``` @@ -67,7 +76,14 @@ import GitLab from "@auth/qwik/providers/gitlab" export const { onRequest, useSession, useSignIn, useSignOut } = QwikAuth$( () => ({ - providers: [GitLab], + providers: [ + GitLab, + GitLab({ + instance: { + baseUrl: "https://gitlab.example.com" + } + }) + ], }) ) ``` @@ -80,7 +96,14 @@ import { SvelteKitAuth } from "@auth/sveltekit" import GitLab from "@auth/sveltekit/providers/gitlab" export const { handle, signIn, signOut } = SvelteKitAuth({ - providers: [GitLab], + providers: [ + GitLab, + GitLab({ + instance: { + baseUrl: "https://gitlab.example.com" + } + }) + ], }) ``` @@ -91,7 +114,14 @@ export const { handle, signIn, signOut } = SvelteKitAuth({ import { ExpressAuth } from "@auth/express" import GitLab from "@auth/express/providers/gitlab" -app.use("/auth/*", ExpressAuth({ providers: [GitLab] })) +app.use("/auth/*", ExpressAuth({ providers: [ + GitLab, + GitLab({ + instance: { + baseUrl: "https://gitlab.example.com" + } + }) +] })) ``` diff --git a/packages/core/src/providers/gitlab.ts b/packages/core/src/providers/gitlab.ts index cc2562586d..dfccf6a659 100644 --- a/packages/core/src/providers/gitlab.ts +++ b/packages/core/src/providers/gitlab.ts @@ -109,24 +109,39 @@ export interface GitLabProfile extends Record { * ::: */ export default function GitLab

( - options: OAuthUserConfig

+ config: OAuthUserConfig

& { + /** Configuration for usage with self-hosted GitLab instances. */ + instance?: { + /** The base URL of your GitLab instance. */ + baseUrl?: string + } + } ): OAuthConfig

{ + const baseUrl = config?.instance?.baseUrl ?? "https://gitlab.com" + const apiBaseUrl = config?.instance?.baseUrl + ? `${config?.instance?.baseUrl}/api/v4` + : "https://gitlab.com/api/v4" + return { id: "gitlab", name: "GitLab", type: "oauth", - authorization: "https://gitlab.com/oauth/authorize?scope=read_user", - token: "https://gitlab.com/oauth/token", - userinfo: "https://gitlab.com/api/v4/user", + authorization: { + url: `${baseUrl}/oauth/authorize?scope=read_user`, + }, + token: `${baseUrl}/oauth/token`, + userinfo: { + url: `${apiBaseUrl}/user`, + }, profile(profile) { return { - id: profile.sub?.toString(), + id: profile.sub?.toString() ?? profile.id?.toString(), name: profile.name ?? profile.username, email: profile.email, image: profile.avatar_url, } }, style: { bg: "#FC6D26", text: "#fff" }, - options, + options: config, } } From f8662d09a7fba44a3675a0c02b9791e28a7949b4 Mon Sep 17 00:00:00 2001 From: Tobias Heinze Date: Mon, 29 Sep 2025 09:50:11 +0000 Subject: [PATCH 2/2] Fix the api Base URL --- packages/core/src/providers/gitlab.ts | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/packages/core/src/providers/gitlab.ts b/packages/core/src/providers/gitlab.ts index dfccf6a659..69b25dca25 100644 --- a/packages/core/src/providers/gitlab.ts +++ b/packages/core/src/providers/gitlab.ts @@ -118,21 +118,14 @@ export default function GitLab

( } ): OAuthConfig

{ const baseUrl = config?.instance?.baseUrl ?? "https://gitlab.com" - const apiBaseUrl = config?.instance?.baseUrl - ? `${config?.instance?.baseUrl}/api/v4` - : "https://gitlab.com/api/v4" return { id: "gitlab", name: "GitLab", type: "oauth", - authorization: { - url: `${baseUrl}/oauth/authorize?scope=read_user`, - }, + authorization: `${baseUrl}/oauth/authorize?scope=read_user`, token: `${baseUrl}/oauth/token`, - userinfo: { - url: `${apiBaseUrl}/user`, - }, + userinfo: `${baseUrl}/api/v4/user`, profile(profile) { return { id: profile.sub?.toString() ?? profile.id?.toString(),