From fd5a94ec8927fcdc8e75661fe9a65bafbb76f744 Mon Sep 17 00:00:00 2001 From: Hendrik Heil Date: Wed, 5 Nov 2025 17:35:30 +0100 Subject: [PATCH 1/2] feat(github): allow defining custom redirect_url --- .../src/runtime/server/routes/auth/github.get.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/module/src/runtime/server/routes/auth/github.get.ts b/src/module/src/runtime/server/routes/auth/github.get.ts index 711a532b..2d9b804e 100644 --- a/src/module/src/runtime/server/routes/auth/github.get.ts +++ b/src/module/src/runtime/server/routes/auth/github.get.ts @@ -58,7 +58,7 @@ export interface OAuthGitHubConfig { /** * Redirect URL to to allow overriding for situations like prod failing to determine public hostname - * @default process.env.NUXT_OAUTH_GITHUB_REDIRECT_URL + * @default process.env.NUXT_STUDIO_AUTH_GITHUB_REDIRECT_URL * @see https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/differences-between-github-apps-and-oauth-apps */ redirectURL?: string @@ -109,7 +109,9 @@ export default eventHandler(async (event: H3Event) => { } const requestURL = getRequestURL(event) - const redirectURL = `${requestURL.protocol}//${requestURL.host}${requestURL.pathname}` + + config.redirectURL = config.redirectURL || `${requestURL.protocol}//${requestURL.host}${requestURL.pathname}` + const state = await handleState(event) if (!query.code) { @@ -125,7 +127,7 @@ export default eventHandler(async (event: H3Event) => { event, withQuery(config.authorizationURL as string, { client_id: config.clientId, - redirect_uri: redirectURL, + redirect_uri: config.redirectURL, scope: config.scope.join(' '), state, ...config.authorizationParams, @@ -149,7 +151,7 @@ export default eventHandler(async (event: H3Event) => { grant_type: 'authorization_code', client_id: config.clientId, client_secret: config.clientSecret, - redirect_uri: redirectURL, + redirect_uri: config.redirectURL, code: query.code, }, }) From 6229e6ff377a8615c60fad308b0c8c09d9eab5af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Wed, 5 Nov 2025 18:06:19 +0100 Subject: [PATCH 2/2] chore use proper env --- src/module/src/runtime/server/routes/auth/github.get.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/module/src/runtime/server/routes/auth/github.get.ts b/src/module/src/runtime/server/routes/auth/github.get.ts index 2d9b804e..c99ee899 100644 --- a/src/module/src/runtime/server/routes/auth/github.get.ts +++ b/src/module/src/runtime/server/routes/auth/github.get.ts @@ -10,12 +10,12 @@ import { useRuntimeConfig } from '#imports' export interface OAuthGitHubConfig { /** * GitHub OAuth Client ID - * @default process.env.NUXT_OAUTH_GITHUB_CLIENT_ID + * @default process.env.STUDIO_GITHUB_CLIENT_ID */ clientId?: string /** * GitHub OAuth Client Secret - * @default process.env.NUXT_OAUTH_GITHUB_CLIENT_SECRET + * @default process.env.STUDIO_GITHUB_CLIENT_SECRET */ clientSecret?: string /** @@ -58,8 +58,8 @@ export interface OAuthGitHubConfig { /** * Redirect URL to to allow overriding for situations like prod failing to determine public hostname - * @default process.env.NUXT_STUDIO_AUTH_GITHUB_REDIRECT_URL - * @see https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/differences-between-github-apps-and-oauth-apps + * Use `process.env.STUDIO_GITHUB_REDIRECT_URL` to overwrite the default redirect URL. + * @default is ${hostname}/__nuxt_studio/auth/github */ redirectURL?: string } @@ -83,6 +83,7 @@ export default eventHandler(async (event: H3Event) => { const config = defu(useRuntimeConfig(event).studio?.auth?.github, { clientId: process.env.STUDIO_GITHUB_CLIENT_ID, clientSecret: process.env.STUDIO_GITHUB_CLIENT_SECRET, + redirectURL: process.env.STUDIO_GITHUB_REDIRECT_URL, authorizationURL: 'https://github.com/login/oauth/authorize', tokenURL: 'https://github.com/login/oauth/access_token', apiURL: 'https://api.github.com',