Skip to content

Commit

Permalink
bind main request context to tokeninfo requests so that the tokeninfo…
Browse files Browse the repository at this point in the history
… opentracing spans would be connected to the main request span (#1530)

Signed-off-by: Arpad Ryszka <[email protected]>
  • Loading branch information
aryszka authored Oct 1, 2020
1 parent 4e9ab17 commit 26b66a9
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions filters/auth/authclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ func (ac *authClient) Close() {
ac.cli.Close()
}

func bindContext(ctx filters.FilterContext, req *http.Request) *http.Request {
return req.WithContext(ctx.Request().Context())
}

func (ac *authClient) getTokenintrospect(token string, ctx filters.FilterContext) (tokenIntrospectionInfo, error) {
body := url.Values{}
body.Add(tokenKey, token)
Expand All @@ -68,6 +72,8 @@ func (ac *authClient) getTokenintrospect(token string, ctx filters.FilterContext
return nil, err
}

req = bindContext(ctx, req)

if ac.url.User != nil {
authorization := base64.StdEncoding.EncodeToString([]byte(ac.url.User.String()))
req.Header.Add("Authorization", fmt.Sprintf("Basic %s", authorization))
Expand Down Expand Up @@ -101,6 +107,9 @@ func (ac *authClient) getTokeninfo(token string, ctx filters.FilterContext) (map
if err != nil {
return doc, err
}

req = bindContext(ctx, req)

if token != "" {
req.Header.Set(authHeaderName, authHeaderPrefix+token)
}
Expand All @@ -126,6 +135,8 @@ func (ac *authClient) getWebhook(ctx filters.FilterContext) (*http.Response, err
if err != nil {
return nil, err
}

req = bindContext(ctx, req)
copyHeader(req.Header, ctx.Request().Header)

rsp, err := ac.cli.Do(req)
Expand Down

0 comments on commit 26b66a9

Please sign in to comment.