Skip to content

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

@sebastianfrh

Description

@sebastianfrh

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions