Skip to content

Instantly share code, notes, and snippets.

@cassolmc
Forked from pbertera/freshdesk-sso.py
Created March 14, 2019 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cassolmc/829427fe3e08df18d72ca5d59e309c5a to your computer and use it in GitHub Desktop.
Save cassolmc/829427fe3e08df18d72ca5d59e309c5a 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')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment