oauth work

This commit is contained in:
Matthew Scragg 2015-10-15 17:36:47 -05:00
parent e9709b6c8f
commit a0124baf1d
4 changed files with 66 additions and 28 deletions

View file

@ -10,17 +10,23 @@ def oauth_failed(next_url):
@blueprint.route("/login/oauth/<provider>")
def oauth_login(provider):
return User.get_app(provider).authorize(callback=url_for('oauth_callback', provider=provider,
next=request.args.get('next') or request.referrer or None))
def login(provider):
return User.get_app(provider).authorize(callback=url_for('auth.oauth.callback', provider=provider))
@blueprint.route('/login/oauth/<provider>/callback')
def oauth_callback(provider):
def callback(provider):
next_url = request.args.get('next') or url_for('index')
resp = User.get_app(provider).authorized_response()
if resp is None:
return oauth_failed(next_url)
try:
resp = User.get_app(provider).authorized_response()
if resp is None:
flash('You denied the request to sign in.', 'error')
flash('Reason: ' + request.args['error_reason'] +
' ' + request.args['error_description'], 'error')
return redirect(next_url)
except Exception as e:
flash('Access denied: %s' % e.message)
return redirect(next_url)
session[provider + '_token'] = (
resp['oauth_token'],