cmd/jwt/main.go
func loadKeyData(path string) (pemutil.Store, jwt.Algorithm, error) {
	// check if it's json data
	buf, err := ioutil.ReadFile(path)
	if err != nil {
		return nil, jwt.NONE, err
	}

	// attempt json decode
	v := make(map[string]interface{})
	err = json.Unmarshal(buf, &v)
	if err != nil {
		// not json encoded, so skip
		keyset, err := pemutil.LoadFile(path)
		if err != nil {
			return nil, jwt.NONE, err
		}
		return keyset, jwt.NONE, nil
	}

	// attempt decode on each field of the json decoded values, and ignoring
	// any errors
	keyset := pemutil.Store{}
	for _, val := range v {
		if str, ok := val.(string); ok {
			_ = keyset.Decode([]byte(str))
		}
	}
	keyset.AddPublicKeys()

	if len(keyset) < 1 {
		return nil, jwt.NONE, fmt.Errorf("could not find any PEM encoded keys in %s", path)
	}

	// if it's a google service account, return RS256
	if bytes.Contains(buf, []byte("gserviceaccount.com")) {
		return keyset, jwt.RS256, nil
	}

	return keyset, jwt.NONE, nil
}
func loadKeyData(path string) (pemutil.Store, jwt.Algorithm, error) {
	// check if it's json data
	buf, err := ioutil.ReadFile(path)
	if err != nil {
		return nil, jwt.NONE, err
	}

	// attempt json decode
	v := make(map[string]interface{})
	err = json.Unmarshal(buf, &v)
	if err != nil {
		// not json encoded, so skip
		keyset, err := pemutil.LoadFile(path)
		if err != nil {
			return nil, jwt.NONE, err
		}
		return keyset, jwt.NONE, nil
	}

	// attempt decode on each field of the json decoded values, and ignoring
	// any errors
	keyset := pemutil.Store{}
	for _, val := range v {
		if str, ok := val.(string); ok {
			_ = keyset.Decode([]byte(str))
		}
	}
	keyset.AddPublicKeys()

	if len(keyset) < 1 {
		return nil, jwt.NONE, fmt.Errorf("could not find any PEM encoded keys in %s", path)
	}

	// if it's a google service account, return RS256
	if bytes.Contains(buf, []byte("gserviceaccount.com")) {
		return keyset, jwt.RS256, nil
	}

	return keyset, jwt.NONE, nil
}
// loadKeyData loads key data from the path.
//
// Attempts to json-decode the file first, otherwise passes it to pemutil. If
// the file appears to be a Google service account JSON file (ie contains
// "gserviceaccount.com"), then jwt.RS256 will be returned, otherwise jwt.NONE
// is returned.