Skip to content

Commit

Permalink
compose: Pass ID Token configuration to strategy (ory#297)
Browse files Browse the repository at this point in the history
Resolves an issue where expiry and issuer where not properly configurable in the strategy.

See ory/hydra#985

Signed-off-by: arekkas <[email protected]>
  • Loading branch information
budougumi0617 committed Aug 22, 2018
1 parent 247fdfa commit 0950ce7
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion compose/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func ComposeAllEnabled(config *Config, storage interface{}, secret []byte, key *
storage,
&CommonStrategy{
CoreStrategy: NewOAuth2HMACStrategy(config, secret),
OpenIDConnectTokenStrategy: NewOpenIDConnectStrategy(key),
OpenIDConnectTokenStrategy: NewOpenIDConnectStrategy(config, key),
JWTStrategy: &jwt.RS256JWTStrategy{
PrivateKey: key,
},
Expand Down
4 changes: 3 additions & 1 deletion compose/compose_strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ func NewOAuth2JWTStrategy(key *rsa.PrivateKey, strategy *oauth2.HMACSHAStrategy)
}
}

func NewOpenIDConnectStrategy(key *rsa.PrivateKey) *openid.DefaultStrategy {
func NewOpenIDConnectStrategy(config *Config, key *rsa.PrivateKey) *openid.DefaultStrategy {
return &openid.DefaultStrategy{
JWTStrategy: &jwt.RS256JWTStrategy{
PrivateKey: key,
},
Expiry: config.GetIDTokenLifespan(),
Issuer: config.IDTokenIssuer,
}
}
5 changes: 4 additions & 1 deletion compose/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ type Config struct {
// AuthorizeCodeLifespan sets how long an authorize code is going to be valid. Defaults to fifteen minutes.
AuthorizeCodeLifespan time.Duration

// IDTokenLifespan sets how long an id token is going to be valid. Defaults to one hour.
// IDTokenLifespan sets the default id token lifetime. Defaults to one hour.
IDTokenLifespan time.Duration

// IDTokenIssuer sets the default issuer of the ID Token.
IDTokenIssuer string

// HashCost sets the cost of the password hashing cost. Defaults to 12.
HashCost int

Expand Down
2 changes: 1 addition & 1 deletion handler/openid/flow_explicit_token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestHandleTokenEndpointRequest(t *testing.T) {
h := &OpenIDConnectExplicitHandler{}
areq := fosite.NewAccessRequest(nil)
areq.Client = &fosite.DefaultClient{
//ResponseTypes: fosite.Arguments{"id_token"},
//ResponseTypes: fosite.Arguments{"id_token"},
}
assert.EqualError(t, h.HandleTokenEndpointRequest(nil, areq), fosite.ErrUnknownRequest.Error())
}
Expand Down

0 comments on commit 0950ce7

Please sign in to comment.