Skip to content

Instantly share code, notes, and snippets.

@jbdietrich
Last active December 8, 2019 18:58
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbdietrich/5489562 to your computer and use it in GitHub Desktop.
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 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