func parseKeySet(jwksBytes json.RawMessage) (keys map[string]*rawJWK, err error) {
	var rawKS rawJWKs
	if err = json.Unmarshal(jwksBytes, &rawKS); err != nil {
		return nil, err
	}
	keys = make(map[string]*rawJWK, len(rawKS.Keys))
	for _, key := range rawKS.Keys {
		key := key
		keys[key.ID] = &key
	}
	return keys, nil
}
New creates a new JWKs from a raw JSON message.
package jwtware
import (
	"bytes"
	"context"
	"encoding/json"
	"errors"
	"fmt"
	"io/ioutil"
	"net/http"
	"sync"
	"time"
	"github.com/golang-jwt/jwt/v4"
)
var (  
	errMissingKeySet = errors.New("not able to download JWKs")
	errKID = errors.New("the JWT has an invalid kid")
	errUnsupportedKeyType = errors.New("the JWT key type is unsupported")
	errKIDNotFound = errors.New("the given key ID was not found in the JWKs")
	errMissingAssets = errors.New("required assets are missing to create a public key")
)
type rawJWK struct {
	Curve       string `json:"crv"`
	Exponent    string `json:"e"`
	ID          string `json:"kid"`
	Modulus     string `json:"n"`
	X           string `json:"x"`
	Y           string `json:"y"`
	precomputed interface{}
}
type rawJWKs struct {
	Keys []rawJWK `json:"keys"`
}
type KeySet struct {
	Keys            map[string]*rawJWK
	Config          *Config
	cancel          context.CancelFunc
	client          *http.Client
	ctx             context.Context
	mux             sync.RWMutex
	refreshRequests chan context.CancelFunc
}
func (j *KeySet) keyFunc() jwt.Keyfunc {
	return func(token *jwt.Token) (interface{}, error) {
		if j.Keys == nil {
			err := j.downloadKeySet()
			if err != nil {
				return nil, fmt.Errorf("%w: key set URL is not accessible", errMissingKeySet)
			}
		}
		kidInter, ok := token.Header["kid"]
		if !ok {
			return nil, fmt.Errorf("%w: could not find kid in JWT header", errKID)
		}
		kid, ok := kidInter.(string)
		if !ok {
			return nil, fmt.Errorf("%w: could not convert kid in JWT header to string", errKID)
		}
		jsonKey, err := j.getKey(kid)
		if err != nil {
			return nil, err
		}
		switch keyAlg := token.Header["alg"]; keyAlg {
		case ES256, ES384, ES512:
			return jsonKey.getECDSA()
		case PS256, PS384, PS512, RS256, RS384, RS512:
			return jsonKey.getRSA()
		default:
			return nil, fmt.Errorf("%w: %s: feel free to add a feature request or contribute to https://github.com/MicahParks/keyfunc", errUnsupportedKeyType, keyAlg)
		}
	}
}
func (j *KeySet) downloadKeySet() (err error) {
	if j.client == nil {
		j.client = http.DefaultClient
	}
	if err = j.refresh(); err != nil {
		return err
	}
	if j.Config.KeyRefreshInterval != nil || j.Config.KeyRefreshRateLimit != nil {
		j.ctx, j.cancel = context.WithCancel(context.Background())
		j.refreshRequests = make(chan context.CancelFunc, 1)
		go j.startRefreshing()
	}
	return nil
}