PHP exampleΒΆ

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
    //Suppose you have already asked user to authenticate himself through a login form
    //The following is the action part of the login form

    //CHANGE THEM:
    $secret = "YOUR_SHARED_SECRET";
    $username = "USER_NAME";
    $email = "USER_EMAIL";
    $site = "YOUR_SITE_NAME";
    $displayName = "USERS_FULL_NAME"; //optional
    $phone = "USERS_PHONE"; //optional
    $organization = "ORGANIZATION";	 //optional
    //END OF CHANGE THEM

    $redirectURL = "http://www.ihelpdesk.com/desktop/SsoServlet.hd?c=".$site."&";

    $hash = sha1($secret."@@".$username."@@".$email);
    $parameters = "username=$username&email=$email";

    /* optional parameters */
    $parameters .="&displayName=$displayName&phone=$phone&organization=$organization";
    $parameters = base64_encode($parameters);

    //If $usePostSubmit is true, then parameters will be submitted thru HTTP POST
    $usePostSubmit = true;

    if(! $usePostSubmit)
    {
        $redirectURL .= "parameters=$parameters&hash=$hash";
        Header("Location:$redirectURL");
    }
    else
    {
        $form = '<html><head><title>SSO Redirect</title></head><body>';
        $form .= '<form id="ssoRedirectForm" name="ssoRedirectForm" method="POST" action="'.$redirectURL.'">';
        $form .= '<input type="hidden" name="parameters" value="'.$parameters.'">';
        $form .= '<input type="hidden" name="hash" value="'.$hash.'">';
        $form .= '</form><script type="text/javascript">document.ssoRedirectForm.submit();</script></body></html>';
        echo $form;
    }
?>