PHP-Open-Source-Saver / jwt-auth

🔐 JSON Web Token Authentication for Laravel & Lumen
MIT License
729 stars 113 forks source link

Cannot authenticate to my reverb server #242

Closed hgoncalves closed 8 months ago

hgoncalves commented 8 months ago

Laravel Reverb authentication

Cannot authenticate to my reverb server

import { useAuth } from './useAuth';

export function useEcho() {
    const { token } = useAuth();

    window.Pusher = Pusher;

    window.Echo = new Echo({
        broadcaster: 'reverb',
        key: import.meta.env.VITE_REVERB_APP_KEY as string,
        wsHost: import.meta.env.VITE_REVERB_HOST as string,
        wsPort: parseInt(import.meta.env.VITE_REVERB_PORT as string, 10),
        wssPort: parseInt(import.meta.env.VITE_REVERB_PORT as string, 10),
        forceTLS: (import.meta.env.VITE_REVERB_SCHEME ?? 'https') === 'https',
        enabledTransports: ['ws', 'wss'],
        authEndpoint: 'http://localhost:8000/broadcasting/auth',
        auth: {
            headers: {
                Authorization: `Bearer ${token.value}`,
            },
        },
        withCredentials: true,
    });

    function subscribeToPrivateChannel(
        channelName: string,
        eventName: string,
        callback: (data: any) => void,
    ) {
        window.Echo.private(channelName).listen(eventName, callback);
    }

    function leaveChannel(channelName: string) {
        window.Echo.leave(channelName);
    }

    return {
        subscribeToPrivateChannel,
        leaveChannel,
    };
}

The token is indeed passed properly

Your environment:

Q A
Bug? yes
New Feature? no
Framework Laravel
Framework version 11
Package version 2.2.2
PHP version 8.2

Steps to reproduce

try to connect to reverb server

Expected behaviour

200

Actual behaviour

403

mfn commented 8 months ago

This is not enough to help, all information provided is external to jwt-auth. You need to do some digging on the server side and pinpoint and then check back with the capabilities of this lib, check readme, etc.

hgoncalves commented 8 months ago

I'm on it