I tried the following code example against facebook but it keeps redirecting me to oauth2error. I am following the directions exactly as per the example but it just doesn't seem to work. I am pretty new to golag but despite my best efforts I can't seem to make things work.
package main
import (
"log"
"net/http"
"github.com/go-martini/martini"
gooauth2 "github.com/golang/oauth2"
"github.com/martini-contrib/oauth2"
"github.com/martini-contrib/sessions"
)
func main() {
m := martini.Classic()
m.Use(sessions.Sessions("my_session", sessions.NewCookieStore([]byte("secret123"))))
m.Use(oauth2.Facebook(&gooauth2.Options{
ClientID: "XXXX",
ClientSecret: "XXXX",
RedirectURL: "http://localhost.foobar.com:8080/",
Scopes: []string{"public_profile"},
}))
m.Get("/", func(tokens oauth2.Tokens) string {
if tokens.IsExpired() {
return "not logged in, or the access token is expired"
}
return "logged in"
})
m.Get("/restrict", oauth2.LoginRequired, func(tokens oauth2.Tokens) string {
return tokens.Access()
})
m.Get("/success", oauth2.LoginRequired, func(tokens oauth2.Tokens) string {
return tokens.Access()
})
log.Fatal(http.ListenAndServe(":8080", m))
}
Can anyone point out what am i doing wrong here?
It looks like your callback url is not set correctly. See my similar config for github:
Try setting your redirect url to: