-
Notifications
You must be signed in to change notification settings - Fork 0
/
firewall.go
56 lines (48 loc) · 1.47 KB
/
firewall.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
package compose
import (
"net/http"
"time"
"github.com/ory-am/fosite"
foauth2 "github.com/ory-am/fosite/handler/oauth2"
"github.com/ory-am/hydra/firewall"
. "github.com/ory-am/hydra/oauth2"
"github.com/ory-am/hydra/pkg"
"github.com/ory-am/hydra/warden"
"github.com/ory-am/ladon"
"golang.org/x/oauth2"
"github.com/ory-am/hydra/warden/group"
)
func NewFirewall(issuer string, subject string, scopes fosite.Arguments, p ...ladon.Policy) (firewall.Firewall, *http.Client) {
tokens := pkg.Tokens(1)
fositeStore := pkg.FositeStore()
ps := map[string]ladon.Policy{}
for _, x := range p {
ps[x.GetID()] = x
}
ladonWarden := pkg.LadonWarden(ps)
ar := fosite.NewAccessRequest(NewSession(subject))
ar.GrantedScopes = scopes
fositeStore.CreateAccessTokenSession(nil, tokens[0][0], ar)
conf := &oauth2.Config{Scopes: scopes, Endpoint: oauth2.Endpoint{}}
return &warden.LocalWarden{
Warden: ladonWarden,
OAuth2: &fosite.Fosite{
Store: fositeStore,
TokenIntrospectionHandlers: fosite.TokenIntrospectionHandlers{
&foauth2.CoreValidator{
CoreStrategy: pkg.HMACStrategy,
CoreStorage: fositeStore,
ScopeStrategy: fosite.HierarchicScopeStrategy,
},
},
ScopeStrategy: fosite.HierarchicScopeStrategy,
},
Issuer: issuer,
AccessTokenLifespan: time.Hour,
Groups: group.NewMemoryManager(),
}, conf.Client(oauth2.NoContext, &oauth2.Token{
AccessToken: tokens[0][1],
Expiry: time.Now().Add(time.Hour),
TokenType: "bearer",
})
}