Skip to content
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

Share the http.Client in all methods that make a request #434

Open
sebastianfrh opened this issue Aug 14, 2024 · 0 comments
Open

Share the http.Client in all methods that make a request #434

sebastianfrh opened this issue Aug 14, 2024 · 0 comments

Comments

@sebastianfrh
Copy link

I apologize for bringing to the table a topic that has already been discussed, but I think the problem was not well understood.

When creating a Provider it is possible to configure a custom http.Client by sending it within the context.

It is saved in the Provider.client attribute, however, it is never used from there and it is necessary to set it again in the context every time we invoke a method of the provider that needs it.

I understand the clarifications that were made in other comments, for example: "The clients and options are passed through contexts to match Go's OAuth 2.0 package" (#402) and I agree that the current context must be sent to each of the methods that need it because it could be different from the context that was used to create the provider; but Go's OAuth 2.0 package does not have a "client" attribute for its config and the requests finally go out from internal and public functions, not methods, therefore they do not have a global configuration.

It doesn't seem correct to have to configure the http.Client again when it was already done when creating the provider and it is saved in an attribute of it, being available from there for all provider methods that have to make a request.

I think that the global configurations of the provider could be used in each of its methods, this would work as a helper to make the client's work simpler and more transparent, for example:

func (p *Provider) UserInfo(ctx context.Context, tokenSource oauth2.TokenSource) (*UserInfo, error) {
//...

    if p.client != nil {
        ClientContext(ctx, p.client)
    }
resp, err := doRequest(ctx, req)

    //...

}

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant