From 88622e642252008d10b8769f7182875412b80239 Mon Sep 17 00:00:00 2001 From: Nicolas Arnold Date: Mon, 27 Sep 2021 10:40:44 +0100 Subject: [PATCH 1/4] Add ability to override github app callback url By default, the github app provider redirects back to the base url. This change allows a user to override the GitHub App url using the config field `customCallbackUrl`. It will look like this in the configuration: ``` auth: providers: github: development: clientId: SUPER ID clientSecret: SUPER SECRET customCallbackUrl: https://some-url.com/callback ``` Signed-off-by: Nicolas Arnold --- .changeset/pretty-feet-explode.md | 5 +++++ plugins/auth-backend/src/providers/github/provider.ts | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 .changeset/pretty-feet-explode.md diff --git a/.changeset/pretty-feet-explode.md b/.changeset/pretty-feet-explode.md new file mode 100644 index 0000000000..c5cf0beb00 --- /dev/null +++ b/.changeset/pretty-feet-explode.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-auth-backend': patch +--- + +Allow users to override callback url of Github provider diff --git a/plugins/auth-backend/src/providers/github/provider.ts b/plugins/auth-backend/src/providers/github/provider.ts index b6b198b644..8abd4c76ea 100644 --- a/plugins/auth-backend/src/providers/github/provider.ts +++ b/plugins/auth-backend/src/providers/github/provider.ts @@ -223,6 +223,9 @@ export const createGithubProvider = ( const enterpriseInstanceUrl = envConfig.getOptionalString( 'enterpriseInstanceUrl', ); + const customCallbackUrl = envConfig.getOptionalString( + 'customCallbackUrl', + ); const authorizationUrl = enterpriseInstanceUrl ? `${enterpriseInstanceUrl}/login/oauth/authorize` : undefined; @@ -232,7 +235,8 @@ export const createGithubProvider = ( const userProfileUrl = enterpriseInstanceUrl ? `${enterpriseInstanceUrl}/api/v3/user` : undefined; - const callbackUrl = `${globalConfig.baseUrl}/${providerId}/handler/frame`; + const callbackUrl = customCallbackUrl || + `${globalConfig.baseUrl}/${providerId}/handler/frame`; const catalogIdentityClient = new CatalogIdentityClient({ catalogApi, From e6cb54be9bd90cb396db1d62277ee66c9d176d00 Mon Sep 17 00:00:00 2001 From: Nicolas Arnold Date: Mon, 27 Sep 2021 11:09:39 +0100 Subject: [PATCH 2/4] Fix formating Signed-off-by: Nicolas Arnold --- .changeset/pretty-feet-explode.md | 2 +- plugins/auth-backend/src/providers/github/provider.ts | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.changeset/pretty-feet-explode.md b/.changeset/pretty-feet-explode.md index c5cf0beb00..46237068c5 100644 --- a/.changeset/pretty-feet-explode.md +++ b/.changeset/pretty-feet-explode.md @@ -2,4 +2,4 @@ '@backstage/plugin-auth-backend': patch --- -Allow users to override callback url of Github provider +Allow users to override callback url of GitHub provider diff --git a/plugins/auth-backend/src/providers/github/provider.ts b/plugins/auth-backend/src/providers/github/provider.ts index 8abd4c76ea..41d08b9230 100644 --- a/plugins/auth-backend/src/providers/github/provider.ts +++ b/plugins/auth-backend/src/providers/github/provider.ts @@ -223,9 +223,8 @@ export const createGithubProvider = ( const enterpriseInstanceUrl = envConfig.getOptionalString( 'enterpriseInstanceUrl', ); - const customCallbackUrl = envConfig.getOptionalString( - 'customCallbackUrl', - ); + const customCallbackUrl = + envConfig.getOptionalString('customCallbackUrl'); const authorizationUrl = enterpriseInstanceUrl ? `${enterpriseInstanceUrl}/login/oauth/authorize` : undefined; @@ -235,8 +234,9 @@ export const createGithubProvider = ( const userProfileUrl = enterpriseInstanceUrl ? `${enterpriseInstanceUrl}/api/v3/user` : undefined; - const callbackUrl = customCallbackUrl || - `${globalConfig.baseUrl}/${providerId}/handler/frame`; + const callbackUrl = + customCallbackUrl || + `${globalConfig.baseUrl}/${providerId}/handler/frame`; const catalogIdentityClient = new CatalogIdentityClient({ catalogApi, From 4098ade69d562e36548925be69099f15a0c524e6 Mon Sep 17 00:00:00 2001 From: Nicolas Arnold Date: Mon, 27 Sep 2021 17:26:40 +0100 Subject: [PATCH 3/4] Addressing comments Signed-off-by: Nicolas Arnold --- docs/auth/github/provider.md | 6 ++++++ plugins/auth-backend/src/providers/github/provider.ts | 3 +-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/docs/auth/github/provider.md b/docs/auth/github/provider.md index 05726e8a4e..bcd6f3092e 100644 --- a/docs/auth/github/provider.md +++ b/docs/auth/github/provider.md @@ -41,6 +41,8 @@ auth: clientSecret: ${AUTH_GITHUB_CLIENT_SECRET} ## uncomment if using GitHub Enterprise # enterpriseInstanceUrl: ${AUTH_GITHUB_ENTERPRISE_INSTANCE_URL} + ## uncomment if intermediate service is used when using github apps + # callbackUrl: ${AUTH_GITHUB_CALLBACK_URL} ``` The GitHub provider is a structure with three configuration keys: @@ -50,6 +52,10 @@ The GitHub provider is a structure with three configuration keys: - `clientSecret`: The client secret tied to the generated client ID. - `enterpriseInstanceUrl` (optional): The base URL for a GitHub Enterprise instance, e.g. `https://ghe..com`. Only needed for GitHub Enterprise. +- `callbackUrl` (optional): The callback url that GitHub will use when + initiating an OAuth flow, e.g. + `https://your-intermediate-service.com/handler`. Only needed if Backstage is + not the immediate receiver (e.g. one OAuth app for many backstage instances). ## Adding the provider to the Backstage frontend diff --git a/plugins/auth-backend/src/providers/github/provider.ts b/plugins/auth-backend/src/providers/github/provider.ts index 41d08b9230..f1949eafa3 100644 --- a/plugins/auth-backend/src/providers/github/provider.ts +++ b/plugins/auth-backend/src/providers/github/provider.ts @@ -223,8 +223,7 @@ export const createGithubProvider = ( const enterpriseInstanceUrl = envConfig.getOptionalString( 'enterpriseInstanceUrl', ); - const customCallbackUrl = - envConfig.getOptionalString('customCallbackUrl'); + const customCallbackUrl = envConfig.getOptionalString('callbackUrl'); const authorizationUrl = enterpriseInstanceUrl ? `${enterpriseInstanceUrl}/login/oauth/authorize` : undefined; From 8e43457f2cdc94763e710dc5aa1be0d28481576e Mon Sep 17 00:00:00 2001 From: Nicolas Arnold Date: Tue, 28 Sep 2021 12:37:34 +0100 Subject: [PATCH 4/4] Addressing doc comment Signed-off-by: Nicolas Arnold --- docs/auth/github/provider.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/auth/github/provider.md b/docs/auth/github/provider.md index bcd6f3092e..d8803e392d 100644 --- a/docs/auth/github/provider.md +++ b/docs/auth/github/provider.md @@ -41,8 +41,6 @@ auth: clientSecret: ${AUTH_GITHUB_CLIENT_SECRET} ## uncomment if using GitHub Enterprise # enterpriseInstanceUrl: ${AUTH_GITHUB_ENTERPRISE_INSTANCE_URL} - ## uncomment if intermediate service is used when using github apps - # callbackUrl: ${AUTH_GITHUB_CALLBACK_URL} ``` The GitHub provider is a structure with three configuration keys: