<?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']);
/** * Return the valid authentication response. * * @param \Illuminate\Http\Request $request * @param mixed $result * @return mixed */ public function validAuthenticationResponse($request, $result) { if (Str::startsWith($request->channel_name, 'private')) { return $this->decodePusherResponse($this->pusher->socket_auth($request->channel_name, $request->socket_id)); } else { return $this->decodePusherResponse($this->pusher->presence_auth($request->channel_name, $request->socket_id, $request->user()->id, $result)); } }
<?php // include Pusher PHP library require_once 'lib/Pusher.php'; // Replace with auth information for your app $auth_key = ""; $secret_key = ""; $app_id = ""; // read channel name and socket id from request $channel_name = trim($_REQUEST['channel_name']); $socket_id = trim($_REQUEST['socket_id']); // use Pusher PHP library to generate auth signature and echo as response to client $pusher = new Pusher($auth_key, $secret_key, $app_id); $auth_sig = $pusher->socket_auth($channel_name, $socket_id); echo $auth_sig;
require '../../vendor/autoload.php'; require '../_includes/config.php'; $appId = getenv('PUSHER_APP_ID'); $appKey = getenv('PUSHER_APP_KEY'); $appSecret = getenv('PUSHER_APP_SECRET'); $pusher = new Pusher($appKey, $appSecret, $appId); /* Uncomment this to have internal Pusher PHP library logging information echoed in the response to the incoming request */ // class EchoLogger { // public function log($msg) { // echo($msg); // } // } // // $pusher->set_logger(new EchoLogger()); $channelName = $_POST['channel_name']; $socketId = $_POST['socket_id']; /* TODO: implement checks to determine if the user is: 1. Authenticated with the app 2. Allowed to subscribe to the $channelName 3. Sanitize any additional data that has been recieved and is to be used If so, proceed... */ $auth = $pusher->socket_auth($channelName, $socketId); header('Content-Type: application/json'); echo $auth;
<?php require 'Pusher.php'; $app_id = '142419'; $app_key = '875a535db554ca357be9'; $app_secret = 'd97dd660cfe8f4e8a900'; $pusher = new Pusher($app_key, $app_secret, $app_id); list(, $userId) = explode('.', $_POST['socket_id']); $auth = $pusher->socket_auth($_POST['channel_name'], $userId); //$presence_data = array('user_id' => $userId); $presence_data = array(); echo $pusher->presence_auth($_POST['channel_name'], $_POST['socket_id'], $userId, $presence_data);
/** * @param Request $request * @return string * @throws AuthenticationException */ public function pusherAuth(Request $request) { //Verify the user has permission to connect to the chosen channel if ($request->get('channel_name') !== 'private-' . Auth::id()) { throw new AuthenticationException(); } $pusher = new \Pusher(config('broadcasting.connections.pusher.key'), config('broadcasting.connections.pusher.secret'), config('broadcasting.connections.pusher.app_id')); return $pusher->socket_auth($request->get('channel_name'), $request->get('socket_id')); }
public function __construct() { define('WP_USE_THEMES', false); include_once dirname(dirname(dirname(dirname(__FILE__)))) . '/wp-load.php'; $this->options = get_option('wp_pusher', false); if ($this->options !== false && $this->options['key'] !== '' && $this->options['secret'] !== '' && $this->options['app_id'] !== '') { include_once 'pusher-php-server/lib/Pusher.php'; $pusher = new Pusher($this->options['key'], $this->options['secret'], $this->options['app_id']); echo $pusher->socket_auth($_POST['channel_name'], $_POST['socket_id']); } }
<?php require __DIR__ . '/vendor/autoload.php'; $app_id = '134441'; $app_key = '599cb5ed77cd5efb659a'; $app_secret = '76a57ea82e311bcbbb1f'; error_log('post ' . var_export($_SERVER, true)); $channel_name = $_POST['channel_name']; $socket_id = $_POST['socket_id']; error_log($app_id); error_log($app_key); error_log($app_secret); error_log('channel name: ' . $channel_name); error_log('socket id: ' . $socket_id); $pusher = new Pusher($app_key, $app_secret, $app_id); echo $pusher->socket_auth($channel_name, $socket_id);
public function Process() { $this->cachedir = JPATH_ROOT . "/cache/" . get_class($this); file_exists($this->cachedir) or mkdir($this->cachedir); //$this->CacheLifetime = intval($this->Params->get("cache_lifetime", 2)) * 60; // Converte da minuti in secondi $this->CacheLifetime = 2 * 60; // Converte da minuti in secondi 2 minuti $tw_consumer_key = trim($this->Params->get("twitter_consumer_key", "")); $tw_consumer_secret = trim($this->Params->get("twitter_consumer_secret", "")); $app_id = trim($this->Params->get("pusher_app_id", "")); $app_key = trim($this->Params->get("pusher_app_key", "")); $app_secret = trim($this->Params->get("pusher_app_secret", "")); /* if (isset($_POST['channel_name']) && isset($_POST['socket_id']) && isset($_POST['only_get_num']) && $_POST['only_get_num']){ $verify_channel=$_POST['channel_name'];//private- presence- $verify_socketid=$_POST['socket_id']; $parts=explode('-',$verify_channel); $channel_type=$parts[0]; if ($channel_type == 'presence'){ $pusher = new Pusher($app_key, $app_secret, $app_id); $presence_data = array( 'displayName' => 'hidden', 'objectType' => 'person', 'image' => array('url'=>''), 'userid'=>'hidden-hidden', 'link'=>'' ); echo $pusher->presence_auth($verify_channel, $verify_socketid, $presence_data['userid'], $presence_data); JFactory::getApplication()->close(); } } */ if (isset($_POST['only_get_num']) && $_POST['only_get_num']) { if (!isset($_POST['channel_name'])) { $this->returnError("Invalid channel"); } $verify_channel = $_POST['channel_name']; //private- presence- $parts = explode('-', $verify_channel); $channel_type = $parts[0]; if ($channel_type == 'presence') { //Caching! QUi $cache_expired = true; $num_users_connected = 0; $cachefile = $this->cachedir . "/" . $this->getHash(array($app_key, $verify_channel), array($app_secret, $app_id)); if (file_exists($cachefile)) { $age = time() - filemtime($cachefile); $lt = $this->CacheLifetime; if ($age < $lt) { $num_users_connected = file_get_contents($cachefile); $cache_expired = false; } } if ($cache_expired) { $pusher = new Pusher($app_key, $app_secret, $app_id); //echo json_encode($pusher->get('/channels/'.$verify_channel.'/members')); $users = $pusher->get('/channels/' . $verify_channel . '/users'); $users = json_decode($users['body'], true); $num_users_connected = count($users['users']); file_put_contents($cachefile, $num_users_connected); } //error_log(var_export($users,true)."\n",3,'C:\workspace\php-errors.log'); echo json_encode(array('c' => $num_users_connected)); JFactory::getApplication()->close(); } else { $this->returnError("Invalid channel"); } } $anonymous_login = intval($this->Params->get("anonymous_login", "1")) == 1; $joomla_login = intval($this->Params->get("joomla_login", "1")) == 1; $facebook_login = false; $googleplus_login = false; $twitter_login = false; $fb_app_id = trim($this->Params->get("facebook_app_id", "")); $fb_app_secret = trim($this->Params->get("facebook_app_secret", "")); if (!empty($fb_app_id) && !empty($fb_app_secret)) { $facebook_login = true; } $gp_client_id = trim($this->Params->get("googleplus_client_id", "")); $gp_client_secret = trim($this->Params->get("googleplus_client_secret", "")); if (!empty($gp_client_id) && !empty($gp_client_secret)) { $googleplus_login = true; } if (!empty($tw_consumer_key) && !empty($tw_consumer_secret)) { $twitter_login = true; } $available_logins = array(); if ($anonymous_login) { $available_logins[] = 'anonymous'; } if ($joomla_login) { $available_logins[] = 'joomla'; } if ($facebook_login) { $available_logins[] = 'facebook'; } if ($googleplus_login) { $available_logins[] = 'googleplus'; } if ($twitter_login) { $available_logins[] = 'twitter'; } if ($twitter_login && isset($_REQUEST['tw_verify'])) { $this->twitter_verify_and_die($tw_consumer_key, $tw_consumer_secret); } if ($twitter_login && isset($_POST['tw_get'])) { $this->twitter_get_and_die($tw_consumer_key, $tw_consumer_secret); } if (isset($_POST['tw_get_status'])) { $this->twitterLogin(true); if ($this->logged_in) { header('Cache-Control: no-cache, must-revalidate'); header('Content-type: application/json'); echo json_encode($this->actor); JFactory::getApplication()->close(); die; } else { $this->returnError("Not logged in"); } } $this->logged_in = false; $this->actor = array(); $session = JFactory::getSession(); if (isset($_POST['logout'])) { $session_var_name = 'oc_user_id_' . $_POST['logout']; if ($session->has($session_var_name)) { $session->clear($session_var_name); } if ($_POST['logout'] == 'twitter' && $session->has("oc_twitter_oauth_access_token_response")) { $session->clear("oc_twitter_oauth_access_token_response"); } JFactory::getApplication()->close(); return; } $oc_logged_in = ''; if (!empty($_COOKIE['oc_logged_in'])) { $oc_logged_in = $_COOKIE['oc_logged_in']; } if (!empty($_POST['loginonly'])) { $oc_logged_in = $_POST['loginonly']; } if (!empty($oc_logged_in) && in_array($oc_logged_in, $available_logins)) { $session_var_name = 'oc_user_id_' . $oc_logged_in; if (isset($_COOKIE[$session_var_name]) && $session->has($session_var_name)) { $actor = $session->get($session_var_name); if ($actor['userid'] == $_COOKIE[$session_var_name]) { $this->logged_in = true; $this->actor = $actor; } } if (!$this->logged_in) { if ($oc_logged_in == 'googleplus') { $this->googleplusLogin(); } else { if ($oc_logged_in == 'facebook') { $this->facebookLogin(); } else { if ($oc_logged_in == 'joomla') { $this->joomlaLogin(); } else { if ($oc_logged_in == 'twitter') { $this->twitterLogin(); } else { if ($oc_logged_in == 'anonymous') { $this->anonymousLogin($_COOKIE['oc_anon_name'], $_COOKIE['oc_anon_email']); } } } } } if ($this->logged_in) { $session->set($session_var_name, $this->actor); } } } if (isset($_POST['loginonly'])) { if ($this->logged_in) { header('Cache-Control: no-cache, must-revalidate'); header('Content-type: application/json'); echo json_encode(array('OK')); //die(); JFactory::getApplication()->close(); return; } else { $this->returnError("Not logged in"); } } if (isset($_POST['channel_name']) && isset($_POST['socket_id'])) { //authendpoint private or presence $verify_channel = $_POST['channel_name']; //private- presence- $verify_socketid = $_POST['socket_id']; $parts = explode('-', $verify_channel); $channel_type = $parts[0]; if (!in_array($channel_type, array('private', 'presence'))) { $this->returnError('invalid private or presence channel'); } if ($this->logged_in) { $pusher = new Pusher($app_key, $app_secret, $app_id); $presence_data = $this->actor; if ($channel_type == 'presence') { echo $pusher->presence_auth($verify_channel, $verify_socketid, $this->actor['userid'], $presence_data); } else { echo $pusher->socket_auth($verify_channel, $verify_socketid); } JFactory::getApplication()->close(); } else { $this->returnError("Forbidden"); } return; } if (isset($_POST['chat_info'])) { //send message $channel_name = "private-" . $this->get_channel_name($this->Params->get("pusher_channel_name", "channel1")); $result = array(); //'activity' => $data, 'pusherResponse' => $response); //if (isset($_POST['chat_info']['logout']) && isset($_POST['chat_info']['logout']['logout_from'])){ //non devo fare nulla // $this->logged_in=false; //} if ($this->logged_in && isset($_POST['chat_info']['text']) && !empty($_POST['chat_info']['text'])) { //creo il messaggio date_default_timezone_set('UTC'); $data = array('id' => uniqid(), 'body' => mb_substr($_POST['chat_info']['text'], 0, 300), 'published' => date('r'), 'type' => 'chat-message', 'actor' => $this->actor); $data['actor']['displayName'] = mb_substr($data['actor']['displayName'], 0, 30); //invio del messaggio $pusher = new Pusher($app_key, $app_secret, $app_id); $response = $pusher->trigger($channel_name, 'chat_message', $data); $result = array('activity' => $data, 'pusherResponse' => $response); } //output result header('Cache-Control: no-cache, must-revalidate'); header('Content-type: application/json'); echo json_encode($result); //die(); JFactory::getApplication()->close(); return; } //se arrivo qui non è ne una presence ne una send $this->returnError('invalid data', 400); }