blob: 4a29d1be004e4c56e929793113df77ed310bf746 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
package web
import (
"crypto/x509"
"encoding/json"
"encoding/pem"
"net/http"
"github.com/lestrrat-go/jwx/v2/jwk"
)
func (h *HttpContext) JsonWebKeySets(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
privatePem, _ := pem.Decode(h.cfg.KeyData)
parsedKey, _ := x509.ParsePKCS1PrivateKey(privatePem.Bytes)
key, _ := jwk.FromRaw(parsedKey)
pubKey, _ := jwk.PublicKeyOf(key)
pubKey.Set(jwk.KeyIDKey, "X")
pubKey.Set(jwk.KeyUsageKey, "sig")
set := jwk.NewSet()
set.Add(pubKey)
json.NewEncoder(w).Encode(set)
}
|