add github support, fix redirect on oauth

This commit is contained in:
Matthew Scragg 2015-10-21 09:09:42 -05:00
parent 4fede50136
commit 4375db4f8c
2 changed files with 19 additions and 9 deletions

View file

@ -17,6 +17,16 @@ providers = {
authorize_url='https://api.twitter.com/oauth/authenticate', authorize_url='https://api.twitter.com/oauth/authenticate',
access_token_method='GET'), access_token_method='GET'),
'button': '<a href="/login/oauth/twitter" class="btn btn-default"><i class="fa fa-twitter"></i> Twitter</a>' 'button': '<a href="/login/oauth/twitter" class="btn btn-default"><i class="fa fa-twitter"></i> Twitter</a>'
},
'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': '<a href="/login/oauth/github" class="btn btn-default"><i class="fa fa-github"></i> Github</a>'
} }
} }
@ -69,8 +79,8 @@ class User(BaseUser):
@staticmethod @staticmethod
def login_form(): def login_form():
buttons = '' buttons = []
for k, v in providers.items(): for k, v in providers.items():
buttons += v.get('button') buttons.append(v.get('button'))
return buttons return " ".join(buttons)

View file

@ -16,7 +16,7 @@ def login(provider):
@blueprint.route('/login/oauth/<provider>/callback') @blueprint.route('/login/oauth/<provider>/callback')
def callback(provider): 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: try:
resp = User.get_app(provider).authorized_response() resp = User.get_app(provider).authorized_response()
if resp is None: if resp is None: