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..69b25dca25 100644 --- a/packages/core/src/providers/gitlab.ts +++ b/packages/core/src/providers/gitlab.ts @@ -109,24 +109,32 @@ 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" + 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: `${baseUrl}/oauth/authorize?scope=read_user`, + token: `${baseUrl}/oauth/token`, + userinfo: `${baseUrl}/api/v4/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, } }