Last active
March 14, 2019 13:05
-
-
Save pbertera/a788324b2235a0ff447e to your computer and use it in GitHub Desktop.
Freshdesk Single sign-on in Python
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
import time | |
import hashlib | |
import hmac | |
import urllib | |
def get_sso_url(email, name, base_url, key, redirect_url=None, phone=None, company=None): | |
"""This function returns the Freshdesk SSO URL. | |
For more info look at https://goo.gl/NISgpr | |
""" | |
utctime = int(time.time()) | |
plaintext = "%s%s%s" % (name, email, utctime) | |
hash = hmac.new(key.encode(), plaintext.encode(), hashlib.md5).hexdigest() | |
url = '%s/login/sso?name=%s&email=%s×tamp=%s&hash=%s' % (base_url, urllib.quote(name), urllib.quote(email), utctime, hash) | |
if redirect_url: | |
url = "%s&redirect_to=%s" % (url, urllib.quote(redirect_url)) | |
if phone: | |
url = "%s&phone=%s" % (url, urllib.quote(phone)) | |
if company: | |
url = "%s&company=%s" % (url, urllib.quote(company)) | |
return url | |
print get_sso_url('[email protected]', 'Ciccio Pasticcio', 'https://support.example.com', '89128932983928912dw23', redirect_url='https://support.example.com/support/tickets') |
FYI, Freshdesk changed things in 2016 after this gist was posted, this code does not currently work. The plaintext needs to have the key added as the 2nd item (please see my fork and update this gist if possible).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for sharing this! really helpful having a reference implementation when Freshdesk gives you a 24 hour notice that they are deprecating the old implementation 👍