forked from ory/fosite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compose_strategy.go
41 lines (35 loc) · 961 Bytes
/
compose_strategy.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
package compose
import (
"crypto/rsa"
"github.com/ory-am/fosite/handler/oauth2"
"github.com/ory-am/fosite/handler/openid"
"github.com/ory-am/fosite/token/hmac"
"github.com/ory-am/fosite/token/jwt"
)
type CommonStrategy struct {
oauth2.CoreStrategy
openid.OpenIDConnectTokenStrategy
}
func NewOAuth2HMACStrategy(config *Config, secret []byte) *oauth2.HMACSHAStrategy {
return &oauth2.HMACSHAStrategy{
Enigma: &hmac.HMACStrategy{
GlobalSecret: secret,
},
AccessTokenLifespan: config.GetAccessTokenLifespan(),
AuthorizeCodeLifespan: config.GetAuthorizeCodeLifespan(),
}
}
func NewOAuth2JWTStrategy(key *rsa.PrivateKey) *oauth2.RS256JWTStrategy {
return &oauth2.RS256JWTStrategy{
RS256JWTStrategy: &jwt.RS256JWTStrategy{
PrivateKey: key,
},
}
}
func NewOpenIDConnectStrategy(key *rsa.PrivateKey) *openid.DefaultStrategy {
return &openid.DefaultStrategy{
RS256JWTStrategy: &jwt.RS256JWTStrategy{
PrivateKey: key,
},
}
}