// VerifyPerm is used to pass a MapClaim to a authorization function.
// After authorization, use UserFetcher to get a user object by identity,
// and set it into the gin.Context.
VerifyPerm is used to pass a MapClaim to a authorization function.
After authorization, use UserFetcher to get a user object by identity,
and set it into the gin.Context.
// VerifyPerm is used to pass a MapClaim to a authorization function . // After authorization use UserFetcher to get a user object by identity // and set it into the gin . Context .
func (a Auth) VerifyPerm(permitted func(MapClaims) bool) gin.HandlerFunc {
	return func(c *gin.Context) {
		token, err := a.parseToken(c)
		if handleParseTokenError(c, err) {
			c.Abort()
			return
		}
		claims := token.Claims.(MapClaims)
		c.Set(PayloadKey, claims)
		if !permitted(claims) {
			c.Set(ErrKey, ErrorPermissionDenied)
			c.Status(http.StatusForbidden)
			c.Abort()
			return
		}
		u, err := a.UserFetcher(c, claims)
		if err != nil {
			c.Set(ErrKey, err)
			c.Status(http.StatusInternalServerError)
			c.Abort()
			return
		}
		if u == nil {
			c.Set(ErrKey, ErrorUserNotFound)
			c.Status(http.StatusInternalServerError)
			c.Abort()
			return
		}
		c.Set(UserKey, u)
		c.Next()
	}
}
func ( a Auth ) VerifyPerm ( permitted func ( MapClaims ) bool ) gin . HandlerFunc { return func ( c * gin . Context ) { token , err := a . parseToken ( c ) if handleParseTokenError ( c , err ) { c . Abort ( ) return } claims := token . Claims . ( MapClaims ) c . Set ( PayloadKey , claims ) if ! permitted ( claims ) { c . Set ( ErrKey , ErrorPermissionDenied ) c . Status ( http . StatusForbidden ) c . Abort ( ) return } u , err := a . UserFetcher ( c , claims ) if err != nil { c . Set ( ErrKey , err ) c . Status ( http . StatusInternalServerError ) c . Abort ( ) return } if u == nil { c . Set ( ErrKey , ErrorUserNotFound ) c . Status ( http . StatusInternalServerError ) c . Abort ( ) return } c . Set ( UserKey , u ) c . Next ( ) } }
VerifyPerm is used to pass a MapClaim to a authorization function.
VerifyPerm is used to pass a MapClaim to a authorization function .
// set payload to context for debug