AbdoPrDZ / laravel_echo_null

This Package is the improved version of the original package "laravel_echo", with some modifications and features.
MIT License
2 stars 4 forks source link

Pass body in Auth request. #4

Open vthakkar66 opened 11 months ago

vthakkar66 commented 11 months ago

authEndPoint: '****/auth', // String?: auth host authHeaders: { // authenticate headers 'Authorization': 'Bearer ${PreferenceUtils.getString(Constant.ACCESS_TOKEN, '')}', 'Accept': 'application/json', },

I have used your plugin in the flutter and finally i got connected to the socket connection but facing issue while authorization, I need to pass socket_id and channel_name into the auth request.

How can i achieve this using your plugin?

AbdoPrDZ commented 11 months ago

Please include larave-echo-server error log, because there are many reasons for the channel subscribe auth problem

There is an example that works well Make sure to read the README carefully

vthakkar66 commented 11 months ago

I have read the README file. but not able to find where to pass body/parameters like headers in the authorization request.

AbdoPrDZ commented 11 months ago

The task of sending an authentication request to the server is automatically handled by the Laravel-Echo-Server. You only need to include the required parameters, such as the authentication token, if needed.

fabioselau077 commented 9 months ago

Same problema here... Private channel not connecting, broadcasting/auth of Laravel returning 403.

socket_id and channel_name is passed correct in auth? I couldn't verify this inside the package

edit: body is passed, working now image

Korefey commented 7 months ago

I received the same bug. [Pusher Connection Error]: Connection not authorized within timeout.

Echo<PusherClient, PusherChannel> pusherEcho = Echo.pusher( 'test', authEndPoint: 'https://test/api/v1/broadcasting/auth', authHeaders: { 'Authorization': 'Bearer $token', 'Accept': 'application/json', }, cluster: 'eu', host: 'test.com', encrypted: true, enableLogging: true, autoConnect: true, wsPort: 6001, wssPort: 443, );

Saifallak commented 1 month ago

make sure your broadcast auth is configured correctly in laravel app.. for example in my app, I'm using broadcast for web and also for API so I made two auth routes and applied the right middleware

Flutter Side:

Future<void> initService() async {
    try {
      echoService = Echo.pusher(
        'xxxxxxYOUR PUSHER APP KEYxxxxxx',
        authEndPoint: 'https://domain.com/api/broadcasting/auth',
        authHeaders: {
          // authenticate headers
          'Authorization': 'Bearer xxxxxxYOUR AUTH BEARER TOKENxxxxxx',
          'Content-Type': 'application/json',
          'Accept': 'application/json',
        },
        cluster: 'xxxxxxYOUR PUSHER APP CLUSTERxxxxxx',
        host: 'api-xxxxxxYOUR PUSHER APP CLUSTERxxxxxx.pusher.com',
        wsPort: 80,
        wssPort: 443,
        encrypted: true,
        activityTimeout: 120000,
        pongTimeout: 30000,
        maxReconnectionAttempts: 6,
        maxReconnectGapInSeconds: 30,
        enableLogging: true,
        autoConnect: true,
      );

      // private channel
      Channel waMsgCh = echoService.private('xxxxxxYOUR PRIVATE CHANNELxxxxxx');
      waMsgCh.listen('xxxxxxYOUR EVENTxxxxxx', (data) {
        print(data);
        print(data.runtimeType);
      });
    } catch (e, s) {
      FirebaseCrashlytics.instance.recordError(e, s);
    }
  }

Laravel Side:

<?php

namespace App\Providers;

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

class BroadcastServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     */
    public function boot(): void
    {
        Broadcast::routes(['middleware' => ['web', 'auth:web']]);
        Broadcast::routes(['middleware' => ['api', 'auth:api'], 'prefix' => 'api']);

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

also don't forget in channels.php you add the right channel their too.

source: https://stackoverflow.com/a/52271897/8623062