mirror of
https://github.com/1f349/mjwt.git
synced 2024-12-21 23:14:04 +00:00
Add JSONWebKeySet generator
This commit is contained in:
parent
1fc34736a2
commit
4e2c18918f
1
go.mod
1
go.mod
@ -7,6 +7,7 @@ toolchain go1.22.3
|
|||||||
require (
|
require (
|
||||||
github.com/1f349/rsa-helper v0.0.2
|
github.com/1f349/rsa-helper v0.0.2
|
||||||
github.com/becheran/wildmatch-go v1.0.0
|
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/golang-jwt/jwt/v4 v4.5.0
|
||||||
github.com/google/subcommands v1.2.0
|
github.com/google/subcommands v1.2.0
|
||||||
github.com/pkg/errors v0.9.1
|
github.com/pkg/errors v0.9.1
|
||||||
|
30
jwks.go
Normal file
30
jwks.go
Normal file
@ -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)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user