forked from ory/hydra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manager_http.go
87 lines (73 loc) · 1.93 KB
/
manager_http.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package jwk
import (
"net/http"
"net/url"
"github.com/ory-am/hydra/pkg"
"github.com/square/go-jose"
)
type HTTPManager struct {
Client *http.Client
Endpoint *url.URL
Dry bool
}
func (m *HTTPManager) CreateKeys(set, algorithm string) (*jose.JsonWebKeySet, error) {
var c = struct {
Algorithm string `json:"alg"`
Keys []jose.JsonWebKey `json:"keys"`
}{
Algorithm: algorithm,
}
var r = pkg.NewSuperAgent(pkg.JoinURL(m.Endpoint, set).String())
r.Client = m.Client
r.Dry = m.Dry
if err := r.Create(&c); err != nil {
return nil, err
}
return &jose.JsonWebKeySet{
Keys: c.Keys,
}, nil
}
func (m *HTTPManager) AddKey(set string, key *jose.JsonWebKey) error {
var r = pkg.NewSuperAgent(pkg.JoinURL(m.Endpoint, set, key.KeyID).String())
r.Client = m.Client
r.Dry = m.Dry
return r.Update(key)
}
func (m *HTTPManager) AddKeySet(set string, keys *jose.JsonWebKeySet) error {
var r = pkg.NewSuperAgent(pkg.JoinURL(m.Endpoint, set).String())
r.Client = m.Client
r.Dry = m.Dry
return r.Update(keys)
}
func (m *HTTPManager) GetKey(set, kid string) (*jose.JsonWebKeySet, error) {
var c jose.JsonWebKeySet
var r = pkg.NewSuperAgent(pkg.JoinURL(m.Endpoint, set, kid).String())
r.Client = m.Client
r.Dry = m.Dry
if err := r.Get(&c); err != nil {
return nil, err
}
return &c, nil
}
func (m *HTTPManager) GetKeySet(set string) (*jose.JsonWebKeySet, error) {
var c jose.JsonWebKeySet
var r = pkg.NewSuperAgent(pkg.JoinURL(m.Endpoint, set).String())
r.Client = m.Client
r.Dry = m.Dry
if err := r.Get(&c); err != nil {
return nil, err
}
return &c, nil
}
func (m *HTTPManager) DeleteKey(set, kid string) error {
var r = pkg.NewSuperAgent(pkg.JoinURL(m.Endpoint, set, kid).String())
r.Client = m.Client
r.Dry = m.Dry
return r.Delete()
}
func (m *HTTPManager) DeleteKeySet(set string) error {
var r = pkg.NewSuperAgent(pkg.JoinURL(m.Endpoint, set).String())
r.Client = m.Client
r.Dry = m.Dry
return r.Delete()
}