oauth2 icon indicating copy to clipboard operation
oauth2 copied to clipboard

Add a way to add custom headers to `conf.Client()` return value

Open klausman opened this issue 7 months ago • 0 comments

Specifically, I want to add some X-headers to the request made after the auth dance has been done. As it is, I can't: using client.Do() just throws away all the work done. and client.Post (or Get) does not allow for header mix-in. Unless there is a way to do this and I just can't find it in the docs?

My current code, adjusted for brevity:

ctx := context.Background()
conf := &clientcredentials.Config{
    ClientID: "some ID",
    ClientSecret: "some Secret",
    TokenURL: "https://thatserver/api/v1/oauth2/token",
}

client := conf.Client(ctx)
rqbody := strings.NewReader("mybody{}")
// ***HERE***
res, err := client.Post("https://thatserver/superapi/?includes=B4181000", "application/json", rqbody)
// ... handle error, parse response etc.

At the ***HERE*** mark is where I'd expect to be able to add more headers. Returning an error if I try to clobber any of the headers OAuth2 needs is fine.

klausman avatar Sep 06 '25 10:09 klausman