Salim Fadhley
Salim Fadhley

Reputation: 8225

Send credentials with angular-websocket?

I'm using Angular-Websocket to make a web-based application which will run within a corporate network (i.e. never exposed to the public).

Normally when I use $https I use the 'withCredentials': true option so that credentials are sent with any REST queries.

I would like to do the same thing for my web-socket connections. Failure to do this gives me an error message with each connection:

WebSocket connection to 'ws://hostname.bigcompany.com:8090/event-service/?user=salimfadhley' failed: HTTP Authentication failed; no valid credentials available

This is how I currently connect to the websocket (warning, Coffeescript):

  getWebSocket: (url)->
    ws = $websocket(url)
    ws.onMessage(@eventHandler)
    ws

So what can I do? The obvious solution is to just connect in such a way that we do provide credentials. Alternatively, I could use some other websocket client? Any suggestions?

Upvotes: 0

Views: 1084

Answers (1)

vtortola
vtortola

Reputation: 35945

WebSockets are not affected by the Same Origin Policy, so it should send any cookies that are valid for the domain you are connecting to by default.

This is not related with the AngularJS component, this is the browser itself.

Upvotes: 1

Related Questions