Last active
December 14, 2015 03:39
-
-
Save jbdietrich/5022412 to your computer and use it in GitHub Desktop.
This file contains 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
""" | |
Remote authentication stub for Flask | |
This is meant as a template for your own customization. | |
You can identify the user anyway you like, | |
integrate it into your intranet, web app or similar. | |
""" | |
from flask import Flask, request, redirect | |
import time | |
import md5 | |
app = Flask(__name__) | |
# insert authentication token here | |
app.config['RA_TOKEN'] = '' | |
# insert account prefix here (e.g. yoursite.zendesk.com) | |
app.config['ZD_URL_PREFIX'] = 'yoursite' | |
@app.route('/zendesk-remoteauth') | |
def redirector(): | |
# populate these values from your data source | |
full_name = '' | |
email = '' | |
external_id = '' | |
organization = '' | |
tags = '' | |
remote_photo_url = '' | |
return_to = '' | |
# build the message | |
try: | |
timestamp = request.args['timestamp'] | |
except KeyError: | |
timestamp = str(time.time()).split('.')[0] | |
pre_hash = full_name + "|" + email + "|" + external_id + "|" + organization \ | |
+ "|" + tags + "|" + remote_photo_url + "|" + app.config['RA_TOKEN'] + "|" + \ | |
timestamp | |
post_hash = md5.new(pre_hash).hexdigest() | |
sso_url = "https://" + app.config['ZD_URL_PREFIX'] + \ | |
".zendesk.com/access/remoteauth/?name=" + full_name + "&email=" + email + \ | |
"&external_id=" + external_id + "×tamp=" + timestamp + "&hash=" + \ | |
post_hash + "&return_to=" + return_to | |
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