Skip to content

Commit

Permalink
chore(oauth): Switch from using basic auth to token when calling `int…
Browse files Browse the repository at this point in the history
…rospect`

# Issue

Basic auth has been deprecated when calling `introspect` and bearer
token auth is now recommended:
https://docs.cloudfoundry.org/api/uaa/version/77.19.0/index.html#introspect-token
  • Loading branch information
silvestre committed Dec 2, 2024
1 parent 2adc708 commit 57a2752
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/autoscaler/cf/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,8 @@ func (c *CtxClient) introspectToken(ctx context.Context, token string) (*Introsp
if err != nil {
return nil, err
}
request.SetBasicAuth(c.conf.ClientID, c.conf.Secret)

c.addAuth(ctx, request)
request.Header.Set("Content-Type", "application/x-www-form-urlencoded;charset=utf-8")

resp, err := c.Client.Do(request)
Expand All @@ -345,3 +346,13 @@ func (c *CtxClient) introspectToken(ctx context.Context, token string) (*Introsp

return introspectionResponse, nil
}

func (c *CtxClient) addAuth(ctx context.Context, req *http.Request) error {
tokens, err := c.GetTokens(ctx)
if err != nil {
return fmt.Errorf("get token failed: %w", err)
}

req.Header.Set("Authorization", TokenTypeBearer+" "+tokens.AccessToken)
return nil
}

0 comments on commit 57a2752

Please sign in to comment.