mclintprojects / actioncable-vue

A Vue plugin that makes integrating Rails Action Cable dead-easy.
MIT License
182 stars 38 forks source link

Send Headers on Connection #73

Open rafaeliga opened 1 year ago

rafaeliga commented 1 year ago

Hello there,

When connecting my flutter app to rails, Im sending headers to authorize:

cable = ActionCable.Connect(constants.socketHost, headers: {
        "Authorization": constants.socketToken,
      }, onConnected: () {

Is there a way to do the same with actioncable-vue?

Thanks,

rafaeliga commented 1 year ago

Any ideas?

Makes sense if I create this issue on rails/actioncable?

jakob-lilliemarck commented 2 months ago

I've run into the same issue. Passing authentication tokens in the url as the docs propose is widely insecure and bad practice. Apparently passing headers on the initial http upgrade request is unsupported in browsers: https://stackoverflow.com/questions/4361173/http-headers-in-websockets-client-api

I guess the next best option is to send the token over the websocket channel after connection, and then start streaming the data that requires auth.