I want to validate a JSON Web Token. The JSON Web Key for the verification are avaiable under this url. Those are JWKs with x509 certificates (x5c). Based on an answer to another question, tried the following:
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
}
But I get the following error
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
I could not find an example that uses x5c. A solution does not have to use the library I used in my example. Thanks!