1
21
22 package compose
23
24 import (
25 "crypto/rsa"
26
27 "github.com/ory/fosite"
28 "github.com/ory/fosite/token/jwt"
29 )
30
31 type Factory func(config *Config, storage interface{}, strategy interface{}) interface{}
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55 func Compose(config *Config, storage interface{}, strategy interface{}, hasher fosite.Hasher, factories ...Factory) fosite.OAuth2Provider {
56 if hasher == nil {
57 hasher = &fosite.BCrypt{WorkFactor: config.GetHashCost()}
58 }
59
60 f := &fosite.Fosite{
61 Store: storage.(fosite.Storage),
62 AuthorizeEndpointHandlers: fosite.AuthorizeEndpointHandlers{},
63 TokenEndpointHandlers: fosite.TokenEndpointHandlers{},
64 TokenIntrospectionHandlers: fosite.TokenIntrospectionHandlers{},
65 RevocationHandlers: fosite.RevocationHandlers{},
66 Hasher: hasher,
67 ScopeStrategy: config.GetScopeStrategy(),
68 AudienceMatchingStrategy: config.GetAudienceStrategy(),
69 SendDebugMessagesToClients: config.SendDebugMessagesToClients,
70 TokenURL: config.TokenURL,
71 JWKSFetcherStrategy: config.GetJWKSFetcherStrategy(),
72 MinParameterEntropy: config.GetMinParameterEntropy(),
73 UseLegacyErrorFormat: config.UseLegacyErrorFormat,
74 ClientAuthenticationStrategy: config.GetClientAuthenticationStrategy(),
75 ResponseModeHandlerExtension: config.ResponseModeHandlerExtension,
76 MessageCatalog: config.MessageCatalog,
77 FormPostHTMLTemplate: config.FormPostHTMLTemplate,
78 }
79
80 for _, factory := range factories {
81 res := factory(config, storage, strategy)
82 if ah, ok := res.(fosite.AuthorizeEndpointHandler); ok {
83 f.AuthorizeEndpointHandlers.Append(ah)
84 }
85 if th, ok := res.(fosite.TokenEndpointHandler); ok {
86 f.TokenEndpointHandlers.Append(th)
87 }
88 if tv, ok := res.(fosite.TokenIntrospector); ok {
89 f.TokenIntrospectionHandlers.Append(tv)
90 }
91 if rh, ok := res.(fosite.RevocationHandler); ok {
92 f.RevocationHandlers.Append(rh)
93 }
94 }
95
96 return f
97 }
98
99
100 func ComposeAllEnabled(config *Config, storage interface{}, secret []byte, key *rsa.PrivateKey) fosite.OAuth2Provider {
101 return Compose(
102 config,
103 storage,
104 &CommonStrategy{
105 CoreStrategy: NewOAuth2HMACStrategy(config, secret, nil),
106 OpenIDConnectTokenStrategy: NewOpenIDConnectStrategy(config, key),
107 JWTStrategy: &jwt.RS256JWTStrategy{
108 PrivateKey: key,
109 },
110 },
111 nil,
112
113 OAuth2AuthorizeExplicitFactory,
114 OAuth2AuthorizeImplicitFactory,
115 OAuth2ClientCredentialsGrantFactory,
116 OAuth2RefreshTokenGrantFactory,
117 OAuth2ResourceOwnerPasswordCredentialsFactory,
118 RFC7523AssertionGrantFactory,
119
120 OpenIDConnectExplicitFactory,
121 OpenIDConnectImplicitFactory,
122 OpenIDConnectHybridFactory,
123 OpenIDConnectRefreshFactory,
124
125 OAuth2TokenIntrospectionFactory,
126 OAuth2TokenRevocationFactory,
127
128 OAuth2PKCEFactory,
129 )
130 }
131
View as plain text