get oauth data from providers

This commit is contained in:
Matthew Scragg 2015-11-12 17:19:26 -06:00
parent 96b583d63b
commit 6edaec3876
3 changed files with 38 additions and 15 deletions

View file

@ -18,7 +18,8 @@ def login(provider):
def callback(provider):
next_url = request.args.get('next') or url_for(current_app.config['ROOT_ENDPOINT'])
try:
resp = User.get_app(provider).authorized_response()
remote_app = User.get_app(provider)
resp = remote_app.authorized_response()
if resp is None:
flash('You denied the request to sign in.', 'error')
flash('Reason: ' + request.args['error_reason'] +
@ -28,11 +29,9 @@ def callback(provider):
flash('Access denied: %s' % e.message)
return redirect(next_url)
session[provider + '_token'] = (
resp['oauth_token'],
resp['oauth_token_secret']
)
profile = User.get_provider_value(provider, 'profile')
data = remote_app.get(profile) if profile else resp
User.auth(provider, resp)
User.auth(provider, data, resp)
return redirect(next_url)