Pusher::socket_auth PHP Method

socket_auth() public method

Creates a socket signature.
public socket_auth ( $channel, string $socket_id, string $custom_data = null ) : string
$socket_id string
$custom_data string
return string
    public function socket_auth($channel, $socket_id, $custom_data = null)
    {
        $this->validate_channel($channel);
        $this->validate_socket_id($socket_id);
        if ($custom_data) {
            $signature = hash_hmac('sha256', $socket_id . ':' . $channel . ':' . $custom_data, $this->settings['secret'], false);
        } else {
            $signature = hash_hmac('sha256', $socket_id . ':' . $channel, $this->settings['secret'], false);
        }
        $signature = array('auth' => $this->settings['auth_key'] . ':' . $signature);
        // add the custom data if it has been supplied
        if ($custom_data) {
            $signature['channel_data'] = $custom_data;
        }
        return json_encode($signature);
    }

Usage Example

Ejemplo n.º 1
5
<?php

use app\config\Config;
// Initialize the app
require_once '../../app/init.php';
// Include the pusher library
require_once '../../lib/pusher/Pusher.php';
// Gather the pusher key, secret and application ID
$authKey = Config::getValue('pusher', 'auth_key', '');
$secret = Config::getValue('pusher', 'secret', '');
$appId = Config::getValue('pusher', 'app_id', '0');
// Create a pusher instance with the proper key, secret and application ID
$pusher = new Pusher($authKey, $secret, $appId);
// Authenticate the request
echo $pusher->socket_auth($_POST['channel_name'], $_POST['socket_id']);
All Usage Examples Of Pusher::socket_auth