mirror of
https://github.com/1f349/mjwt.git
synced 2024-11-12 22:41:36 +00:00
32 lines
652 B
Go
32 lines
652 B
Go
package mjwt
|
|
|
|
import (
|
|
"encoding/json"
|
|
"github.com/go-jose/go-jose/v4"
|
|
"io"
|
|
)
|
|
|
|
// WriteJwkSetJson outputs the public keys used by the Issuers
|
|
func WriteJwkSetJson(w io.Writer, issuers []*Issuer) error {
|
|
enc := json.NewEncoder(w)
|
|
enc.SetIndent("", " ")
|
|
var j jose.JSONWebKeySet
|
|
for _, issuer := range issuers {
|
|
// get public key from private key
|
|
key, err := issuer.PrivateKey()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
pubKey := &key.PublicKey
|
|
|
|
// format as JWK
|
|
j.Keys = append(j.Keys, jose.JSONWebKey{
|
|
Algorithm: issuer.signing.Alg(),
|
|
Use: "sig",
|
|
KeyID: issuer.kid,
|
|
Key: pubKey,
|
|
})
|
|
}
|
|
return enc.Encode(j)
|
|
}
|