forked from zendesk/zendesk_jwt_sso_examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_flask_jwt.py
More file actions
36 lines (28 loc) · 983 Bytes
/
Copy pathpython_flask_jwt.py
File metadata and controls
36 lines (28 loc) · 983 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# This example relies on you having installed PyJWT, `sudo easy_install PyJWT` - you can
# read more about this in the GitHub repository https://github.com/progrium/pyjwt
from flask import Flask, request, redirect
import time
import uuid
import jwt
import urllib
# insert token here
app.config['SHARED_KEY'] = ''
# insert account prefix here (e.g. yoursite.zendesk.com)
app.config['SUBDOMAIN'] = 'yoursite'
@app.route('/zendesk-jwt')
def sso_redirector():
payload = {
"iat": int(time.time()),
"jti": str(uuid.uuid1()),
# populate these values from your data source
"name": '',
"email": ''
}
jwt_string = jwt.encode(payload, app.config['SHARED_KEY'])
sso_url = "https://" + app.config ['SUBDOMAIN'] + ".zendesk.com/access/jwt?jwt=" + jwt_string
return_to = request.args.get('return_to')
if return_to is not None:
sso_url += "&return_to=" + urllib.quote(return_to)
return redirect(sso_url)
if __name__ == "__main__":
app.run()