georgeboot / laravel-echo-api-gateway

Use Laravel Echo with API Gateway Websockets. Works with Bref.sh and Laravel Vapor.
MIT License
99 stars 23 forks source link

Invalid auth signature #16

Open icreatestuff opened 2 years ago

icreatestuff commented 2 years ago

We're using Laravel Vapor and have followed the installation and setup instructions in the README.md to setup the DynamoDB table, API Gateway and updated IAM role as well as include the 4 .env variables to set the broadcast drive, DB table, Gateway API ID and stage.

Having installed both the composer and NPM packages we've then setup our JS with the following:

import Echo from 'laravel-echo';
import {broadcaster} from 'laravel-echo-api-gateway';

window.Echo.join(`stream.${eventSlug}`)
    .listen('UpdateStreamTitle', e => {
        console.log(e.title);
    })
    .error((error) => {
        console.error(error);
    });

Our BrodcastServiceProvider.php contains

<?php

namespace App\Providers;

use Illuminate\Support\Facades\Broadcast;
use Illuminate\Support\ServiceProvider;

class BroadcastServiceProvider extends ServiceProvider
{
    public function boot()
    {
        Broadcast::routes();

        require base_path('routes/channels.php');
    }
}

and our routes/channels.php has

<?php

use Illuminate\Support\Facades\Broadcast;

Broadcast::channel('stream.{eventSlug}', function ($user, $data) {
    return ['name' => $user->first_name . ' ' . $user->last_name, 'data' => $data];
});

When viewing the developer console we're seeing a few logged messages and then an Invalid auth signature error. The console logs read as:

just set socketId to M-C-kdiQrPECH3A=
Sending auth request for channel presence-stream.my-mega-event
Subscribing to channels presence-stream.my-mega-event
Received event error on channel presence-stream.my-mega-event
{message: 'Invalid auth signature'}

Looking at the Network activity I can see the request to /broadcasting/auth sends the channel_name and socket_id and returns with auth and channel_data.

Inspecting the WebSocket network activity I see a request to our configured wss://{api-ip}.execute-api.{region}.amazonaws.com/{stage} Gateway API (with the variables replaced). This returns with the following data:

{
    connectionId: "M-C-kdiQrPECH3A="
    message: "Internal server error"
    requestId: "M-DasGC8LPEFqGA="
}

For what it's worth we're running:

I'm not sure where things are going wrong so any help would be greatly appreciated. Many thanks.

nandorossetti commented 2 years ago

Have you set the Echo's authEndpoint in your window.Echo params?

icreatestuff commented 2 years ago

@nandorossetti It's using the default /broadcasting/auth at the moment, should it be set to something else when using this package?

nandorossetti commented 2 years ago

Specify explicitly the authEndpoint and test by logging the authEndpoint path in case it happens to be failing.

icreatestuff commented 2 years ago

I was using a Presence Channel and have since simplified things for testing to use a regular Channel. I'm still getting Internal Server Error messages in the websocket responses after a successful connection similar to @nandorossetti issue here .

jdavidbakr commented 2 years ago

I had this happen when connecting from my local machine and my APP_KEY did not match the one deployed.

Adesin-fr commented 2 weeks ago

Do you still experience this issue ?

leob commented 2 weeks ago

@Adesin-fr I've never experienced this one myself :)