Skip to content

Instantly share code, notes, and snippets.

@pbertera
Last active March 14, 2019 13:05

Revisions

  1. pbertera revised this gist Sep 22, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion freshdesk-sso.py
    Original file line number Diff line number Diff line change
    @@ -19,4 +19,4 @@ def get_sso_url(email, name, base_url, key, redirect_url=None, phone=None, compa
    url = "%s&company=%s" % (url, urllib.quote(company))
    return url

    print get_sso_url('test@myportal.com', 'User Name', 'https://support.example.com', '89128932983928912dw23', redirect_url='https://support.example.com/support/tickets')
    print get_sso_url('test@myportal.com', 'Ciccio Pasticcio', 'https://support.example.com', '89128932983928912dw23', redirect_url='https://support.example.com/support/tickets')
  2. pbertera revised this gist Sep 22, 2015. 1 changed file with 13 additions and 2 deletions.
    15 changes: 13 additions & 2 deletions freshdesk-sso.py
    Original file line number Diff line number Diff line change
    @@ -3,9 +3,20 @@
    import hmac
    import urllib

    def get_sso_url(email, name, base_url, key):
    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)
    return url
    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', 'User Name', 'https://support.example.com', '89128932983928912dw23', redirect_url='https://support.example.com/support/tickets')
  3. pbertera created this gist Sep 22, 2015.
    11 changes: 11 additions & 0 deletions freshdesk-sso.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    import time
    import hashlib
    import hmac
    import urllib

    def get_sso_url(email, name, base_url, key):
    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)
    return url