【发布时间】:2021-06-25 13:10:16
【问题描述】:
我想验证 JSON Web 令牌。用于验证的 JSON Web Key 在this url 下可用。这些是具有 x509 证书 (x5c) 的 JWK。基于answer to another question,尝试了以下方法:
import "github.com/dgrijalva/jwt-go"
import "github.com/lestrrat-go/jwx/jwk"
func verifyToken(tokenBytes []byte) {
token, err := jwt.Parse(string(tokenBytes), getKey)
if err != nil {
panic(err)
}
}
func getKey(token *jwt.Token) (interface{}, error) {
set, err := jwk.Fetch(context.Background(), "https://shareduks.uks.attest.azure.net/certs")
if err != nil {
return nil, err
}
keyID, ok := token.Header["kid"].(string)
if !ok {
return nil, err
}
key, ok := set.LookupKeyID(keyID)
if !ok {
return nil, errors.New("could not find key with kid")
}
return key, nil
}
但我收到以下错误
panic: failed to parse JWK set: failed to unmarshal JWK set: failed to unmarshal key #1 (total 5) from multi-key JWK set: failed to unmarshal JSON into key (*jwk.rsaPublicKey): required field e is missing
我找不到使用 x5c 的示例。解决方案不必使用我在示例中使用的库。谢谢!
【问题讨论】: