fix(client/rs): do not error when issuer discovery has no introspection endpoint (#414)
* chore(tests): add basic unit tests for `pkg/client/rs/resource_server.go` * fix: do not error when issuer discovery has no introspection endpoint
This commit is contained in:
parent
fb891d8281
commit
406153a4f4
2 changed files with 230 additions and 4 deletions
|
@ -77,11 +77,15 @@ func newResourceServer(issuer string, authorizer func() (interface{}, error), op
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rs.tokenURL = config.TokenEndpoint
|
||||
rs.introspectURL = config.IntrospectionEndpoint
|
||||
if rs.tokenURL == "" {
|
||||
rs.tokenURL = config.TokenEndpoint
|
||||
}
|
||||
if rs.introspectURL == "" {
|
||||
rs.introspectURL = config.IntrospectionEndpoint
|
||||
}
|
||||
}
|
||||
if rs.introspectURL == "" || rs.tokenURL == "" {
|
||||
return nil, errors.New("introspectURL and/or tokenURL is empty: please provide with either `WithStaticEndpoints` or a discovery url")
|
||||
if rs.tokenURL == "" {
|
||||
return nil, errors.New("tokenURL is empty: please provide with either `WithStaticEndpoints` or a discovery url")
|
||||
}
|
||||
rs.authFn = authorizer
|
||||
return rs, nil
|
||||
|
@ -113,6 +117,9 @@ func WithStaticEndpoints(tokenURL, introspectURL string) Option {
|
|||
}
|
||||
|
||||
func Introspect(ctx context.Context, rp ResourceServer, token string) (*oidc.IntrospectionResponse, error) {
|
||||
if rp.IntrospectionURL() == "" {
|
||||
return nil, errors.New("resource server: introspection URL is empty")
|
||||
}
|
||||
authFn, err := rp.AuthFn()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue