Skip to content

Commit

Permalink
fix: remove token_type validation from introspection handler (#556)
Browse files Browse the repository at this point in the history
Closes #553
  • Loading branch information
daviddelucca authored Oct 18, 2020
1 parent 85df0e1 commit b18d90a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pipeline/authn/authenticator_oauth2_introspection.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ type AuthenticatorOAuth2IntrospectionResult struct {
ClientID string `json:"client_id,omitempty"`
Scope string `json:"scope,omitempty"`
Expires int64 `json:"exp"`
TokenUse string `json:"token_use"`
}

func (a *AuthenticatorOAuth2Introspection) tokenFromCache(config *AuthenticatorOAuth2IntrospectionConfiguration, token string) (*AuthenticatorOAuth2IntrospectionResult, bool) {
Expand Down Expand Up @@ -168,8 +169,8 @@ func (a *AuthenticatorOAuth2Introspection) Authenticate(r *http.Request, session
return errors.WithStack(err)
}

if len(i.TokenType) > 0 && i.TokenType != "access_token" {
return errors.WithStack(helper.ErrForbidden.WithReason(fmt.Sprintf("Introspected token is not an access token but \"%s\"", i.TokenType)))
if len(i.TokenUse) > 0 && i.TokenUse != "access_token" {
return errors.WithStack(helper.ErrForbidden.WithReason(fmt.Sprintf("Use of introspected token is not an access token but \"%s\"", i.TokenUse)))
}

if !i.Active {
Expand Down
21 changes: 21 additions & 0 deletions pipeline/authn/authenticator_oauth2_introspection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,27 @@ func TestAuthenticatorOAuth2Introspection(t *testing.T) {
},
expectErr: true,
},
{
d: "should fail because token use not matching",
r: &http.Request{Header: http.Header{"Authorization": {"bearer token"}}},
config: []byte(`{}`),
setup: func(t *testing.T, m *httprouter.Router) {
m.POST("/oauth2/introspect", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
require.NoError(t, r.ParseForm())
require.Equal(t, "token", r.Form.Get("token"))
require.NoError(t, json.NewEncoder(w).Encode(&AuthenticatorOAuth2IntrospectionResult{
Active: true,
Subject: "subject",
Audience: []string{"audience"},
Issuer: "issuer",
Username: "username",
Extra: map[string]interface{}{"extra": "foo"},
TokenUse: "any-token-use",
}))
})
},
expectErr: true,
},
{
d: "should pass",
r: &http.Request{Header: http.Header{"Authorization": {"bearer token"}}},
Expand Down

0 comments on commit b18d90a

Please sign in to comment.