0

個々のユーザーがプライベートチャネルに接続できるようにする php/javascript アプリケーションを構築しています (private-channel.userID など)。

ユーザーは、次の認証エンドポイントを通じて認証されます。以下のコードを参照してください。

ただし、ユーザーが認証されると、他のプライベート チャネルにサブスクライブしてメッセージを送受信できるようになります。

たとえば、userID 100 が private-channel.100 に登録する必要があるとします。エンドポイントを介して認証された後、private-channel.200 またはその他の private-channel.userID にメッセージを送信することもできます!!!

とにかく、ユーザー 100 が private-channel.100 に対してのみ認証できるようにし、他の private-channel にサブスクライブできないようにする

認証エンドポイントに何か問題があると思いますが、何が原因かわかりませんでした。

どうもありがとう!

public function pusherAuth(Request $request){
    $pusher = new Pusher(
        config('broadcasting.connections.pusher.key'),
        config('broadcasting.connections.pusher.secret'),
        config('broadcasting.connections.pusher.app_id'),
        config('broadcasting.connections.pusher.options')
    );
    $request->headers->set('Accept', 'application/json');
    // return $pusher->socket_auth($request->channel_name, $request->socket_id);
    //$channel = $request->channel_name;response()->json(
    // $request->headers->set('Accept', 'application/json');
    $auth = $pusher->socket_auth($request->channel_name, $request->socket_id);
    $jsn = json_decode($auth,true);
    // return response($auth)->header('Content-Type',"application/json");
    return response()->json($jsn);
    // re\turn ['auth' => $jsn->auth];
}

PHP クライアント コード:

connectToPusher() {
    this.pusher = new Pusher(window.Config.pusherKey, {
        authEndpoint: '/broadcasting/auth',
        cluster: window.Config.pusherCluster,
        auth: {
            headers: {
                'X-CSRF-Token': window.Config.csrfToken
            }
        }
    });
4

1 に答える 1