Skip to content

Instantly share code, notes, and snippets.

@jasonhildebrand
Forked from pbertera/freshdesk-sso.py
Last active January 8, 2023 05:45
Show Gist options
  • Save jasonhildebrand/43520463d17bddce4576ab712cc5d857 to your computer and use it in GitHub Desktop.
Save jasonhildebrand/43520463d17bddce4576ab712cc5d857 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.
email - the name of the user you are logging in to freshdesk. Does not need an existing account in freshdesk,
as it will be created on-the-fly if necessary.
name - full name of the user.
base_url - base url of your freshdesk instance, with trailing slash.
key - the secret key from freshdesk SSO settings.
redirect_url - the URL in freshdesk where you want the user to be redirected after login.
For more info look at https://goo.gl/NISgpr
"""
utctime = int(time.time())
plaintext = "%s%s%s%s" % (name, key, 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('[email protected]', '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