mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-07 02:26:00 +08:00
ws token
This commit is contained in:
+11
-5
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user