From c3fe66b5e9e1c0be08a8626a5a26f73b36dc3aea Mon Sep 17 00:00:00 2001 From: Pietro Bertera Date: Wed, 27 Apr 2016 17:31:50 +0200 Subject: [PATCH] Added the get_sso_link.py file --- Python/get_sso_link.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Python/get_sso_link.py diff --git a/Python/get_sso_link.py b/Python/get_sso_link.py new file mode 100644 index 0000000..b59fb62 --- /dev/null +++ b/Python/get_sso_link.py @@ -0,0 +1,22 @@ +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%s" % (name, key, 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('test@myportal.com', 'Ciccio Pasticcio', 'https://support.example.com', '89128932983928912dw23', redirect_url='https://support.example.com/support/tickets')