我一直在敲打我的头两天,显然遗漏了一些东西。我对后端/服务器开发有一点想法,并希望有人能指出我正确的方向。
问题
谢谢!
package main
import (
"code.google.com/p/goauth2/oauth"
"fmt"
"github.com/codegangsta/martini"
"io"
"net/http"
)
var config = &oauth.Config{
ClientId: CLIENT_ID,
ClientSecret: CLIENT_SECRET,
Scope: "identify",
AuthURL: "https://ssl.reddit.com/api/v1/authorize",
TokenURL: "https://ssl.reddit.com/api/v1/access_token",
RedirectURL: "http://localhost:3000/reddit_oauth",
}
func main() {
m := martini.Classic()
m.Get("/reddit_oauth", handleCallback)
m.Run()
}
func handleCallback(w http.ResponseWriter, r *http.Request) {
//Get the code from the response
code := r.FormValue("code")
// Exchange the received code for a token
t := &oauth.Transport{Config: config}
t.Exchange(code)
// Am I done?
}
参考点
其它
答案 0 :(得分:1)
好的,答案主要在我的客户端应用程序中 - 再次,而不是Go - 其OAuth2请求中有一些缺少的方面。 (为了满足不同的请求,还需要花费一些精力才能使标头正确。)
我发现Reddit的OAuth2流程的最佳信息在这里:http://www.reddit.com/r/redditdev/comments/197x36/using_oauth_to_send_valid_requests/
Reddit的回复仍然要求我提出ClientID和ClientSecret,我相信可以通过正确的ResponseWriter提供服务,但目前我只是简单地复制/粘贴到弹出窗口,这样我就可以专注于其他事情了!
当我得到那个平方时,我会加上这个答案。
如果有人对更多信息感兴趣,请不要犹豫。
再次感谢TomWilde和Elithrar!
答案 1 :(得分:1)