diff --git a/flask_stormpath/views.py b/flask_stormpath/views.py index 61b1a0c..d03d575 100644 --- a/flask_stormpath/views.py +++ b/flask_stormpath/views.py @@ -23,6 +23,8 @@ ) from .models import User +# Add libraries to support url parsing from google redirect +import urllib,urlparse def register(): """ @@ -396,6 +398,12 @@ def google_login(): # Google user will be treated exactly like a normal Stormpath user! login_user(account, remember=True) + # First check if redirect from google included a state parameter that contained the next url + if 'state' in request.args: + params = urlparse.parse_qs(urllib.unquote(request.args.get('state'))) + if 'next' in params and len(params['next']) == 1: + return redirect(params['next'][0]) + return redirect(request.args.get('next') or current_app.config['STORMPATH_REDIRECT_URL'])