-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NewClient documentation possibly contradicts implementation #324
Comments
You can try overriding the client. The context key is a bit hidden, but #321 talks about that. |
same question |
I recently opened a similar issue #564 not realizing this has been an open question for 2 years lol. what should we do if we want to configure client that makes non-token-exchange requests ? I need to have token exchange transport somehow injected in this: func NewClient() *http.Client {
return &http.Client{
Timeout: time.Second * 60,
Transport: &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
}).DialContext,
ForceAttemptHTTP2: true,
MaxIdleConns: 100,
MaxConnsPerHost: 100,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
},
}
} |
I agree, that whole section is invalid.
And in fact
In fact, the Hashicorp uses |
I also stumbled about this wrong documentation. Should be improved (together with #368) |
I also came across this. On a similar note: why do the
Specifically, I want to set the timeout on the returned client, but it's not clear to me why I'm not supposed to modify the client's timeout value, and what the alternative would be. Edit: For setting a timeout value, I suppose you could use |
Oof, I hit this today too. I did some experiments with every combination of ways you can mix a context and an HttpClient. The cases that might be surprising to users are:
Here's my data:
|
I submitted https://go-review.googlesource.com/c/oauth2/+/493335 to update the documentation to match implementation. |
also regarding the documentation and what @DRK3 wrote:
Why the returned client can't be modified?
|
@Av1shay Yes, I had exactly the same question. From my testing, it seems like setting the Timeout does indeed work as expected (at least for my test cases). I'm suspecting it's just a mistake in the docs, but I'm not 100% certain |
@DRK3 in the meantime I use this workaround
|
Same issue here. I have to do a HTTP request from a specific IP address. The only way I see to do it is via modifying the DialContext (see example below in which "123.456.789.123" is the IP address I want to use to make the request). Sadly when using oauth2 this is not possible anymore. Do you know a workaround until this is fixed?
|
@fosple I think you should pass client inside the context and it should work. So I do not remember exactly anymore, it is some time when I was implementing oauth2 using this library, but my issue was more about documentation and not that it is not possible to do it. |
It works. Thanks a lot @mitar! |
The documentation on
NewClient
states:Note that if a custom *http.Client is provided via the Context it is used only for token acquisition and is not used to configure the *http.Client returned from NewClient.
However, the implementation looks like it does use the Context-provided client as the underlying round tripper for the non-token-fetching requests. In fact, since the
TokenSource
is hardcoded as aReuseTokenSource
, it doesn't seem like the context-provided*http.Client
is used at all for token acquisition.Am I totally misreading this? Or is that contradictory, and thus should the documentation (or implementation) change?
If it's not contradictory,
*Config.NewClient
, doesn't seem to allow for configuration of the underlying transport for non-token-exchange requests. Its documentation even statesThe returned client and its Transport should not be modified.
, so it's unclear how I would configure a proxy server for the non-token-exchange requests, other than, perhaps, configuringhttp.DefaultClient
.The text was updated successfully, but these errors were encountered: