add operationID when ws connecting

pull/455/head
skiffer-git 3 years ago committed by Xinwei Xiong(cubxxw-openim)
parent dbf233d30b
commit d3aa3dbf41

@ -262,19 +262,23 @@ func (ws *WServer) getUserUid(conn *UserConn) (uid, platform string) {
func (ws *WServer) headerCheck(w http.ResponseWriter, r *http.Request) bool { func (ws *WServer) headerCheck(w http.ResponseWriter, r *http.Request) bool {
status := http.StatusUnauthorized status := http.StatusUnauthorized
query := r.URL.Query() query := r.URL.Query()
operationID := ""
if len(query["operationID"]) != 0 {
operationID = query["operationID"][0]
}
if len(query["token"]) != 0 && len(query["sendID"]) != 0 && len(query["platformID"]) != 0 { if len(query["token"]) != 0 && len(query["sendID"]) != 0 && len(query["platformID"]) != 0 {
if ok, err, msg := token_verify.WsVerifyToken(query["token"][0], query["sendID"][0], query["platformID"][0]); !ok { if ok, err, msg := token_verify.WsVerifyToken(query["token"][0], query["sendID"][0], query["platformID"][0]); !ok {
e := err.(*constant.ErrInfo) // e := err.(*constant.ErrInfo)
log.ErrorByKv("Token verify failed", "", "query", query, msg) log.Error(operationID, "Token verify failed ", "query ", query, msg, err.Error())
w.Header().Set("Sec-Websocket-Version", "13") w.Header().Set("Sec-Websocket-Version", "13")
http.Error(w, e.ErrMsg, int(e.ErrCode)) http.Error(w, err.Error(), 2001)
return false return false
} else { } else {
log.InfoByKv("Connection Authentication Success", "", "token", query["token"][0], "userID", query["sendID"][0]) log.Info(operationID, "Connection Authentication Success", "", "token", query["token"][0], "userID", query["sendID"][0])
return true return true
} }
} else { } else {
log.ErrorByKv("Args err", "", "query", query) log.Error(operationID, "Args err", "query", query)
w.Header().Set("Sec-Websocket-Version", "13") w.Header().Set("Sec-Websocket-Version", "13")
http.Error(w, http.StatusText(status), status) http.Error(w, http.StatusText(status), status)
return false return false

@ -218,13 +218,13 @@ func VerifyToken(token, uid string) (bool, error) {
func WsVerifyToken(token, uid string, platformID string) (bool, error, string) { func WsVerifyToken(token, uid string, platformID string) (bool, error, string) {
claims, err := ParseToken(token, "") claims, err := ParseToken(token, "")
if err != nil { if err != nil {
return false, err, "parse token err" return false, utils.Wrap(err, ""), "parse token err"
} }
if claims.UID != uid { if claims.UID != uid {
return false, &constant.ErrTokenUnknown, "uid is not same to token uid" return false, utils.Wrap(&constant.ErrTokenUnknown, ""), "uid is not same to token uid"
} }
if claims.Platform != constant.PlatformIDToName(utils.StringToInt32(platformID)) { if claims.Platform != constant.PlatformIDToName(utils.StringToInt32(platformID)) {
return false, &constant.ErrTokenUnknown, "platform is not same to token platform" return false, utils.Wrap(&constant.ErrTokenUnknown, ""), "platform is not same to token platform"
} }
log.NewDebug("", claims.UID, claims.Platform) log.NewDebug("", claims.UID, claims.Platform)
return true, nil, "" return true, nil, ""

Loading…
Cancel
Save