mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
ws token
This commit is contained in:
parent
a990e6f19d
commit
c16e7fc022
@ -1,13 +1,11 @@
|
||||
package msggateway
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
)
|
||||
import "github.com/OpenIMSDK/Open-IM-Server/pkg/apiresp"
|
||||
|
||||
func httpError(ctx *UserConnContext, err error) {
|
||||
code := http.StatusUnauthorized
|
||||
ctx.SetHeader("Sec-Websocket-Version", "13")
|
||||
ctx.SetHeader("ws_err_msg", err.Error())
|
||||
//code := http.StatusUnauthorized
|
||||
//ctx.SetHeader("Sec-Websocket-Version", "13")
|
||||
//ctx.SetHeader("ws_err_msg", err.Error())
|
||||
//if errors.Is(err, errs.ErrTokenExpired) {
|
||||
// code = errs.ErrTokenExpired.Code()
|
||||
//}
|
||||
@ -38,5 +36,6 @@ func httpError(ctx *UserConnContext, err error) {
|
||||
//if errors.Is(err, errs.ErrConnArgsErr) {
|
||||
// code = errs.ErrConnArgsErr.Code()
|
||||
//}
|
||||
ctx.ErrReturn(err.Error(), code)
|
||||
//ctx.ErrReturn(err.Error(), code)
|
||||
apiresp.HttpError(ctx.RespWriter, err)
|
||||
}
|
||||
|
@ -5,15 +5,21 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func HttpError(w http.ResponseWriter, err error) {
|
||||
data, err := json.Marshal(ParseError(err))
|
||||
func httpJson(w http.ResponseWriter, data any) {
|
||||
body, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
http.Error(w, "json marshal error: "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
_ = data
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, _ = w.Write(body)
|
||||
}
|
||||
|
||||
func HttpError(w http.ResponseWriter, err error) {
|
||||
httpJson(w, ParseError(err))
|
||||
}
|
||||
|
||||
func HttpSuccess(w http.ResponseWriter, data any) {
|
||||
|
||||
httpJson(w, ApiSuccess(data))
|
||||
}
|
||||
|
@ -89,15 +89,15 @@ func IsManagerUserID(opUserID string) bool {
|
||||
return utils.IsContain(opUserID, config.Config.Manager.AppManagerUid)
|
||||
}
|
||||
func WsVerifyToken(token, userID, platformID string) error {
|
||||
//claim, err := GetClaimFromToken(token)
|
||||
//if err != nil {
|
||||
// return err
|
||||
//}
|
||||
//if claim.UID != userID {
|
||||
// return errs.ErrTokenInvalid.Wrap(fmt.Sprintf("token uid %s != userID %s", claim.UID, userID))
|
||||
//}
|
||||
//if claim.Platform != platformID {
|
||||
// return errs.ErrInternalServer.Wrap(fmt.Sprintf("token platform %s != platformID %s", claim.Platform, platformID))
|
||||
//}
|
||||
claim, err := GetClaimFromToken(token)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if claim.UID != userID {
|
||||
return errs.ErrTokenInvalid.Wrap(fmt.Sprintf("token uid %s != userID %s", claim.UID, userID))
|
||||
}
|
||||
if claim.Platform != platformID {
|
||||
return errs.ErrTokenInvalid.Wrap(fmt.Sprintf("token platform %s != platformID %s", claim.Platform, platformID))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user