Skip to content

Instantly share code, notes, and snippets.

@thanashyam
Last active September 19, 2025 16:17
Show Gist options
  • Select an option

  • Save thanashyam/1662527 to your computer and use it in GitHub Desktop.

Select an option

Save thanashyam/1662527 to your computer and use it in GitHub Desktop.
SSO Login for Freshdesk support portal - PHP Sample Code (Updated)
<?php
define('FRESHDESK_SHARED_SECRET','____Place your Single Sign On Shared Secret here_____');
define('FRESHDESK_BASE_URL','http://{{your-account}}.freshdesk.com/'); //With Trailing slashes
function getSSOUrl($strName, $strEmail) {
$timestamp = time();
$to_be_hashed = $strName . FRESHDESK_SHARED_SECRET . $strEmail . $timestamp;
$hash = hash_hmac('md5', $to_be_hashed, FRESHDESK_SHARED_SECRET);
return FRESHDESK_BASE_URL."login/sso/?name=".urlencode($strName)."&email=".urlencode($strEmail)."&timestamp=".$timestamp."&hash=".$hash;
}
header("Location: ".getSSOUrl("User's Name","username@thecompany.com"));
// This is not deprecated by Freshdesk. Simple SSO is not supported
@jonmc99

jonmc99 commented Apr 29, 2016

Copy link
Copy Markdown

Thanks for the feedback. That change matches what Freshdesk support also said.

I've updated my code and all tested to be working fine. Thanks for your assistance.

Oddly, my very original code (your original revision) also still works!

@abhinavgarg33

Copy link
Copy Markdown

I am using this code but unable to login to freshdesk. Can someone help me. Thanks in advance.

function getSSOUrl($strName, $strEmail) {
$time = time();
return FRESHDESK_BASE_URL.
"login/sso/?name=".
urlencode($strName).
"&email=".
urlencode($strEmail).
"&timestamp=".
$time.
"&hash=".
getHash($strName,$strEmail,$time);
}

function getHash($strName, $strEmail, $time) {

$to_be_hashed = $strName . FRESHDESK_SHARED_SECRET . $strEmail . $time;
return hash_hmac('md5', $to_be_hashed, FRESHDESK_SHARED_SECRET);

}

@AbhiX28

AbhiX28 commented Jul 16, 2016

Copy link
Copy Markdown

I am facing a unique problem with this, the code works with email that do not consists of dot (.) before the @ sign.
If the email has a dot (.) e.g. firstname.lastname@gmail.com then the login does not work .
I think it could be because of the urlencode but not sure.
Any inputs/ suggestions???

Thanks

@abheist

abheist commented Aug 8, 2016

Copy link
Copy Markdown

@gdelacc

gdelacc commented Feb 4, 2017

Copy link
Copy Markdown

Its works

@AlLoud

AlLoud commented Sep 4, 2018

Copy link
Copy Markdown

An easier to read code with the help of PHP's http_build_query:

http_build_query([
  'name' => $strName,
  'email' => $strEmail,
  'timestamp' => $timestamp,
  'hash' => hash_hmac('md5', $str_to_be_hashed, FRESHDESK_SHARED_SECRET),
], '', '&amp;');

The whole code is in this fork:
https://gist.github.com/AlLoud/cfdea1aac2d158f288deaa71ed186037

@exwyezed

exwyezed commented Jan 7, 2019

Copy link
Copy Markdown

How do you guys handle a user's email address change scenario?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment