diff --git a/compose/compose.go b/compose/compose.go index e889b70be..5060ec579 100644 --- a/compose/compose.go +++ b/compose/compose.go @@ -30,14 +30,17 @@ type Factory func(config *Config, storage interface{}, strategy interface{}) int // ) // // Compose makes use of interface{} types in order to be able to handle a all types of stores, strategies and handlers. -func Compose(config *Config, storage interface{}, strategy interface{}, factories ...Factory) fosite.OAuth2Provider { +func Compose(config *Config, storage interface{}, strategy interface{}, hasher fosite.Hasher, factories ...Factory) fosite.OAuth2Provider { + if hasher == nil { + hasher = &fosite.BCrypt{WorkFactor: config.GetHashCost()} + } f := &fosite.Fosite{ Store: storage.(fosite.Storage), AuthorizeEndpointHandlers: fosite.AuthorizeEndpointHandlers{}, TokenEndpointHandlers: fosite.TokenEndpointHandlers{}, TokenIntrospectionHandlers: fosite.TokenIntrospectionHandlers{}, RevocationHandlers: fosite.RevocationHandlers{}, - Hasher: &fosite.BCrypt{WorkFactor: config.GetHashCost()}, + Hasher: hasher, ScopeStrategy: fosite.HierarchicScopeStrategy, } @@ -69,6 +72,8 @@ func ComposeAllEnabled(config *Config, storage interface{}, secret []byte, key * CoreStrategy: NewOAuth2HMACStrategy(config, secret), OpenIDConnectTokenStrategy: NewOpenIDConnectStrategy(key), }, + nil, + OAuth2AuthorizeExplicitFactory, OAuth2AuthorizeImplicitFactory, OAuth2ClientCredentialsGrantFactory, diff --git a/integration/authorize_code_grant_test.go b/integration/authorize_code_grant_test.go index e63b0ce80..14d6ac9ab 100644 --- a/integration/authorize_code_grant_test.go +++ b/integration/authorize_code_grant_test.go @@ -22,7 +22,7 @@ func TestAuthorizeCodeFlow(t *testing.T) { } func runAuthorizeCodeGrantTest(t *testing.T, strategy interface{}) { - f := compose.Compose(new(compose.Config), fositeStore, strategy, compose.OAuth2AuthorizeExplicitFactory, compose.OAuth2TokenIntrospectionFactory) + f := compose.Compose(new(compose.Config), fositeStore, strategy, nil, compose.OAuth2AuthorizeExplicitFactory, compose.OAuth2TokenIntrospectionFactory) ts := mockServer(t, f, &fosite.DefaultSession{}) defer ts.Close() diff --git a/integration/authorize_implicit_grant_test.go b/integration/authorize_implicit_grant_test.go index 31bcf3164..fb6adf080 100644 --- a/integration/authorize_implicit_grant_test.go +++ b/integration/authorize_implicit_grant_test.go @@ -26,7 +26,7 @@ func TestAuthorizeImplicitFlow(t *testing.T) { } func runTestAuthorizeImplicitGrant(t *testing.T, strategy interface{}) { - f := compose.Compose(new(compose.Config), fositeStore, strategy, compose.OAuth2AuthorizeImplicitFactory, compose.OAuth2TokenIntrospectionFactory) + f := compose.Compose(new(compose.Config), fositeStore, strategy, nil, compose.OAuth2AuthorizeImplicitFactory, compose.OAuth2TokenIntrospectionFactory) ts := mockServer(t, f, &fosite.DefaultSession{}) defer ts.Close() diff --git a/integration/client_credentials_grant_test.go b/integration/client_credentials_grant_test.go index 9e278d3c4..c9bae2ed6 100644 --- a/integration/client_credentials_grant_test.go +++ b/integration/client_credentials_grant_test.go @@ -20,7 +20,7 @@ func TestClientCredentialsFlow(t *testing.T) { } func runClientCredentialsGrantTest(t *testing.T, strategy oauth2.AccessTokenStrategy) { - f := compose.Compose(new(compose.Config), fositeStore, strategy, compose.OAuth2ClientCredentialsGrantFactory, compose.OAuth2TokenIntrospectionFactory) + f := compose.Compose(new(compose.Config), fositeStore, strategy, nil, compose.OAuth2ClientCredentialsGrantFactory, compose.OAuth2TokenIntrospectionFactory) ts := mockServer(t, f, &fosite.DefaultSession{}) defer ts.Close() diff --git a/integration/introspect_token_test.go b/integration/introspect_token_test.go index 55aaa282d..266f106d2 100644 --- a/integration/introspect_token_test.go +++ b/integration/introspect_token_test.go @@ -42,7 +42,7 @@ func TestIntrospectToken(t *testing.T) { } func runIntrospectTokenTest(t *testing.T, strategy oauth2.AccessTokenStrategy, introspectionFactory compose.Factory) { - f := compose.Compose(new(compose.Config), fositeStore, strategy, compose.OAuth2ClientCredentialsGrantFactory, introspectionFactory) + f := compose.Compose(new(compose.Config), fositeStore, strategy, nil, compose.OAuth2ClientCredentialsGrantFactory, introspectionFactory) ts := mockServer(t, f, &fosite.DefaultSession{}) defer ts.Close() diff --git a/integration/refresh_token_grant_test.go b/integration/refresh_token_grant_test.go index 65af99ec7..3e08eb2ce 100644 --- a/integration/refresh_token_grant_test.go +++ b/integration/refresh_token_grant_test.go @@ -27,6 +27,7 @@ func runRefreshTokenGrantTest(t *testing.T, strategy interface{}) { new(compose.Config), fositeStore, strategy, + nil, compose.OAuth2AuthorizeExplicitFactory, compose.OAuth2RefreshTokenGrantFactory, compose.OAuth2TokenIntrospectionFactory, diff --git a/integration/resource_owner_password_credentials_grant_test.go b/integration/resource_owner_password_credentials_grant_test.go index 085b2099e..6e98f14cd 100644 --- a/integration/resource_owner_password_credentials_grant_test.go +++ b/integration/resource_owner_password_credentials_grant_test.go @@ -20,7 +20,7 @@ func TestResourceOwnerPasswordCredentialsFlow(t *testing.T) { } func runResourceOwnerPasswordCredentialsGrantTest(t *testing.T, strategy hst.AccessTokenStrategy) { - f := compose.Compose(new(compose.Config), fositeStore, strategy, compose.OAuth2ResourceOwnerPasswordCredentialsFactory) + f := compose.Compose(new(compose.Config), fositeStore, strategy, nil, compose.OAuth2ResourceOwnerPasswordCredentialsFactory) ts := mockServer(t, f, &fosite.DefaultSession{}) defer ts.Close() diff --git a/integration/revoke_token_test.go b/integration/revoke_token_test.go index 829fbbe5a..039808927 100644 --- a/integration/revoke_token_test.go +++ b/integration/revoke_token_test.go @@ -23,7 +23,7 @@ func TestRevokeToken(t *testing.T) { } func runRevokeTokenTest(t *testing.T, strategy oauth2.AccessTokenStrategy) { - f := compose.Compose(new(compose.Config), fositeStore, strategy, compose.OAuth2ClientCredentialsGrantFactory, compose.OAuth2TokenIntrospectionFactory, compose.OAuth2TokenRevocationFactory) + f := compose.Compose(new(compose.Config), fositeStore, strategy, nil, compose.OAuth2ClientCredentialsGrantFactory, compose.OAuth2TokenIntrospectionFactory, compose.OAuth2TokenRevocationFactory) ts := mockServer(t, f, &fosite.DefaultSession{}) defer ts.Close()