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;
    }