From 4375db4f8c107a73a5ee861e6ad0f9d5a7da02e2 Mon Sep 17 00:00:00 2001 From: Matthew Scragg Date: Wed, 21 Oct 2015 09:09:42 -0500 Subject: [PATCH] add github support, fix redirect on oauth --- realms/modules/auth/oauth/models.py | 26 ++++++++++++++++++-------- realms/modules/auth/oauth/views.py | 2 +- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/realms/modules/auth/oauth/models.py b/realms/modules/auth/oauth/models.py index 252756e..3a24840 100644 --- a/realms/modules/auth/oauth/models.py +++ b/realms/modules/auth/oauth/models.py @@ -17,6 +17,16 @@ providers = { authorize_url='https://api.twitter.com/oauth/authenticate', access_token_method='GET'), 'button': ' Twitter' + }, + 'github': { + 'oauth': dict( + request_token_params={'scope': 'user:email'}, + base_url='https://api.github.com/', + request_token_url=None, + access_token_method='POST', + access_token_url='https://github.com/login/oauth/access_token', + authorize_url='https://github.com/login/oauth/authorize'), + 'button': ' Github' } } @@ -58,19 +68,19 @@ class User(BaseUser): if oauth.remote_apps.get(provider): return oauth.remote_apps.get(provider) return oauth.remote_app( - provider, - consumer_key=config.OAUTH.get(provider, {}).get('key'), - consumer_secret=config.OAUTH.get(provider, {}).get( - 'secret'), - **providers[provider]['oauth']) + provider, + consumer_key=config.OAUTH.get(provider, {}).get('key'), + consumer_secret=config.OAUTH.get(provider, {}).get( + 'secret'), + **providers[provider]['oauth']) def get_id(self): return unicode("%s/%s/%s" % (self.type, self.provider, self.id)) @staticmethod def login_form(): - buttons = '' + buttons = [] for k, v in providers.items(): - buttons += v.get('button') + buttons.append(v.get('button')) - return buttons + return " ".join(buttons) diff --git a/realms/modules/auth/oauth/views.py b/realms/modules/auth/oauth/views.py index 9c52cf4..fc4970f 100644 --- a/realms/modules/auth/oauth/views.py +++ b/realms/modules/auth/oauth/views.py @@ -16,7 +16,7 @@ def login(provider): @blueprint.route('/login/oauth//callback') def callback(provider): - next_url = request.args.get('next') or current_app.config['ROOT_ENDPOINT'] + next_url = request.args.get('next') or url_for(current_app.config['ROOT_ENDPOINT']) try: resp = User.get_app(provider).authorized_response() if resp is None: