From 57a2752c4a1b6bcded0e8826f2ffdf6ea83145ad Mon Sep 17 00:00:00 2001 From: Silvestre Zabala Date: Fri, 29 Nov 2024 18:29:34 +0100 Subject: [PATCH] chore(oauth): Switch from using basic auth to token when calling `introspect` # 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 --- src/autoscaler/cf/client.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/autoscaler/cf/client.go b/src/autoscaler/cf/client.go index a16a453608..dceb8dd3b8 100644 --- a/src/autoscaler/cf/client.go +++ b/src/autoscaler/cf/client.go @@ -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) @@ -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 +}