Fix next for Google oauth

This commit is contained in:
Adam Kariv 2015-12-26 23:19:37 +02:00
parent 5e25ba0cf6
commit a9ccfb8b42
3 changed files with 12 additions and 8 deletions

View File

@ -1,8 +1,8 @@
import logging
from flask.ext.login import login_user
import requests
from flask import redirect, url_for, Blueprint, flash
from flask_oauth import OAuth
from flask import redirect, url_for, Blueprint, flash, request
from flask_oauthlib.client import OAuth
from redash import models, settings
logger = logging.getLogger('google_oauth')
@ -18,11 +18,9 @@ google = oauth.remote_app('google',
request_token_url=None,
request_token_params={
'scope': 'https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile',
'response_type': 'code'
},
access_token_url='https://accounts.google.com/o/oauth2/token',
access_token_method='POST',
access_token_params={'grant_type': 'authorization_code'},
consumer_key=settings.GOOGLE_CLIENT_ID,
consumer_secret=settings.GOOGLE_CLIENT_SECRET)
@ -65,10 +63,10 @@ def create_and_login_user(name, email):
@blueprint.route('/oauth/google', endpoint="authorize")
def login():
# TODO, suport next
next = request.args.get('next','/')
callback=url_for('.callback', _external=True)
logger.debug("Callback url: %s", callback)
return google.authorize(callback=callback)
return google.authorize(callback=callback, state=next)
@blueprint.route('/oauth/google_callback', endpoint="callback")
@ -93,4 +91,6 @@ def authorized(resp):
create_and_login_user(profile['name'], profile['email'])
return redirect(url_for('index'))
next = request.args.get('state','/')
return redirect(next)

View File

@ -2,7 +2,7 @@ Flask==0.10.1
Flask-Admin==1.1.0
Flask-RESTful==0.2.10
Flask-Login==0.2.11
Flask-OAuth==0.12
Flask-OAuthLib==0.9.2
flask-mail==0.9.1
passlib==1.6.2
Jinja2==2.7.2

View File

@ -3,6 +3,10 @@ os.environ['REDASH_REDIS_URL'] = "redis://localhost:6379/5"
# Use different url for Celery to avoid DB being cleaned up:
os.environ['REDASH_CELERY_BROKER'] = "redis://localhost:6379/6"
# Dummy values for oauth login
os.environ['REDASH_GOOGLE_CLIENT_ID'] = "dummy"
os.environ['REDASH_GOOGLE_CLIENT_SECRET'] = "dummy"
import logging
from unittest import TestCase