add operationID when ws connecting

pull/218/head
skiffer-git 3 years ago
parent 3a8a0a541e
commit fe3bd2a1f1

@ -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

@ -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, ""

Loading…
Cancel
Save