devgianlu / go-librespot

Yet another open source Spotify client, written in Go.
GNU General Public License v3.0
70 stars 14 forks source link

Websocket not authorised for host #92

Closed Willyarma closed 1 day ago

Willyarma commented 6 days ago

I'm getting this message:

time="2024-09-11T10:43:47+01:00" level=error msg="failed accepting websocket connection" error="failed to accept WebSocket connection: request Origin \"http://192.168.5.49:8888\" is not authorized for Host \"192.168.5.49:3678\""

Am I doing something wrong?

config.yml: device_name: go-librespot credentials: type: zeroconf server: enabled: true port: 3678

Willyarma commented 6 days ago

I added allow_origin: "http://192.168.5.49:8888" to the config.yml and it only affects the get and post part of the API it does not affect the websocket. Putting "*" dosent work either for websockets but does for get/post.

Willyarma commented 6 days ago

I hacked it for the time being just to get it going...

m.HandleFunc("/events", func(w http.ResponseWriter, r *http.Request) {
    opts := &websocket.AcceptOptions{}
    if len(s.allowOrigin) > 0 {
        //opts.OriginPatterns = []string{s.allowOrigin}
    }
    opts.InsecureSkipVerify = true

obviously this isnt the right way

devgianlu commented 2 days ago

@Willyarma Can you test again with the latest changes?

Willyarma commented 2 days ago

I'm using a node.js wrapper that I wrote with a minimal web interface, the HTTP server of it is on port 8888.

Without specifying allow_origin in config.yml, get/post gives cors errors in the firefox web console, the websocket won't connect.

allow_origin: "*" works for both get/post and websockets allow_origin: "http://192.168.5.49:8888" also works allow_origin: "192.168.5.49:8888" only works for websockets

Would it be worth mentioning requiring allow_origin in the main readme?

Thanks for fixing it so quickly.

devgianlu commented 1 day ago

Added to the README for clarity. Thank you for reporting!