Last active
June 20, 2022 10:08
-
-
Save sXakil/67deae7dcad559c56e69cab816a328f0 to your computer and use it in GitHub Desktop.
Custom Pusher Auth for Private Channel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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