I am working on implementing a client library for a remote API which uses 2-legged OAuth2 for authentication.
package main
import (
"net/http"
"golang.org/x/oauth2/clientcredentials"
"golang.org/x/net/context"
)
type SpecialClient struct {
*http.Client
}
func NewClient(cid, cis string) *SpecialClient {
tconf := clientcredentials.Config{
ClientID: cid,
ClientSecret: cis,
TokenURL: "http://some.remote.resource/token",
}
c := tconf.Client(context.Background())
return &SpecialClient{c}
}
func main() {
c := NewClient("clientID", "clientSecret")
c.Get("http://some.remote.resource/path/to/resource")
}
It is extremely straightforward. Right now, I think the remote API's OAuth2 implementation is broken, as it's not returning a token properly according to RFC 6749. I'm trying to debug the client creation with golang.org/x/oauth2/clientcredentials
, but I cannot determine at which point a token is fetched from the token URL. I've stepped through almost 100 calls with delve, and I do not see the client creating a new request to fetch a token. Is there a way I can review the request created by the *http.Client
used to retrieve the token?