Skip to content

Commit

Permalink
feat: add custom Gitlab instances
Browse files Browse the repository at this point in the history
  • Loading branch information
bfkss committed Jan 17, 2025
1 parent ec9b727 commit 5dded7e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ export default defineNuxtModule<ModuleOptions>({
clientId: '',
clientSecret: '',
redirectURL: '',
baseURL: 'https://gitlab.com',
})
// Spotify OAuth
runtimeConfig.oauth.spotify = defu(runtimeConfig.oauth.spotify, {
Expand Down
17 changes: 13 additions & 4 deletions src/runtime/server/lib/oauth/gitlab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ export interface OAuthGitLabConfig {
* @default process.env.NUXT_OAUTH_GITLAB_REDIRECT_URL
*/
redirectURL?: string

/**
* URL of your instance, if you are self-hosting
* @default https://gitlab.com
*/
baseURL?: string
}

export function defineOAuthGitLabEventHandler({
Expand All @@ -67,9 +73,12 @@ export function defineOAuthGitLabEventHandler({
onError,
}: OAuthConfig<OAuthGitLabConfig>) {
return eventHandler(async (event: H3Event) => {
config = defu(config, useRuntimeConfig(event).oauth?.gitlab, {
authorizationURL: 'https://gitlab.com/oauth/authorize',
tokenURL: 'https://gitlab.com/oauth/token',
const runtimeConfig = useRuntimeConfig(event).oauth?.gitlab
const baseURL
= config?.baseURL ?? runtimeConfig.baseURL ?? 'https://gitlab.com'
config = defu(config, runtimeConfig, {
authorizationURL: `${baseURL}/oauth/authorize`,
tokenURL: `${baseURL}/oauth/token`,
authorizationParams: {},
}) as OAuthGitLabConfig

Expand Down Expand Up @@ -134,7 +143,7 @@ export function defineOAuthGitLabEventHandler({
const accessToken = tokens.access_token
// TODO: improve typing
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const user: any = await $fetch('https://gitlab.com/api/v4/user', {
const user: any = await $fetch(`${baseURL}/api/v4/user`, {
headers: {
Authorization: `Bearer ${accessToken}`,
},
Expand Down

0 comments on commit 5dded7e

Please sign in to comment.