Conversation
These functions now live in io.
Export Auther to enable package consumers to directly set the authorization header of their requests. There are use cases where adding authorization transparently through http.Client is less desirable than just setting the header directly. Export Auther to allow for this use case.
dghubble
left a comment
There was a problem hiding this comment.
I think the more idiomatic approach would be to chain http.RoundTripper's to compose your own http.Client. Here's someone's blog with pointers.
The oauth1.Transport is already a http.RoundTripper, so we'd just need something similar to config.NewClient, such as a NewTransport that does the same thing but doesn't wrap the RoundTripper in an http.Client.
// NewTransport returns a new RoundTripper that signs requests via OAuth1.
func NewTransport(ctx context.Context, config *Config, token *Token) http.RoundTripper {
return &Transport{
Base: contextTransport(ctx),
source: StaticTokenSource(token),
auther: newAuther(config),
}
}In that sense, oauth1 would just provide a http.RoundTripper that's about the same as what NewClient does, but can be composed with any other RoundTrippers to your liking and used with your own http.Client. You should be able to try this out without any change to this library by using config.NewClient(...).Transport.
It doesn't seem right for this package to expose a Clock or to directly expose the internal auther struct. Also, it would be nice to have the cleanups as a separate change.
|
I agree that it's idiomatic to provide a In what we're working on, this is part of a request builder, so it's a bit out of left field to instead start wrapping the I understand though if that's not what you're going for here and it runs counter to the package. I can pull together a separate pull request with the other two items as well. |
Hello,
We've been using this package to authorize requests against an OAuth 1.0a API for a number of years, and it works great.
However, we're applying it to a new package, and it would be much more convenient to apply the authorization header directly when building the request. The existing usage requires creating a new
http.Clientwith the package'shttp.RoundTripper.The proposal here is to export
Autherand its key fields and methods. This doesn't affect existing usage.I've exported both Clock and Config to make it easier to test packages using
Auther(e.g. using a fixed clock).I've also replaced usage of
ioutilwithio, as it's deprecated, and resolved anunused value of errwarning inTestBaseURI.Thanks for writing and maintaining this package.