4

Using Pusher in conjunction with Echo on the client, I'm attempting to authenticate a private channel via api using Bearer Authorization header token - however I'm met with the following logs (THE LAST LOG BEING THE ERROR):

Pusher : : ["State changed","initialized -> connecting"]

Pusher : : ["Connecting",{"transport":"ws","url":"ws://ws-mt1.pusher.com:80/app/************?protocol=7&client=js&version=7.0.3&flash=false"}]

Pusher : : ["State changed","connecting -> connected with new socket ID 224550.32180982"]

Pusher : : ["No callbacks on private-App.User.17 for pusher:subscription_error"]

Pusher : : ["Error: JSON returned from auth endpoint was invalid, yet status code was 200. Data was: <!doctype html>\n<html class="en" lang="en">\n\t\n\t\t\t<meta charset="utf-...

Seems like my server is just returning the webpage rather than a JSON response.

Here is my Client setup:

Pusher.logToConsole = true

const PusherClient = new Pusher(PUSHER_APP_KEY,{
    cluster: PUSHER_APP_CLUSTER,
    wsHost: `ws-${PUSHER_APP_CLUSTER}.pusher.com`,
    wssPort: 443,
    enabledTransports: ['ws'],
    forceTLS: true,
    encrypted: true,
    auth: {
        headers: {
            'Content-Type': 'application/json',
            'Authorization': `Bearer ${token}`
        }
    },
    authEndpoint: http://127.0.0.1:8000/api/broadcasting/auth'
});

return new Echo({
    broadcaster: 'pusher',
    client: PusherClient
})

Broadcast routes defined in api.php on Laravel server:

Route::group(['middleware' => 'auth:api'], function () {
    Broadcast::routes();
});

enter image description here

What am I missing here?

3
  • can you add a screenshot of the error log completely Commented May 18, 2021 at 2:44
  • Try to match your authentication token you have created to validate user. Commented May 18, 2021 at 8:36
  • Plz would mind take a look at this question: stackoverflow.com/questions/67605266/… Commented May 22, 2021 at 10:56

1 Answer 1

1

First you can setup client side without laravel-echo, just with pusher-js. In the version I'm using there shouldn't be Content-Type header:

    auth: {
        headers: {
            'Authorization': `Bearer CLIENT_TOKEN`,
        }

    },

You must make sure the channel you're subscribing is available and all pusher app parameters and also user's token are inserted correctly.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.