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.
Open-IM-Server/internal/cms_api/middleware/jwt_auth.go

27 lines
671 B

3 years ago
package middleware
import (
3 years ago
"Open_IM/pkg/common/log"
"Open_IM/pkg/common/token_verify"
3 years ago
"Open_IM/pkg/utils"
2 years ago
"net/http"
3 years ago
"github.com/gin-gonic/gin"
)
func JWTAuth() gin.HandlerFunc {
return func(c *gin.Context) {
3 years ago
ok, userID, errInfo := token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), "")
2 years ago
// log.NewInfo("0", utils.GetSelfFuncName(), "userID: ", userID)
3 years ago
c.Set("userID", userID)
3 years ago
if !ok {
3 years ago
log.NewError("", "GetUserIDFromToken false ", c.Request.Header.Get("token"))
3 years ago
c.Abort()
2 years ago
c.JSON(http.StatusOK, gin.H{"errCode": 400, "errMsg": errInfo})
3 years ago
return
3 years ago
} else {
log.NewInfo("0", utils.GetSelfFuncName(), "failed: ", errInfo)
3 years ago
}
3 years ago
}
}