Skip to content

Commit

Permalink
Add JSONWebKeySet generator
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmelon54 committed Jul 27, 2024
1 parent 1fc3473 commit 4e2c189
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ toolchain go1.22.3
require (
github.com/1f349/rsa-helper v0.0.2
github.com/becheran/wildmatch-go v1.0.0
github.com/go-jose/go-jose/v4 v4.0.4
github.com/golang-jwt/jwt/v4 v4.5.0
github.com/google/subcommands v1.2.0
github.com/pkg/errors v0.9.1
Expand Down
30 changes: 30 additions & 0 deletions jwks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package mjwt

import (
"encoding/json"
"github.com/go-jose/go-jose/v4"
"io"
)

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)
}

0 comments on commit 4e2c189

Please sign in to comment.