go - Gorilla websocket with cookie authentication -
here's setup: i'm building service (using negroni , gorilla) user login, upon login, user gets session cookie server uses authorize protected endpoints. 1 of protected endpoints allows user/client open websocket server, so:
app := negroni.new() r := mux.newrouter() r.handlefunc("/auth/connection", func(rw http.responsewriter, req *http.request) { // authorize request using req.cookie("session_id") // create websocket conn, err := upgrader.upgrade(rw, req, nil) if err != nil { panic(err) } defer conn.close() // stuff... }) app.usehandler(r) app.run(":3000")
however, req.cookies()
empty, meaning can't authorize requests "/auth/connection"
-- , i'm positive not problem websocket client (if you're curious, i'm testing using python package: https://github.com/liris/websocket-client). approaching authentication of websocket correctly?
any help/advice appreciated!
the server handles websocket handshake normal http request point upgrade called. use whatever authentication use normal http requests.
the gorilla package not in play @ line of code auth comment.
Comments
Post a Comment