Skip to content

Instantly share code, notes, and snippets.

@jbdietrich
Last active December 14, 2015 03:39
Show Gist options
  • Save jbdietrich/5022412 to your computer and use it in GitHub Desktop.
Save jbdietrich/5022412 to your computer and use it in GitHub Desktop.
"""
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 + "&timestamp=" + 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