Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions pkg/client/acr/acr.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const (
)

type Client struct {
Keyfunc keyfunc.Keyfunc
Options

cacheMu sync.Mutex
Expand Down Expand Up @@ -62,7 +63,17 @@ func New(opts Options) (*Client, error) {
return nil, errors.New("cannot specify refresh token as well as username/password")
}

var k keyfunc.Keyfunc
var err error
if opts.JWKSURI != "" {
k, err = keyfunc.NewDefaultCtx(context.TODO(), []string{opts.JWKSURI})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used the same context as what was being replaced. The keyfunc.NewDefault function can be used instead if no context is required. The context.Background() will be used by default.

if err != nil {
return nil, fmt.Errorf("failed to create keyfunc: %w", err)
}
}

return &Client{
Keyfunc: k,
Options: opts,
cachedACRClient: make(map[string]*acrClient),
}, nil
Expand Down Expand Up @@ -266,13 +277,8 @@ func (c *Client) getTokenExpiration(tokenString string) (time.Time, error) {
jwtParser := jwt.NewParser(jwt.WithoutClaimsValidation())
var token *jwt.Token
var err error
if c.JWKSURI != "" {
var k keyfunc.Keyfunc
k, err = keyfunc.NewDefaultCtx(context.TODO(), []string{c.JWKSURI})
if err != nil {
return time.Time{}, err
}
token, err = jwtParser.Parse(tokenString, k.Keyfunc)
if c.Keyfunc != nil {
token, err = jwtParser.Parse(tokenString, c.Keyfunc.Keyfunc)
} else {
token, _, err = jwtParser.ParseUnverified(tokenString, jwt.MapClaims{})
}
Expand Down
Loading