package main import ( "flag" "fmt" "net/http" "github.com/gorilla/mux" "github.com/markbates/goth" "github.com/markbates/goth/gothic" "github.com/markbates/goth/providers/facebook" "github.com/markbates/goth/providers/gplus" "github.com/markbates/goth/providers/twitter" ) var ( twitterKey = flag.String("twitter_key", "", "this is your twitter API key") twitterSecret = flag.String("twitter_secret", "", "this is your twitter secre") facebookKey = flag.String("facebook_key", "", "this is your facebook API key") facebookSecret = flag.String("facebook_secret", "", "this is your facebook API secret") gplusKey = flag.String("gplus_key", "", "this is your gplus API key") gplusSecret = flag.String("gplus_secret", "", "this is your gplus API secret") ) func main() { flag.Parse() goth.UseProviders( twitter.New(*twitterKey, *twitterSecret, "http://localhost:8888/auth/twitter/callback?provider=twitter"), facebook.New(*facebookKey, *facebookSecret, "http://localhost:8888/auth/twitter/callback?provider=facebook"), gplus.New(*gplusKey, *gplusSecret, "http://localhost:8888/auth/gplus/callback?provider=gplus"), ) gothic.GetState = func(r *http.Request) string { return r.URL.Query().Get("state") } r := mux.NewRouter() r.HandleFunc("/auth/{provider}/callback", func(w http.ResponseWriter, r *http.Request) { fmt.Println(gothic.GetState(r)) user, err := gothic.CompleteUserAuth(w, r) if err != nil { panic(err) } fmt.Fprintln(w, "logged in!", user) }) r.HandleFunc("/auth/{provider}", gothic.BeginAuthHandler) r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "

Click to log in with twitter

") fmt.Fprintf(w, "

Click to log in with facebook

") fmt.Fprintf(w, "

Click to log in with gplus

") }) http.ListenAndServe("localhost:8888", r) }