Evan, Thank you for your insight. I'm not an OAuth expert but the data swap seems suspect here.
When I use the Exchange() method to swap the 'code' response, the token returned is token [<nil>]
Interestingly, when I use the 'code' response in place of the token, I get back a '200 OK' but the data is 'userinfo.email' rather than the actual email address that is requested.
Although I don't expect a complete program solution, any help would be appreciated. Here's what I did:
Thank you, Robin
var (
googleOauthConfig = &oauth2.Config{
Endpoint: google.Endpoint,
}
)
// From POST
body := r.Body
buf, err := ioutil.ReadAll(body)
// Convert our []Byte buffer into a string
code := string( buf )
// 2016/11/23 13:28:41 [L2592] code [4/8-lbcODbzxjE937rXRUAtJUF_LYpzPAKxgM9i33dD2Y]
var ctx = newappengine.NewContext(r)
token, err := googleOauthConfig.Exchange(ctx, code)
// 2016/11/23 10:41:12 [L2632] token [<nil>]
client := &http.Client{
Transport: &oauth2.Transport{
Base: &newurlfetch.Transport{Context: ctx},
},
}
//Note: Intentional substitution of 'code' for 'token' as token response above is '<nil>'
defer resp.Body.Close()
bufBytes := make([]byte, 1024)
resp.Body.Read(bufBytes)
// 2016/11/23 13:09:44 [L2654] resp [&{200 OK 200 HTTP/1.1 1 1 map[X-Content-Type-Options:[nosniff]
// Expires:[Wed, 23 Nov 2016 19:09:47 GMT] Cache-Control:[private, max-age=0] Date:[Wed, 23 Nov 2016 19:09:47 GMT]
// Alt-Svc:[quic=":443"; ma=2592000; v="36,35,34"] Content-Type:[text/plain] X-Xss-Protection:[1; mode=block]
// Server:[GSE] X-Frame-Options:[SAMEORIGIN] Transfer-Encoding:[chunked]] 0xc0821a8560 14 [] true map[] 0xc0821c8000 <nil>}]
// 2016/11/23 13:09:44 [L2671] resp body close()
// 2016/11/23 13:09:44 [L2637] Resp body: userinfo.email
I note that the reference link provided was last updated two years ago, ref Jan 18, 2015
It appears OAuth2 had substantial changes after that post: