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
Этот коммит содержится в:
коммит произвёл
Christopher Speller
родитель
ef363fd88e
Коммит
316b155a42
@@ -37,6 +37,37 @@ func (wr *WebSocketRouter) ServeWebSocket(conn *WebConn, r *model.WebSocketReque
|
||||
return
|
||||
}
|
||||
|
||||
if r.Action == model.WEBSOCKET_AUTHENTICATION_CHALLENGE {
|
||||
token, ok := r.Data["token"].(string)
|
||||
if !ok {
|
||||
conn.WebSocket.Close()
|
||||
return
|
||||
}
|
||||
|
||||
session := GetSession(token)
|
||||
|
||||
if session == nil || session.IsExpired() {
|
||||
conn.WebSocket.Close()
|
||||
} else {
|
||||
go SetStatusOnline(session.UserId, session.Id, false)
|
||||
|
||||
conn.SessionToken = session.Token
|
||||
conn.UserId = session.UserId
|
||||
|
||||
resp := model.NewWebSocketResponse(model.STATUS_OK, r.Seq, nil)
|
||||
resp.DoPreComputeJson()
|
||||
conn.Send <- resp
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if conn.SessionToken == "" {
|
||||
err := model.NewLocAppError("ServeWebSocket", "api.web_socket_router.not_authenticated.app_error", nil, "")
|
||||
wr.ReturnWebSocketError(conn, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
var handler *webSocketHandler
|
||||
if h, ok := wr.handlers[r.Action]; !ok {
|
||||
err := model.NewLocAppError("ServeWebSocket", "api.web_socket_router.bad_action.app_error", nil, "")
|
||||
|
||||
Ссылка в новой задаче
Block a user