diff options
author | Joram Wilander <jwawilander@gmail.com> | 2016-10-31 08:59:23 -0400 |
---|---|---|
committer | Christopher Speller <crspeller@gmail.com> | 2016-10-31 08:59:23 -0400 |
commit | 316b155a42a4d00fb835438ce7e0401a64e59add (patch) | |
tree | 6a64f05e948323ae7595971608d84a4420a08290 /model/websocket_client.go | |
parent | ef363fd88ebb731dbb0470ad7cb5f50de0f3845c (diff) | |
download | chat-316b155a42a4d00fb835438ce7e0401a64e59add.tar.gz chat-316b155a42a4d00fb835438ce7e0401a64e59add.tar.bz2 chat-316b155a42a4d00fb835438ce7e0401a64e59add.zip |
PLT-3562 Switch websocket over to post-connect authentication (#4327)
* Switch websocket over to post-connect authentication
* Add ability to specify token in websocket js driver, add unit tests
* Temporarily disable client websocket tests until issues are resolved
* Minor refactoring and fix status test
* Add isAuthenticated method to WebConn and minor status updates
Diffstat (limited to 'model/websocket_client.go')
-rw-r--r-- | model/websocket_client.go | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/model/websocket_client.go b/model/websocket_client.go index a4983e385..453ae49b7 100644 --- a/model/websocket_client.go +++ b/model/websocket_client.go @@ -6,7 +6,6 @@ package model import ( "encoding/json" "github.com/gorilla/websocket" - "net/http" ) type WebSocketClient struct { @@ -23,14 +22,12 @@ type WebSocketClient struct { // NewWebSocketClient constructs a new WebSocket client with convienence // methods for talking to the server. func NewWebSocketClient(url, authToken string) (*WebSocketClient, *AppError) { - header := http.Header{} - header.Set(HEADER_AUTH, "BEARER "+authToken) - conn, _, err := websocket.DefaultDialer.Dial(url+API_URL_SUFFIX+"/users/websocket", header) + conn, _, err := websocket.DefaultDialer.Dial(url+API_URL_SUFFIX+"/users/websocket", nil) if err != nil { return nil, NewLocAppError("NewWebSocketClient", "model.websocket_client.connect_fail.app_error", nil, err.Error()) } - return &WebSocketClient{ + client := &WebSocketClient{ url, url + API_URL_SUFFIX, conn, @@ -39,19 +36,25 @@ func NewWebSocketClient(url, authToken string) (*WebSocketClient, *AppError) { make(chan *WebSocketEvent, 100), make(chan *WebSocketResponse, 100), nil, - }, nil + } + + client.SendMessage(WEBSOCKET_AUTHENTICATION_CHALLENGE, map[string]interface{}{"token": authToken}) + + return client, nil } func (wsc *WebSocketClient) Connect() *AppError { - header := http.Header{} - header.Set(HEADER_AUTH, "BEARER "+wsc.AuthToken) - var err error - wsc.Conn, _, err = websocket.DefaultDialer.Dial(wsc.ApiUrl+"/users/websocket", header) + wsc.Conn, _, err = websocket.DefaultDialer.Dial(wsc.ApiUrl+"/users/websocket", nil) if err != nil { return NewLocAppError("NewWebSocketClient", "model.websocket_client.connect_fail.app_error", nil, err.Error()) } + wsc.EventChannel = make(chan *WebSocketEvent, 100) + wsc.ResponseChannel = make(chan *WebSocketResponse, 100) + + wsc.SendMessage(WEBSOCKET_AUTHENTICATION_CHALLENGE, map[string]interface{}{"token": wsc.AuthToken}) + return nil } @@ -89,6 +92,7 @@ func (wsc *WebSocketClient) Listen() { wsc.ResponseChannel <- &response continue } + } }() } |