Skip to content

Commit 3e1011f

Browse files
committed
fix #153 next arg for oauth redirect needs to be double quoted to handle special characters
1 parent 739233e commit 3e1011f

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

sopy/auth/views.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from urllib.parse import urlencode, parse_qs
1+
from urllib.parse import urlencode, parse_qs, quote
22
from flask import url_for, redirect, request, session, current_app, render_template
33
import requests
44
from sopy import db
@@ -22,9 +22,10 @@ def login():
2222

2323
return render_template('auth/login.html', form=form)
2424

25+
next = quote(quote(request.args['next'])) if 'next' in request.args else None
2526
qs = urlencode({
2627
'client_id': current_app.config['SE_CONSUMER_KEY'],
27-
'redirect_uri': url_for('auth.authorized', next=request.args.get('next'), _external=True)
28+
'redirect_uri': url_for('auth.authorized', next=next, _external=True)
2829
})
2930
url = 'https://stackexchange.com/oauth?{}'.format(qs)
3031

@@ -33,11 +34,12 @@ def login():
3334

3435
@bp.route('/login/authorized')
3536
def authorized():
37+
next = quote(quote(request.args['next'])) if 'next' in request.args else None
3638
r = requests.post('https://stackexchange.com/oauth/access_token', {
3739
'client_id': current_app.config['SE_CONSUMER_KEY'],
3840
'client_secret': current_app.config['SE_CONSUMER_SECRET'],
3941
'code': request.args['code'],
40-
'redirect_uri': url_for('auth.authorized', next=request.args.get('next'), _external=True)
42+
'redirect_uri': url_for('auth.authorized', next=next, _external=True)
4143
})
4244

4345
session['oauth_token'] = parse_qs(r.text)['access_token'][0]

sopy/templates/base.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
</ul>
3030
<ul class="nav navbar-nav navbar-right">
3131
{% if current_user.anonymous %}
32-
<li><a href="{{ url_for('auth.login', next=request.path) }}">Log In</a></li>
32+
<li><a href="{{ url_for('auth.login', next=request.full_path if request.query_string else request.path) }}">Log In</a></li>
3333
{% else %}
3434
<li class="{% block nav_user %}{% endblock %}"><a href="#">{{ current_user.display_name }}</a></li>
3535
<li><a href="{{ url_for('auth.logout') }}">Log Out</a></li>

0 commit comments

Comments
 (0)