From 9d1b6d829a6c9b0b0ecdd882cc7df1393372f97f Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Thu, 6 Nov 2014 20:35:52 -0500 Subject: [PATCH] Make sure the external login link for GHE links to the enterprise GitHub and not the hosted version --- endpoints/common.py | 5 +---- static/js/app.js | 2 ++ static/js/controllers.js | 1 + static/partials/user-admin.html | 2 +- util/oauth.py | 29 +++++++++++++++++++++++------ 5 files changed, 28 insertions(+), 11 deletions(-) diff --git a/endpoints/common.py b/endpoints/common.py index 1fa5ae522..6a221bd5c 100644 --- a/endpoints/common.py +++ b/endpoints/common.py @@ -180,10 +180,7 @@ def render_page_template(name, **kwargs): def get_oauth_config(): oauth_config = {} for oauth_app in oauth_apps: - oauth_config[oauth_app.key_name] = { - 'CLIENT_ID': oauth_app.client_id(), - 'AUTHORIZE_ENDPOINT': oauth_app.authorize_endpoint() - } + oauth_config[oauth_app.key_name] = oauth_app.get_public_config() return oauth_config diff --git a/static/js/app.js b/static/js/app.js index 3e4ea32e9..b3f655ed9 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -1727,6 +1727,8 @@ quayApp = angular.module('quay', quayDependencies, function($provide, cfpLoading keyService['githubLoginUrl'] = oauth['GITHUB_LOGIN_CONFIG']['AUTHORIZE_ENDPOINT']; keyService['googleLoginUrl'] = oauth['GOOGLE_LOGIN_CONFIG']['AUTHORIZE_ENDPOINT']; + keyService['githubEndpoint'] = oauth['GITHUB_LOGIN_CONFIG']['GITHUB_ENDPOINT']; + keyService['githubTriggerAuthorizeUrl'] = oauth['GITHUB_LOGIN_CONFIG']['AUTHORIZE_ENDPOINT']; keyService['githubLoginScope'] = 'user:email'; diff --git a/static/js/controllers.js b/static/js/controllers.js index 3a44a0e3c..07041ae7a 100644 --- a/static/js/controllers.js +++ b/static/js/controllers.js @@ -1738,6 +1738,7 @@ function UserAdminCtrl($scope, $timeout, $location, ApiService, PlanService, Use if (login.service == 'github') { $scope.hasGithubLogin = true; $scope.githubLogin = login.metadata['service_username']; + $scope.githubEndpoint = KeyService['githubEndpoint']; } if (login.service == 'google') { diff --git a/static/partials/user-admin.html b/static/partials/user-admin.html index a51119531..3493702df 100644 --- a/static/partials/user-admin.html +++ b/static/partials/user-admin.html @@ -176,7 +176,7 @@
diff --git a/util/oauth.py b/util/oauth.py index f654098b9..5349e5435 100644 --- a/util/oauth.py +++ b/util/oauth.py @@ -37,17 +37,20 @@ class GithubOAuthConfig(OAuthConfig): def service_name(self): return 'GitHub' - def authorize_endpoint(self): + def _endpoint(self): endpoint = self.config.get('GITHUB_ENDPOINT', 'https://github.com') - return self._get_url(endpoint, '/login/oauth/authorize') + '?' + if not endpoint.endswith('/'): + endpoint = endpoint + '/' + return endpoint + + def authorize_endpoint(self): + return self._get_url(self._endpoint(), '/login/oauth/authorize') + '?' def token_endpoint(self): - endpoint = self.config.get('GITHUB_ENDPOINT', 'https://github.com') - return self._get_url(endpoint, '/login/oauth/access_token') + return self._get_url(self._endpoint(), '/login/oauth/access_token') def _api_endpoint(self): - endpoint = self.config.get('GITHUB_ENDPOINT', 'https://github.com') - return self.config.get('API_ENDPOINT', self._get_url(endpoint, '/api/v3/')) + return self.config.get('API_ENDPOINT', self._get_url(self._endpoint(), '/api/v3/')) def user_endpoint(self): api_endpoint = self._api_endpoint() @@ -57,6 +60,14 @@ class GithubOAuthConfig(OAuthConfig): api_endpoint = self._api_endpoint() return self._get_url(api_endpoint, 'user/emails') + def get_public_config(self): + return { + 'CLIENT_ID': self.client_id(), + 'AUTHORIZE_ENDPOINT': self.authorize_endpoint(), + 'GITHUB_ENDPOINT': self._endpoint() + } + + class GoogleOAuthConfig(OAuthConfig): def __init__(self, app, key_name): @@ -74,5 +85,11 @@ class GoogleOAuthConfig(OAuthConfig): def user_endpoint(self): return 'https://www.googleapis.com/oauth2/v1/userinfo' + def get_public_config(self): + return { + 'CLIENT_ID': self.client_id(), + 'AUTHORIZE_ENDPOINT': self.authorize_endpoint() + } +