You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
880 B
33 lines
880 B
package middleware
|
|
|
|
import (
|
|
"Open_IM/pkg/common/config"
|
|
"Open_IM/pkg/common/log"
|
|
"Open_IM/pkg/common/token_verify"
|
|
"Open_IM/pkg/utils"
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func JWTAuth() gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
ok, userID, errInfo := token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), "")
|
|
// log.NewInfo("0", utils.GetSelfFuncName(), "userID: ", userID)
|
|
c.Set("userID", userID)
|
|
if !ok {
|
|
log.NewError("", "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
|
c.Abort()
|
|
c.JSON(http.StatusOK, gin.H{"errCode": 400, "errMsg": errInfo})
|
|
return
|
|
} else {
|
|
if !utils.IsContain(userID, config.Config.Manager.AppManagerUid) {
|
|
c.Abort()
|
|
c.JSON(http.StatusOK, gin.H{"errCode": 400, "errMsg": "user is not admin"})
|
|
return
|
|
}
|
|
log.NewInfo("0", utils.GetSelfFuncName(), "failed: ", errInfo)
|
|
}
|
|
}
|
|
}
|