-
Notifications
You must be signed in to change notification settings - Fork 66
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
feat(websocket): add process to authenticate websocket connections #1921
Conversation
972cf3b
to
37f1808
Compare
37f1808
to
a0dd49a
Compare
lib/websocket_test.go
Outdated
connID := newID() | ||
SetIDRand(strings.NewReader(randIDStr)) | ||
|
||
wsh.WSConnectionHandler(mockWebsocketWriterAndRequest()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this tests that the wsHandler
is setting up a connection & placing it in the conns
map.
However, it doesn't set us up to be able to test the wsHandler.read
or wsHandler.handleMessage
methods. May need to expand on the mockHijacker
struct below & create methods that allow us to write on the connection.
a0dd49a
to
e7f976f
Compare
Websocket connections need to be scoped so we only send the relevant events to the correct connections. To accomplish this, we keep track of the profile.ID of each connections using the new `websocket.conn` struct, as well as keeping a map of profile.IDs to connections. To allow us to authenticate tokens, the `websocket.Handler` must have access to the `key.Store`. We've added an authentication handshake. Once the connection has been established, the client can request to "subscribe" to a connection, and send over a token as part of the message payload. If that token is valid, we upgrade the connection, and send over a success message. If not, we send over a failure message. If the client wants to unsubscribe, they send over an "unsubscribe" request. This will remove the association between that connection and a profile.ID. It will not close the connection. We've also defined a `websocket.message` struct that the websocket expects to receive for communication about the state of the websocket connection (namely the authentication handshake).
e7f976f
to
ef8110e
Compare
Subscribe
& Unsubscribe
process to websocket connectionsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
closes #1912
also moves
websocket
work into its own package