首页 > 解决方案 > 我在 golang 中的令牌验证功能中出现错误

问题描述

我的代码:

func ValidateToken(w http.ResponseWriter, r *http.Request) {
    token, err := request.ParseFromRequestWithClaims(r, request.OAuth2Extractor, &models.Claim{}, func(token *jwt.Token) (interface{}, error) {
        return publicKey, nil
    })
    if err != nil {
        fmt.Fprintln(w, "Invalid Token")
        return
    }
    if token.Valid {
        w.WriteHeader(http.StatusAccepted)
        fmt.Fprintln(w, "welcome to the system")
    } else {
        w.WriteHeader(http.StatusUnauthorized)
        fmt.Fprintln(w, "your token is not valid")
    }
}

我有问题:

cannot use func literal (type func(*"github.com/tokens/vendor/github.com/dgrijalva/jwt-go".Token) (interface {}, error)) as type "github.com/dgrijalva/jwt-go".Keyfunc in argument to request.ParseFromRequestWithClaims

标签: gojwt

解决方案


推荐阅读