diff --git a/internal/msg_gateway/gate/ws_server.go b/internal/msg_gateway/gate/ws_server.go index 7c602a5fc..7686b6cab 100644 --- a/internal/msg_gateway/gate/ws_server.go +++ b/internal/msg_gateway/gate/ws_server.go @@ -262,19 +262,23 @@ func (ws *WServer) getUserUid(conn *UserConn) (uid, platform string) { func (ws *WServer) headerCheck(w http.ResponseWriter, r *http.Request) bool { status := http.StatusUnauthorized 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 ok, err, msg := token_verify.WsVerifyToken(query["token"][0], query["sendID"][0], query["platformID"][0]); !ok { - e := err.(*constant.ErrInfo) - log.ErrorByKv("Token verify failed", "", "query", query, msg) + // e := err.(*constant.ErrInfo) + log.Error(operationID, "Token verify failed ", "query ", query, msg, err.Error()) w.Header().Set("Sec-Websocket-Version", "13") - http.Error(w, e.ErrMsg, int(e.ErrCode)) + http.Error(w, err.Error(), 2001) return false } 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 } } else { - log.ErrorByKv("Args err", "", "query", query) + log.Error(operationID, "Args err", "query", query) w.Header().Set("Sec-Websocket-Version", "13") http.Error(w, http.StatusText(status), status) return false diff --git a/pkg/common/token_verify/jwt_token.go b/pkg/common/token_verify/jwt_token.go index bfff43116..16eb5e8d0 100644 --- a/pkg/common/token_verify/jwt_token.go +++ b/pkg/common/token_verify/jwt_token.go @@ -218,13 +218,13 @@ func VerifyToken(token, uid string) (bool, error) { func WsVerifyToken(token, uid string, platformID string) (bool, error, string) { claims, err := ParseToken(token, "") if err != nil { - return false, err, "parse token err" + return false, utils.Wrap(err, ""), "parse token err" } 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)) { - 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) return true, nil, ""