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.
Questions
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
Misc
Okay, the answer mostly sat in my client application--again, not Go--which had a few missing aspects in its OAuth2 request. (It also took a little effort to get the headers correct for the different requests.)
The best info for Reddit's OAuth2 process I found was here: http://www.reddit.com/r/redditdev/comments/197x36/using_oauth_to_send_valid_requests/
The response from Reddit still pings me asking for the ClientID and ClientSecret, which I am sure could be served via a proper ResponseWriter, though for the moment I am simply copy/pasting into a popup just so I can focus on something else!
When I get that squared away I will add to this answer.
If anyone is interested in any more information, please do not hesitate to ask.
Thanks again, TomWilde and Elithrar!
Checkout the martini-contrib page for an OAuth2 implementation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With