/** * 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)); } }
/** * {@inheritdoc} */ public function join(string $channel, array $data = []) { Assertion::notEmptyKey($data, 'socketId', "Invalid socket id"); Assertion::notEmptyKey($data, 'userId', "Invalid user id"); Assertion::notEmptyKey($data, 'fullName', "Invalid full name"); return $this->pusher->presence_auth($channel, $data['socketId'], $data['userId'], ['id' => $data['userId'], 'name' => utf8_encode($data['fullName'])]); }
<?php require 'Pusher.php'; // you get your own app key, secret and id, by creating an account at pusher.com $pusher = new Pusher(APP_KEY, APP_SECRET, APP_ID); $user_id = rand(1, 4000); $user_info = array('name' => $_GET["your_name"]); echo $pusher->presence_auth($_POST['channel_name'], $_POST['socket_id'], $user_id, $user_info);
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... */ $userId = uniqid('user_'); $userInfo = ['website' => 'http://www.leggetter.co.uk', 'company' => 'Pusher', 'job_title' => 'Head of Developer Relations', 'is_active' => true, 'email' => '*****@*****.**']; $auth = $pusher->presence_auth($channelName, $socketId, $userId, $userInfo); header('Content-Type: application/json'); echo $auth;
<?php require_once 'Config.php'; require_once 'Pusher.php'; /************************************ * Super dumb Pusher auth (;_;) * ************************************/ if (!empty($_COOKIE['chat-username']) && !empty($_COOKIE['chat-email']) && !empty($_POST['channel_name']) && !empty($_POST['socket_id'])) { $pusher = new Pusher(APP_KEY, APP_SECRET, APP_ID); $username = mb_substr(htmlspecialchars($_COOKIE['chat-username']), 0, 30); $email = htmlspecialchars($_COOKIE['chat-email']); $channel_name = $_POST['channel_name']; $socket_id = $_POST['socket_id']; echo $pusher->presence_auth($channel_name, $socket_id, $username, array('username' => $username, 'email' => $email)); } else { die('Invalid request'); }
<?php /* |-------------------------------------------------------------------------- | Application Routes |-------------------------------------------------------------------------- | | Here is where you can register all of the routes for an application. | It's a breeze. Simply tell Laravel the URIs it should respond to | and give it the controller to call when that URI is requested. | */ Route::get('/', function () { return view('index'); }); Route::post('pusher/auth', function (Illuminate\Http\Request $request) { $pusher = new Pusher(config('broadcasting.connections.pusher.key'), config('broadcasting.connections.pusher.secret'), config('broadcasting.connections.pusher.app_id')); return $pusher->presence_auth($request->input('channel_name'), $request->input('socket_id'), uniqid(), ['username' => $request->input('username')]); }); Route::resource('messages', 'Message', ['only' => ['index', 'store']]);
<?php require_once '../../config.class.php'; require_once '../Pusher.php'; require_once '../pusher_defaults.php'; $pusher = new Pusher(Config::pusher_key, Config::pusher_secret, Config::pusher_app_id, true); $channel = isset($_REQUEST['channel_name']) ? $_REQUEST['channel_name'] : $presence_default_channel; $socket_id = $_REQUEST['socket_id']; $user_id = isset($_SESSION['user_id']) ? $_SESSION['user_id'] : time(); $_SESSION['user_id'] = $user_id; $user_name = isset($_REQUEST['user_name']) ? $_REQUEST['user_name'] : 'valued_user'; echo $pusher->presence_auth($channel, $socket_id, $user_id, array('name' => $user_name));
//Autenticar require_once './vendor/autoload.php'; session_start(); include "_db.php"; $con = crearConexion(); if ($con->connect_error) { die("Connection failed: " . $con->connect_error); } $app_id = '163546'; $app_key = '1af1d4c26abef175083a'; $app_secret = 'b06bd7deadbe3c59cd79'; $pusher = new Pusher($app_key, $app_secret, $app_id, array('encrypted' => true)); if (!isset($_POST['sala'], $_POST['password'])) { echo "Ingrese una contraseña por favor"; } else { $sala = $_POST['sala']; $password = $_POST['password'] || ""; $stmt = $con->prepare("SELECT passsala,COUNT(*) as existe FROM salas WHERE nombre = ?"); $stmt->bind_param("s", $sala); $stmt->execute(); $stmt->bind_result($col1, $col2); while ($stmt->fetch()) { if ($col1 == $password || empty($col1) || $col2 < 1) { $data = array('admin' => $_POST['admin']); echo $pusher->presence_auth($_POST['channel_name'], $_POST['socket_id'], $_POST['sala'] . "-" . $_POST['socket_id'], $data); } else { echo "false"; } } $stmt->close(); }
<?php /* ------------ user autentification --------------- /* * Pusher chat * facebook like chat jQuery plugin using Pusher API * version: 1.0 * Author & support : zied.hosni.mail@gmail.com * © 2012 html5-ninja.com * for more info please visit http://html5-ninja.com * */ require_once 'config.php'; // https://github.com/squeeks/Pusher-PHP require_once '../lib/Pusher.php'; $name = $_GET['name']; // chose the way to get this get,post session ...etc $user_id = $_GET['user_id']; // chose the way to get this get,post session ...etc $channel_name = $_POST['channel_name']; // never change $socket_id = $_POST['socket_id']; // never change $pusher = new Pusher($key, $secret, $app_id); $presence_data = array('name' => $name); echo $pusher->presence_auth($channel_name, $socket_id, $user_id, $presence_data);
<?php include "pusher.php"; $pusher = new Pusher("9f2cde4bf9c16af5d034", "bf441c57e38a97b090b1", "90168"); $presence_data = array('username' => "miamiam", 'avatar' => "lolol"); echo $pusher->presence_auth($_POST['channel_name'], $_POST['socket_id'], rand(1, 200), $presence_data);
<?php require_once 'Pusher.php'; // Define constants for the pusher api info define('PUSHER_API_KEY', 'YOUR KEY'); define('PUSHER_API_SECRET', 'YOUR SECRET'); define('PUSHER_APP_ID', 'YOUR APP ID'); // Creating a connection to Pusher $pusher = new Pusher(PUSHER_API_KEY, PUSHER_API_SECRET, PUSHER_APP_ID); $uniqid = uniqid(); $presence_data = array('id' => $uniqid); $auth = $pusher->presence_auth($_GET['channel_name'], $_GET['socket_id'], $uniqid, $presence_data); $callback = str_replace('\\', '', $_GET['callback']); header('Content-Type: application/javascript'); echo $callback . '(' . $auth . ');';
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); }
<?php require_once 'smswall.inc.php'; require 'libs/Pusher.php'; $pusher = new Pusher(PUSHER_KEY, PUSHER_SECRET, PUSHER_APPID); $presence_data = array('name' => 'publicwall'); $uid = uniqid(); echo $pusher->presence_auth($_POST['channel_name'], $_POST['socket_id'], $uid, $presence_data);