我已经尝试通过golang.com/x/oauth2库成功使用 OAuth 进行身份验证。// provider variable is oauth2.Config// scope is: https://www.googleapis.com/auth/userinfo.emailurl := provider.AuthCodeURL(``) // redirect URL从客户端重定向回来后,我auth_code成功发送auth_code := ctx.Request.URL.RawQuery // code=XXXXif len(auth_code) > 5 { auth_code = auth_code[5:] // XXXX}tok, err := provider.Exchange(oauth2.NoContext, auth_code)if err == nil { client := provider.Client(oauth2.NoContext, tok) email_url := `https://www.googleapis.com/auth/userinfo.email` //Log.Describe(client) response, err := client.Get(email_url) if err == nil { ctx.Render(`login_oauth`, response) //handled = true }}//Log.Describe(err)我没有发现任何可以告诉response(Body空的)电子邮件部分的内容:{ "Status": "200 OK", "StatusCode": 200, "Proto": "HTTP/1.1", "ProtoMajor": 1, "ProtoMinor": 1, "Header": { "Alternate-Protocol": [ "443:quic,p=0.5" ], "Cache-Control": [ "private, max-age=0" ], "Content-Type": [ "text/plain" ], "Date": [ "Tue, 14 Apr 2015 05:52:17 GMT" ], "Expires": [ "Tue, 14 Apr 2015 05:52:17 GMT" ], "Server": [ "GSE" ], "X-Content-Type-Options": [ "nosniff" ], "X-Frame-Options": [ "SAMEORIGIN" ], "X-Xss-Protection": [ "1; mode=block" ] }, "Body": {}, // empty!!! "ContentLength": -1, "TransferEncoding": [ "chunked" ], "Close": false, "Trailer": null, "Request": { "Method": "GET", "URL": { "Scheme": "https", "Opaque": "", "User": null, "Host": "www.googleapis.com", "Path": "/auth/userinfo.email", "RawQuery": "", "Fragment": "" }, 第一个问题,如何正确获取邮箱?不使用 Google+ API。
1 回答
- 1 回答
- 0 关注
- 188 浏览
添加回答
举报
0/150
提交
取消