def oauth_authorized(): # pragma: no cover
"""Authorize facebook login."""
resp = facebook.oauth.authorized_response()
next_url = request.args.get('next') or url_for('home.home')
if resp is None:
flash(u'You denied the request to sign in.', 'error')
flash(u'Reason: ' + request.args['error_reason'] +
' ' + request.args['error_description'], 'error')
return redirect(next_url)
if isinstance(resp, OAuthException):
flash('Access denied: %s' % resp.message)
current_app.logger.error(resp)
return redirect(next_url)
# We have to store the oauth_token in the session to get the USER fields
access_token = resp['access_token']
session['oauth_token'] = (resp['access_token'], '')
user_data = facebook.oauth.get('/me').data
user = manage_user(access_token, user_data)
return manage_user_login(user, user_data, next_url)
评论列表
文章目录