I have been banging my head for two days on this and am clearly missing something. I am a bit of a doofus on backend/server development and hoping someone can point me in the right direction.
- I have a desktop application (not Go) which makes an OAuth2 request from Reddit.
- The OAuth2 in my application is working just fine however the flow fails when Reddit hit the redirect URI on my own server.
- I am guessing it is waiting for the proper ResponseWriter result and none of my dozen incompetent attempts have worked.
- The redirect URI hits my server and callback function (below) then does nothing.
Questions
- Where am I going wrong?
- Is variable "t" my auth code and am I done (aka, you are a buffoon!)?
- Can I just write t's value to my non-Go app and be done?
- Or am I missing a step?
- Note: code slightly simplified.
Thanks!
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?
}
Points of reference
- Reddit API
- Reddit specific PHP example
- Reddit specific Python example
- Martini
- Go OAuth2
Misc
- Why Martini? It looks bloody great.
- Why not just Oauth2? Because I am ignorant.
- Why not PHP/Python? Because, c'mon! I am trying to learn Go. (I am loving it and getting some great results which enhances my UI work.)