Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions python_flask_jwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
import uuid
import jwt
import urllib
Copy link

@ianlintner-wf ianlintner-wf Sep 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For user examples it's always tricky just providing version changes... def not saying this is the RIGHT way just a couple other options.

Option 1:

import sys
if sys.version_info.major > 2:  # Python 3 or later
    from urllib.parse import quote
else:  # Python 2
    from urllib import quote

Option 2:

use pip install six
since the code already has pip dependency for jwt

Suggested change
import urllib
from six.moves.urllib.parse import quote

#Then change line 39 to

quote(return_to)

If not I would make the python3 version the default.




#init app
app = Flask(__name__)
# insert token here
app.config['SHARED_KEY'] = ''
# insert account prefix here (e.g. yoursite.zendesk.com)
Expand All @@ -24,11 +27,16 @@ def sso_redirector():
}

jwt_string = jwt.encode(payload, app.config['SHARED_KEY'])
# for python 3.7 use
# sso_url = "https://" + app.config ['SUBDOMAIN'] + ".zendesk.com/access/jwt?jwt=" + jwt_string.decode('utf8')

sso_url = "https://" + app.config ['SUBDOMAIN'] + ".zendesk.com/access/jwt?jwt=" + jwt_string
return_to = request.args.get('return_to')
return_to = request.args.get('return_to')

if return_to is not None:
sso_url += "&return_to=" + urllib.quote(return_to)
if return_to is not None:
# for python > 3.7 use
# sso_url += "&return_to=" + urllib.parse.quote(return_to)
sso_url += "&return_to=" + urllib.quote(return_to)
Comment on lines +38 to +39
Copy link

@ianlintner-wf ianlintner-wf Sep 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In tandem with above addition of import

Suggested change
# sso_url += "&return_to=" + urllib.parse.quote(return_to)
sso_url += "&return_to=" + urllib.quote(return_to)
sso_url += "&return_to=" + quote(return_to)


return redirect(sso_url)

Expand Down