Skip to content

Instantly share code, notes, and snippets.

@pbertera
Last active March 14, 2019 13:05
Show Gist options
  • Save pbertera/a788324b2235a0ff447e to your computer and use it in GitHub Desktop.
Save pbertera/a788324b2235a0ff447e to your computer and use it in GitHub Desktop.
Freshdesk Single sign-on in Python
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&timestamp=%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('test@myportal.com', 'Ciccio Pasticcio', 'https://support.example.com', '89128932983928912dw23', redirect_url='https://support.example.com/support/tickets')
@danriti
Copy link

danriti commented Apr 27, 2016

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 👍

@jasonhildebrand
Copy link

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