* updates go-jose to new updated repo due to migration - updated from /square/go-jose to /go-jose/go-jose - updates to v2.6.3 - addresses CVE-2016-9123 and CVE-2016-9121 - fixes tests that were adjusting for a 1s delay * revert 299>300 in op_test.go
42 lines
941 B
Go
42 lines
941 B
Go
package op
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"gopkg.in/go-jose/go-jose.v2"
|
|
|
|
httphelper "github.com/zitadel/oidc/v2/pkg/http"
|
|
)
|
|
|
|
type KeyProvider interface {
|
|
KeySet(context.Context) ([]Key, error)
|
|
}
|
|
|
|
func keysHandler(k KeyProvider) func(http.ResponseWriter, *http.Request) {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
Keys(w, r, k)
|
|
}
|
|
}
|
|
|
|
func Keys(w http.ResponseWriter, r *http.Request, k KeyProvider) {
|
|
keySet, err := k.KeySet(r.Context())
|
|
if err != nil {
|
|
httphelper.MarshalJSONWithStatus(w, err, http.StatusInternalServerError)
|
|
return
|
|
}
|
|
httphelper.MarshalJSON(w, jsonWebKeySet(keySet))
|
|
}
|
|
|
|
func jsonWebKeySet(keys []Key) *jose.JSONWebKeySet {
|
|
webKeys := make([]jose.JSONWebKey, len(keys))
|
|
for i, key := range keys {
|
|
webKeys[i] = jose.JSONWebKey{
|
|
KeyID: key.ID(),
|
|
Algorithm: string(key.Algorithm()),
|
|
Use: key.Use(),
|
|
Key: key.Key(),
|
|
}
|
|
}
|
|
return &jose.JSONWebKeySet{Keys: webKeys}
|
|
}
|