我已經嘗試通過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 回答
- 0 關注
- 210 瀏覽
添加回答
舉報
0/150
提交
取消