1- from urllib .parse import urlencode , parse_qs
1+ from urllib .parse import urlencode , parse_qs , quote
22from flask import url_for , redirect , request , session , current_app , render_template
33import requests
44from 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' )
3536def 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 ]
0 commit comments