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
38 changes: 34 additions & 4 deletions docs/pages/getting-started/providers/gitlab.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
})
],
})
```

Expand All @@ -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"
}
})
],
})
)
```
Expand All @@ -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"
}
})
],
})
```

Expand All @@ -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"
}
})
] }))
```

</Code.Express>
Expand Down
20 changes: 14 additions & 6 deletions packages/core/src/providers/gitlab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,24 +109,32 @@ export interface GitLabProfile extends Record<string, any> {
* :::
*/
export default function GitLab<P extends GitLabProfile>(
options: OAuthUserConfig<P>
config: OAuthUserConfig<P> & {
/** Configuration for usage with self-hosted GitLab instances. */
instance?: {
/** The base URL of your GitLab instance. */
baseUrl?: string
}
}
): OAuthConfig<P> {
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,
}
}