Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Multi-tenancy Invalid signature on Private channels #184

Closed
@SolStis86

Description

@SolStis86

When receiving and authentication payload from a private or presence channel, the payload should be in the format key:signature. However, whats actually returned from the auth endpoint is something like this:

{"auth":":ce25a333287f30d67b36e486f6e60b59b0a0e55a7df62d209ad67766ef170ab5"}

Note that only the signature is present, not the key.

From what i can see the auth string is generated in Pusher\Pusher@socket_auth (Ln:735) however it seems that the auth_key isnt being set ready for the response.

Im using a custom AppProvider that retrieves the config on a per tenant basis and the overrides the config for the pusher connection through middleware on every request.

My app provider is as follows:

namespace App\Websockets;


use BeyondCode\LaravelWebSockets\Apps\App;
use BeyondCode\LaravelWebSockets\Apps\AppProvider as AppProviderInterface;
use App\Models\System\Website;
use Illuminate\Support\Facades\Cache;

class AppProvider implements AppProviderInterface
{
    public function all(): array
    {
        return Website::all()
            ->map(function (Website $website) {
                return $this->transformWebsiteToApp($website);
            })
            ->toArray();
    }

    public function findById($appId): ?App
    {
        $website = Website::find($appId);

        if (! $website) {
            return null;
        }

        return $this->transformWebsiteToApp($website);
    }

    public function findByKey(string $appKey): ?App
    {
        $website = Website::where('key', $appKey)->first();

        if (! $website) {
            return null;
        }

        return $this->transformWebsiteToApp($website);
    }

    public function findBySecret(string $appSecret): ?App
    {
        $website = Website::where('secret', $appSecret)->first();

        if (! $website) {
            return null;
        }

        return $this->transformWebsiteToApp($website);
    }

    protected function transformWebsiteToApp(Website $website)
    {
        return (new App($website->id, $website->key, $website->secret))
            ->setName($website->uuid)
            ->enableClientMessages(true)
            ->enableStatistics(false);
    }
}

And the middleware:

namespace App\Http\Middleware;

use Closure;
use Hyn\Tenancy\Environment;

class SetupTenantConfig
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if ($website = app(Environment::class)->tenant()) {
            config([
                'broadcasting.connections.pusher' => [
                    'driver' => 'pusher',
                    'key' => $website->key,
                    'secret' => $website->secret,
                    'app_id' => $website->id,
                    'options' => [
//                        'cluster' => env('PUSHER_APP_CLUSTER'),
                        'encrypted' => true,
                        'host' => '127.0.0.1',
                        'port' => 6001,
                        'scheme' => 'http',
                        'auth_key' => $website->key,
                    ],
                ],
            ]);
        }

        return $next($request);
    }
}

Anyone else ran in to this issue and solved it? Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions