From c485f7375ebc31c4d907d9b74f9f0c1a8e6072f6 Mon Sep 17 00:00:00 2001 From: Paul Pacheco Date: Thu, 30 Jul 2020 04:43:02 -0500 Subject: [PATCH 1/5] Add configuration for github enterprise --- plugins/auth-backend/src/providers/github/provider.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/auth-backend/src/providers/github/provider.ts b/plugins/auth-backend/src/providers/github/provider.ts index 37d661f9ab..2404bd0be1 100644 --- a/plugins/auth-backend/src/providers/github/provider.ts +++ b/plugins/auth-backend/src/providers/github/provider.ts @@ -136,11 +136,17 @@ export function createGithubProvider( const appOrigin = envConfig.getString('appOrigin'); const clientID = envConfig.getString('clientId'); const clientSecret = envConfig.getString('clientSecret'); + const authorizationURL = envConfig.getOptionalString('authorizationURL'); + const tokenURL = envConfig.getOptionalString('tokenURL'); + const userProfileURL = envConfig.getOptionalString('userProfileURL'); const callbackURL = `${baseUrl}/${providerId}/handler/frame?env=${env}`; const opts = { clientID, clientSecret, + authorizationURL, + tokenURL, + userProfileURL, callbackURL, }; From 84d366527ac1d04005a668abfaee019d13d8ac05 Mon Sep 17 00:00:00 2001 From: Paul Pacheco Date: Thu, 30 Jul 2020 04:51:04 -0500 Subject: [PATCH 2/5] Get config from environment variables --- app-config.yaml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app-config.yaml b/app-config.yaml index e5f872201d..6ca9356053 100644 --- a/app-config.yaml +++ b/app-config.yaml @@ -48,6 +48,15 @@ auth: clientSecret: $secret: env: AUTH_GITHUB_CLIENT_SECRET + authorizationURL: + $secret: + env: AUTH_GITHUB_AUTHORIZATION_URL + tokenURL: + $secret: + env: AUTH_GITHUB_TOKEN_URL + userProfileUrl: + $secret: + env: AUTH_GITHUB_USER_PROFILE_URL gitlab: development: appOrigin: "http://localhost:3000/" From c0feeecc29e3ca93b90f777d6a14f75db04ce1de Mon Sep 17 00:00:00 2001 From: Paul Pacheco Date: Thu, 30 Jul 2020 04:53:35 -0500 Subject: [PATCH 3/5] Add documentation --- plugins/auth-backend/README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/plugins/auth-backend/README.md b/plugins/auth-backend/README.md index ff0b1c7a3d..7b52da4ad0 100644 --- a/plugins/auth-backend/README.md +++ b/plugins/auth-backend/README.md @@ -32,6 +32,16 @@ export AUTH_GITHUB_CLIENT_ID=x export AUTH_GITHUB_CLIENT_SECRET=x ``` +for github enterprise: + +```bash +export AUTH_GITHUB_CLIENT_ID=x +export AUTH_GITHUB_CLIENT_SECRET=x +export AUTH_GITHUB_AUTHORIZATION_URL=https://ENTERPRISE_INSTANCE_URL/login/oauth/authorize +export AUTH_GITHUB_TOKEN_URL=https://ENTERPRISE_INSTANCE_URL/login/oauth/access_token +export AUTH_GITHUB_USER_PROFILE_URL=https://ENTERPRISE_INSTANCE_URL/api/v3/user +``` + ### Gitlab ```bash From 5cde7069cfa01f3bfbabc6d8f97d83e4fd719278 Mon Sep 17 00:00:00 2001 From: Paul Pacheco Date: Thu, 30 Jul 2020 09:33:12 -0500 Subject: [PATCH 4/5] Pass github enterprise base url, derive urls for authentication --- app-config.yaml | 10 ++-------- plugins/auth-backend/README.md | 4 +--- .../auth-backend/src/providers/github/provider.ts | 15 ++++++++++++--- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/app-config.yaml b/app-config.yaml index 6ca9356053..514ba8e3c7 100644 --- a/app-config.yaml +++ b/app-config.yaml @@ -48,15 +48,9 @@ auth: clientSecret: $secret: env: AUTH_GITHUB_CLIENT_SECRET - authorizationURL: + enterpriseInstanceURL: $secret: - env: AUTH_GITHUB_AUTHORIZATION_URL - tokenURL: - $secret: - env: AUTH_GITHUB_TOKEN_URL - userProfileUrl: - $secret: - env: AUTH_GITHUB_USER_PROFILE_URL + env: AUTH_GITHUB_ENTERPRISE_INSTANCE_URL gitlab: development: appOrigin: "http://localhost:3000/" diff --git a/plugins/auth-backend/README.md b/plugins/auth-backend/README.md index 7b52da4ad0..f413d56fbd 100644 --- a/plugins/auth-backend/README.md +++ b/plugins/auth-backend/README.md @@ -37,9 +37,7 @@ for github enterprise: ```bash export AUTH_GITHUB_CLIENT_ID=x export AUTH_GITHUB_CLIENT_SECRET=x -export AUTH_GITHUB_AUTHORIZATION_URL=https://ENTERPRISE_INSTANCE_URL/login/oauth/authorize -export AUTH_GITHUB_TOKEN_URL=https://ENTERPRISE_INSTANCE_URL/login/oauth/access_token -export AUTH_GITHUB_USER_PROFILE_URL=https://ENTERPRISE_INSTANCE_URL/api/v3/user +export AUTH_GITHUB_ENTERPRISE_INSTANCE_URL=https://x ``` ### Gitlab diff --git a/plugins/auth-backend/src/providers/github/provider.ts b/plugins/auth-backend/src/providers/github/provider.ts index 2404bd0be1..ab102bad19 100644 --- a/plugins/auth-backend/src/providers/github/provider.ts +++ b/plugins/auth-backend/src/providers/github/provider.ts @@ -136,9 +136,18 @@ export function createGithubProvider( const appOrigin = envConfig.getString('appOrigin'); const clientID = envConfig.getString('clientId'); const clientSecret = envConfig.getString('clientSecret'); - const authorizationURL = envConfig.getOptionalString('authorizationURL'); - const tokenURL = envConfig.getOptionalString('tokenURL'); - const userProfileURL = envConfig.getOptionalString('userProfileURL'); + const enterpriseInstanceUrl = envConfig.getOptionalString( + 'enterpriseInstanceURL', + ); + const authorizationURL = enterpriseInstanceUrl + ? `${enterpriseInstanceUrl}/login/oauth/authorize` + : undefined; + const tokenURL = enterpriseInstanceUrl + ? `${enterpriseInstanceUrl}/login/oauth/access_token` + : undefined; + const userProfileURL = enterpriseInstanceUrl + ? `${enterpriseInstanceUrl}/api/v3/user` + : undefined; const callbackURL = `${baseUrl}/${providerId}/handler/frame?env=${env}`; const opts = { From b625b19978d796dda98e9f7ae90609dc31868faa Mon Sep 17 00:00:00 2001 From: Paul Pacheco Date: Thu, 30 Jul 2020 09:50:08 -0500 Subject: [PATCH 5/5] use cammel case --- app-config.yaml | 2 +- plugins/auth-backend/src/providers/github/provider.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app-config.yaml b/app-config.yaml index 514ba8e3c7..5f75ff522e 100644 --- a/app-config.yaml +++ b/app-config.yaml @@ -48,7 +48,7 @@ auth: clientSecret: $secret: env: AUTH_GITHUB_CLIENT_SECRET - enterpriseInstanceURL: + enterpriseInstanceUrl: $secret: env: AUTH_GITHUB_ENTERPRISE_INSTANCE_URL gitlab: diff --git a/plugins/auth-backend/src/providers/github/provider.ts b/plugins/auth-backend/src/providers/github/provider.ts index ab102bad19..e9c719ea1c 100644 --- a/plugins/auth-backend/src/providers/github/provider.ts +++ b/plugins/auth-backend/src/providers/github/provider.ts @@ -137,7 +137,7 @@ export function createGithubProvider( const clientID = envConfig.getString('clientId'); const clientSecret = envConfig.getString('clientSecret'); const enterpriseInstanceUrl = envConfig.getOptionalString( - 'enterpriseInstanceURL', + 'enterpriseInstanceUrl', ); const authorizationURL = enterpriseInstanceUrl ? `${enterpriseInstanceUrl}/login/oauth/authorize`