Return errors on nil credentials, move code around
Signed-off-by: Vartan Benohanian <vartanbeno@gmail.com>
This commit is contained in:
+3
-11
@@ -51,16 +51,8 @@ func (s *oauthTokenSource) Token() (*oauth2.Token, error) {
|
||||
}
|
||||
|
||||
func oauthTransport(client *Client) http.RoundTripper {
|
||||
// We need to set a custom user agent, because using the one set by default by the
|
||||
// stdlib gives us 429 Too Many Request responses from the Reddit API.
|
||||
userAgentTransport := &userAgentTransport{
|
||||
userAgent: client.UserAgent(),
|
||||
Base: client.client.Transport,
|
||||
}
|
||||
|
||||
httpClient := &http.Client{Transport: userAgentTransport}
|
||||
ctx := context.Background()
|
||||
ctx = context.WithValue(ctx, oauth2.HTTPClient, httpClient)
|
||||
httpClient := &http.Client{Transport: client.client.Transport}
|
||||
ctx := context.WithValue(context.Background(), oauth2.HTTPClient, httpClient)
|
||||
|
||||
config := &oauth2.Config{
|
||||
ClientID: client.ID,
|
||||
@@ -80,6 +72,6 @@ func oauthTransport(client *Client) http.RoundTripper {
|
||||
|
||||
return &oauth2.Transport{
|
||||
Source: tokenSource,
|
||||
Base: userAgentTransport,
|
||||
Base: client.client.Transport,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user