Skip to content

Commit

Permalink
oauth2/introspection: configure core validator with access only option (
Browse files Browse the repository at this point in the history
ory#208)

Signed-off-by: Beorn Facchini <beornf@gmail.com>
  • Loading branch information
budougumi0617 committed Aug 21, 2017
1 parent adc482d commit a33a647
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
7 changes: 4 additions & 3 deletions compose/compose_oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ func OAuth2TokenRevocationFactory(config *Config, storage interface{}, strategy
// an access token and refresh token validator.
func OAuth2TokenIntrospectionFactory(config *Config, storage interface{}, strategy interface{}) interface{} {
return &oauth2.CoreValidator{
CoreStrategy: strategy.(oauth2.CoreStrategy),
CoreStorage: storage.(oauth2.CoreStorage),
ScopeStrategy: config.GetScopeStrategy(),
CoreStrategy: strategy.(oauth2.CoreStrategy),
CoreStorage: storage.(oauth2.CoreStorage),
ScopeStrategy: config.GetScopeStrategy(),
DisableRefreshTokenValidation: config.DisableRefreshTokenValidation,
}
}

Expand Down
3 changes: 3 additions & 0 deletions compose/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ type Config struct {
// HashCost sets the cost of the password hashing cost. Defaults to 12.
HashCost int

// DisableRefreshTokenValidation sets the introspection endpoint to disable refresh token validation.
DisableRefreshTokenValidation bool

ScopeStrategy fosite.ScopeStrategy
}

Expand Down
7 changes: 6 additions & 1 deletion handler/oauth2/introspector.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ import (
type CoreValidator struct {
CoreStrategy
CoreStorage
ScopeStrategy fosite.ScopeStrategy
ScopeStrategy fosite.ScopeStrategy
DisableRefreshTokenValidation bool
}

func (c *CoreValidator) IntrospectToken(ctx context.Context, token string, tokenType fosite.TokenType, accessRequest fosite.AccessRequester, scopes []string) (err error) {
if c.DisableRefreshTokenValidation {
return c.introspectAccessToken(ctx, token, accessRequest, scopes)
}

switch tokenType {
case fosite.RefreshToken:
if err = c.introspectRefreshToken(ctx, token, accessRequest, scopes); err == nil {
Expand Down
8 changes: 8 additions & 0 deletions handler/oauth2/introspector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ func TestIntrospectToken(t *testing.T) {
},
expectErr: fosite.ErrTokenExpired,
},
{
description: "should fail because access token invalid",
setup: func() {
v.DisableRefreshTokenValidation = true
chgen.EXPECT().ValidateAccessToken(nil, areq, "1234").Return(errors.WithStack(fosite.ErrInvalidTokenFormat))
},
expectErr: fosite.ErrInvalidTokenFormat,
},
{
description: "should pass",
setup: func() {
Expand Down

0 comments on commit a33a647

Please sign in to comment.