mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
fix secret check and management
This commit is contained in:
parent
a87c16de0d
commit
dfd028625d
@ -49,6 +49,10 @@ func UserRegister(c *gin.Context) {
|
|||||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if params.Secret != config.Config.Secret {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 401, "errMsg": "not authorized"})
|
||||||
|
return
|
||||||
|
}
|
||||||
pbData := newUserRegisterReq(¶ms)
|
pbData := newUserRegisterReq(¶ms)
|
||||||
|
|
||||||
log.Info("", "", "api user_register is server, [data: %s]", pbData.String())
|
log.Info("", "", "api user_register is server, [data: %s]", pbData.String())
|
||||||
|
@ -37,6 +37,10 @@ func UserToken(c *gin.Context) {
|
|||||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if params.Secret != config.Config.Secret {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 401, "errMsg": "not authorized"})
|
||||||
|
return
|
||||||
|
}
|
||||||
pbData := newUserTokenReq(¶ms)
|
pbData := newUserTokenReq(¶ms)
|
||||||
|
|
||||||
log.Info("", "", "api user_token is server, [data: %s]", pbData.String())
|
log.Info("", "", "api user_token is server, [data: %s]", pbData.String())
|
||||||
|
@ -35,7 +35,7 @@ type paramsManagementSendMsg struct {
|
|||||||
SessionType int32 `json:"sessionType" binding:"required"`
|
SessionType int32 `json:"sessionType" binding:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func newUserSendMsgReq(token string, params *paramsManagementSendMsg) *pbChat.UserSendMsgReq {
|
func newUserSendMsgReq(params *paramsManagementSendMsg) *pbChat.UserSendMsgReq {
|
||||||
var newContent string
|
var newContent string
|
||||||
switch params.ContentType {
|
switch params.ContentType {
|
||||||
case constant.Text:
|
case constant.Text:
|
||||||
@ -53,7 +53,6 @@ func newUserSendMsgReq(token string, params *paramsManagementSendMsg) *pbChat.Us
|
|||||||
}
|
}
|
||||||
pbData := pbChat.UserSendMsgReq{
|
pbData := pbChat.UserSendMsgReq{
|
||||||
ReqIdentifier: constant.WSSendMsg,
|
ReqIdentifier: constant.WSSendMsg,
|
||||||
Token: token,
|
|
||||||
SendID: params.SendID,
|
SendID: params.SendID,
|
||||||
SenderNickName: params.SenderNickName,
|
SenderNickName: params.SenderNickName,
|
||||||
SenderFaceURL: params.SenderFaceURL,
|
SenderFaceURL: params.SenderFaceURL,
|
||||||
@ -103,15 +102,19 @@ func ManagementSendMsg(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
token := c.Request.Header.Get("token")
|
token := c.Request.Header.Get("token")
|
||||||
if !utils.IsContain(params.SendID, config.Config.Manager.AppManagerUid) {
|
claims, err := utils.ParseToken(token)
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "not appManager", "sendTime": 0, "MsgID": ""})
|
if err != nil {
|
||||||
|
log.NewError(params.OperationID, "parse token failed", err.Error())
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "parse token failed", "sendTime": 0, "MsgID": ""})
|
||||||
|
}
|
||||||
|
if !utils.IsContain(claims.UID, config.Config.Manager.AppManagerUid) {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "not authorized", "sendTime": 0, "MsgID": ""})
|
||||||
return
|
return
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log.InfoByKv("Ws call success to ManagementSendMsgReq", params.OperationID, "Parameters", params)
|
log.InfoByKv("Ws call success to ManagementSendMsgReq", params.OperationID, "Parameters", params)
|
||||||
|
|
||||||
pbData := newUserSendMsgReq(token, ¶ms)
|
pbData := newUserSendMsgReq(¶ms)
|
||||||
log.Info("", "", "api ManagementSendMsg call start..., [data: %s]", pbData.String())
|
log.Info("", "", "api ManagementSendMsg call start..., [data: %s]", pbData.String())
|
||||||
|
|
||||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfflineMessageName)
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfflineMessageName)
|
||||||
|
@ -42,12 +42,9 @@ type MsgCallBackResp struct {
|
|||||||
|
|
||||||
func (rpc *rpcChat) UserSendMsg(_ context.Context, pb *pbChat.UserSendMsgReq) (*pbChat.UserSendMsgResp, error) {
|
func (rpc *rpcChat) UserSendMsg(_ context.Context, pb *pbChat.UserSendMsgReq) (*pbChat.UserSendMsgResp, error) {
|
||||||
replay := pbChat.UserSendMsgResp{}
|
replay := pbChat.UserSendMsgResp{}
|
||||||
log.InfoByKv("sendMsg", pb.OperationID, "args", pb.String())
|
log.NewDebug(pb.OperationID, "rpc sendMsg come here", pb.String())
|
||||||
time := utils.GetCurrentTimestampByMill()
|
|
||||||
//if !utils.VerifyToken(pb.Token, pb.SendID) {
|
//if !utils.VerifyToken(pb.Token, pb.SendID) {
|
||||||
// return returnMsg(&replay, pb, http.StatusUnauthorized, "token validate err,not authorized", "", 0)
|
// return returnMsg(&replay, pb, http.StatusUnauthorized, "token validate err,not authorized", "", 0)
|
||||||
//}
|
|
||||||
log.NewInfo(pb.OperationID, "VerifyToken cost time ", utils.GetCurrentTimestampByMill()-time)
|
|
||||||
serverMsgID := GetMsgID(pb.SendID)
|
serverMsgID := GetMsgID(pb.SendID)
|
||||||
pbData := pbChat.WSToMsgSvrChatMsg{}
|
pbData := pbChat.WSToMsgSvrChatMsg{}
|
||||||
pbData.MsgFrom = pb.MsgFrom
|
pbData.MsgFrom = pb.MsgFrom
|
||||||
@ -99,10 +96,8 @@ func (rpc *rpcChat) UserSendMsg(_ context.Context, pb *pbChat.UserSendMsgReq) (*
|
|||||||
}
|
}
|
||||||
switch pbData.SessionType {
|
switch pbData.SessionType {
|
||||||
case constant.SingleChatType:
|
case constant.SingleChatType:
|
||||||
time := utils.GetCurrentTimestampByMill()
|
|
||||||
err1 := rpc.sendMsgToKafka(&pbData, pbData.RecvID)
|
err1 := rpc.sendMsgToKafka(&pbData, pbData.RecvID)
|
||||||
err2 := rpc.sendMsgToKafka(&pbData, pbData.SendID)
|
err2 := rpc.sendMsgToKafka(&pbData, pbData.SendID)
|
||||||
log.NewInfo(pb.OperationID, "send kafka cost time ", utils.GetCurrentTimestampByMill()-time)
|
|
||||||
if err1 != nil || err2 != nil {
|
if err1 != nil || err2 != nil {
|
||||||
return returnMsg(&replay, pb, 201, "kafka send msg err", "", 0)
|
return returnMsg(&replay, pb, 201, "kafka send msg err", "", 0)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user