Skip to content

Instantly share code, notes, and snippets.

@sXakil
Last active June 20, 2022 10:08
Show Gist options
  • Save sXakil/67deae7dcad559c56e69cab816a328f0 to your computer and use it in GitHub Desktop.
Save sXakil/67deae7dcad559c56e69cab816a328f0 to your computer and use it in GitHub Desktop.
Custom Pusher Auth for Private Channel
public function pusherAuth(Request $request) {
if(Auth::check()) {
$channel_name = $request->channel_name;
$socket_id = $request->socket_id;
$id = Auth::user()->id;
$auth_channel = 'private-chat-' . $id;
if($channel_name != $auth_channel) {
return response()->json('Forbidden', 403);
}
$data = $socket_id . ':' . $auth_channel;
$hash = hash_hmac("sha256", $data, env('PUSHER_APP_SECRET'));
$auth = env('PUSHER_APP_KEY') . ':' . $hash;
return response()->json(['auth' => $auth], 200);
} else {
return response()->json('Forbidden', 403);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment