src/Pdefreitas/VanillaSSO/VanillaSSO.php
public static function WriteJsConnect($User, $Request, $Secure = TRUE)
    {
        $User = array_change_key_case($User);
        $ClientID = Config::get("vanillasso.client_id");
        $Secret = Config::get("vanillasso.secret");

        // Error checking.
        if ($Secure) {
            // Check the client.
            if (!isset($Request['client_id']))
                $Error = array('error' => 'invalid_request', 'message' => 'The client_id parameter is missing.');
            elseif ($Request['client_id'] != $ClientID)
                $Error = array('error' => 'invalid_client', 'message' => "Unknown client {$Request['client_id']}.");
            elseif (!isset($Request['timestamp']) && !isset($Request['signature'])) {
                if (is_array($User) && count($User) > 0) {
                    // This isn't really an error, but we are just going to return public information when no signature is sent.
                    $Error = array('name' => $User['name'], 'photourl' => @$User['photourl']);
                } else {
                    $Error = array('name' => '', 'photourl' => '');
                }
            } elseif (!isset($Request['timestamp']) || !is_numeric($Request['timestamp']))
                $Error = array('error' => 'invalid_request', 'message' => 'The timestamp parameter is missing or invalid.');
            elseif (!isset($Request['signature']))
                $Error = array('error' => 'invalid_request', 'message' => 'Missing  signature parameter.');
            elseif (($Diff = abs($Request['timestamp'] - self::JsTimestamp())) > JS_TIMEOUT)
                $Error = array('error' => 'invalid_request', 'message' => 'The timestamp is invalid.');
            else {
                // Make sure the timestamp hasn't timed out.
                $Signature = self::JsHash($Request['timestamp'] . $Secret, $Secure);
                if ($Signature != $Request['signature'])
                    $Error = array('error' => 'access_denied', 'message' => 'Signature invalid.');
            }
        }

        if (isset($Error))
            $Result = $Error;
        elseif (is_array($User) && count($User) > 0) {
            if ($Secure === NULL) {
                $Result = $User;
            } else {
                $Result = self::SignJsConnect($User, $ClientID, $Secret, $Secure, TRUE);
            }
        } else
            $Result = array('name' => '', 'photourl' => '');

        $Json = json_encode($Result);

        if (isset($Request['callback']))
            return "{$Request['callback']}($Json)";
        else
            return $Json;
    }
public static function WriteJsConnect($User, $Request, $Secure = TRUE)
    {
        $User = array_change_key_case($User);
        $ClientID = Config::get("vanillasso.client_id");
        $Secret = Config::get("vanillasso.secret");

        // Error checking.
        if ($Secure) {
            // Check the client.
            if (!isset($Request['client_id']))
                $Error = array('error' => 'invalid_request', 'message' => 'The client_id parameter is missing.');
            elseif ($Request['client_id'] != $ClientID)
                $Error = array('error' => 'invalid_client', 'message' => "Unknown client {$Request['client_id']}.");
            elseif (!isset($Request['timestamp']) && !isset($Request['signature'])) {
                if (is_array($User) && count($User) > 0) {
                    // This isn't really an error, but we are just going to return public information when no signature is sent.
                    $Error = array('name' => $User['name'], 'photourl' => @$User['photourl']);
                } else {
                    $Error = array('name' => '', 'photourl' => '');
                }
            } elseif (!isset($Request['timestamp']) || !is_numeric($Request['timestamp']))
                $Error = array('error' => 'invalid_request', 'message' => 'The timestamp parameter is missing or invalid.');
            elseif (!isset($Request['signature']))
                $Error = array('error' => 'invalid_request', 'message' => 'Missing  signature parameter.');
            elseif (($Diff = abs($Request['timestamp'] - self::JsTimestamp())) > JS_TIMEOUT)
                $Error = array('error' => 'invalid_request', 'message' => 'The timestamp is invalid.');
            else {
                // Make sure the timestamp hasn't timed out.
                $Signature = self::JsHash($Request['timestamp'] . $Secret, $Secure);
                if ($Signature != $Request['signature'])
                    $Error = array('error' => 'access_denied', 'message' => 'Signature invalid.');
            }
        }

        if (isset($Error))
            $Result = $Error;
        elseif (is_array($User) && count($User) > 0) {
            if ($Secure === NULL) {
                $Result = $User;
            } else {
                $Result = self::SignJsConnect($User, $ClientID, $Secret, $Secure, TRUE);
            }
        } else
            $Result = array('name' => '', 'photourl' => '');

        $Json = json_encode($Result);

        if (isset($Request['callback']))
            return "{$Request['callback']}($Json)";
        else
            return $Json;
    }
public static function WriteJsConnect ( $ User , $ Request , $ Secure = TRUE ) { $ User = array_change_key_case ( $ User ) ; $ ClientID = Config :: get ( "vanillasso.client_id" ) ; $ Secret = Config :: get ( "vanillasso.secret" ) ; // Error checking. if ( $ Secure ) { // Check the client. if ( ! isset ( $ Request [ 'client_id' ] ) ) $ Error = array ( 'error' => 'invalid_request' , 'message' => 'The client_id parameter is missing.' ) ; elseif ( $ Request [ 'client_id' ] != $ ClientID ) $ Error = array ( 'error' => 'invalid_client' , 'message' => "Unknown client {$Request['client_id']}." ) ; elseif ( ! isset ( $ Request [ 'timestamp' ] ) && ! isset ( $ Request [ 'signature' ] ) ) { if ( is_array ( $ User ) && count ( $ User ) > 0 ) { // This isn't really an error, but we are just going to return public information when no signature is sent. $ Error = array ( 'name' => $ User [ 'name' ] , 'photourl' => @ $ User [ 'photourl' ] ) ; } else { $ Error = array ( 'name' => '' , 'photourl' => '' ) ; } } elseif ( ! isset ( $ Request [ 'timestamp' ] ) || ! is_numeric ( $ Request [ 'timestamp' ] ) ) $ Error = array ( 'error' => 'invalid_request' , 'message' => 'The timestamp parameter is missing or invalid.' ) ; elseif ( ! isset ( $ Request [ 'signature' ] ) ) $ Error = array ( 'error' => 'invalid_request' , 'message' => 'Missing  signature parameter.' ) ; elseif ( ( $ Diff = abs ( $ Request [ 'timestamp' ] - self :: JsTimestamp ( ) ) ) > JS_TIMEOUT ) $ Error = array ( 'error' => 'invalid_request' , 'message' => 'The timestamp is invalid.' ) ; else { // Make sure the timestamp hasn't timed out. $ Signature = self :: JsHash ( $ Request [ 'timestamp' ] . $ Secret , $ Secure ) ; if ( $ Signature != $ Request [ 'signature' ] ) $ Error = array ( 'error' => 'access_denied' , 'message' => 'Signature invalid.' ) ; } } if ( isset ( $ Error ) ) $ Result = $ Error ; elseif ( is_array ( $ User ) && count ( $ User ) > 0 ) { if ( $ Secure === NULL ) { $ Result = $ User ; } else { $ Result = self :: SignJsConnect ( $ User , $ ClientID , $ Secret , $ Secure , TRUE ) ; } } else $ Result = array ( 'name' => '' , 'photourl' => '' ) ; $ Json = json_encode ( $ Result ) ; if ( isset ( $ Request [ 'callback' ] ) ) return "{$Request['callback']}($Json)" ; else return $ Json ; }
Write the jsConnect string for single sign on.
@param array $User An array containing information about the currently signed on user. If no user is signed in then this should be an empty array.
@param array $Request An array of the $_GET request.
@param string|bool $Secure Whether or not to check for security. This is one of these values.
- true: Check for security and sign the response with an md5 hash.
- false: Don't check for security, but sign the response with an md5 hash.
- string: Check for security and sign the response with the given hash algorithm. See hash_algos() for what your server can support.
- null: Don't check for security and don't sign the response.
@since 1.1b Added the ability to provide a hash algorithm to $Secure.
@return string JSON response formatted.
Write the jsConnect string for single sign on .