Last active
December 8, 2019 18:58
-
-
Save jbdietrich/5489562 to your computer and use it in GitHub Desktop.
A naive implementation of Zendesk's JWT-based Remote Auth for Flask
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
# 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 redirect(sso_url) | |
if __name__ == "__main__": | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment