Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong request body: Form Data instead of JSON - private channels #57

Open
robertkabat opened this issue Jun 16, 2021 · 2 comments
Open

Comments

@robertkabat
Copy link

robertkabat commented Jun 16, 2021

Hey,

I am working on a little app where I am using NuxtJS with the laravel echo package for the frontend and Laravel8 with the LaravelWebsockets package for the backend. I am trying to make it work with private channels and passport in Laravel.

I've noticed something really strange that I can't really change or I don't know how to do that.

It looks like Laravel Echo package is making the request with FORM data instead of JSON body which I need and I have no clue if and how I could change it.

When I am trying to subscribe to a private channel(pusher as a broadcaster) echo makes a request to brodcasting/auth endpoint which is fine. However, the data in that request is sent as form data and not as JSON body.

I've made a little plugin in nuxtjs to add headers and stuff so I tried it like this:

export default function ({ $echo, $auth}) {
  console.log($echo)

  let authData = {
    headers: {
      // Authorization: 'Bearer 1c2d3a31dd0c5e1933c609ffce1ef4e3'
      Authorization: $auth.strategy.token.get(),
      // Accept: 'application/json',
      "X-Requested-With": 'XMLHttpRequest',
      "Content-Type": 'application/json'
    },
  };

  $echo.connector.pusher.config.auth = authData;
  $echo.connector._defaultOptions.auth = authData;
  $echo.connector.options.auth = authData;
  $echo.options.auth = authData;
  // $echo.options.auth = authData;
}

My headers are added (although it seems like it is hardcoded in echo package to add application/x-www-form-urlencoded header).

As a result in my Laravel I am getting 403 error and when I traced the code back to where it breaks the data from request is missing. It is because Laravel at this points expects JSON body and it is not there.

My question is - can I somehow make Echo to send the application/json body? Maybe I am misunderstanding the whole thing?

Is there some other way to make this package for Nuxt to work nicely with passport?

@devzom
Copy link

devzom commented Aug 31, 2021

Dealing with the same problem atm. ;(

@Jasperscheper
Copy link

Did you manage to get this working?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants