Skip to content

Commit

Permalink
compose: enable fosite composing with custom hashers. (#170)
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Hartstonge <matt@mykro.co.nz>
  • Loading branch information
matthewhartstonge authored and arekkas committed Jun 3, 2017
1 parent fe74027 commit d70d882
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 8 deletions.
9 changes: 7 additions & 2 deletions compose/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down Expand Up @@ -69,6 +72,8 @@ func ComposeAllEnabled(config *Config, storage interface{}, secret []byte, key *
CoreStrategy: NewOAuth2HMACStrategy(config, secret),
OpenIDConnectTokenStrategy: NewOpenIDConnectStrategy(key),
},
nil,

OAuth2AuthorizeExplicitFactory,
OAuth2AuthorizeImplicitFactory,
OAuth2ClientCredentialsGrantFactory,
Expand Down
2 changes: 1 addition & 1 deletion integration/authorize_code_grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion integration/authorize_implicit_grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion integration/client_credentials_grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion integration/introspect_token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
1 change: 1 addition & 0 deletions integration/refresh_token_grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func runRefreshTokenGrantTest(t *testing.T, strategy interface{}) {
new(compose.Config),
fositeStore,
strategy,
nil,
compose.OAuth2AuthorizeExplicitFactory,
compose.OAuth2RefreshTokenGrantFactory,
compose.OAuth2TokenIntrospectionFactory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion integration/revoke_token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit d70d882

Please sign in to comment.