func main() { goth.UseProviders( twitter.New(os.Getenv("TWITTER_KEY"), os.Getenv("TWITTER_SECRET"), "http://localhost:3000/auth/twitter/callback"), facebook.New(os.Getenv("FACEBOOK_KEY"), os.Getenv("FACEBOOK_SECRET"), "http://localhost:3000/auth/facebook/callback"), gplus.New(os.Getenv("GPLUS_KEY"), os.Getenv("GPLUS_SECRET"), "http://localhost:3000/auth/gplus/callback"), github.New(os.Getenv("GITHUB_KEY"), os.Getenv("GITHUB_SECRET"), "http://localhost:3000/auth/github/callback"), spotify.New(os.Getenv("SPOTIFY_KEY"), os.Getenv("SPOTIFY_SECRET"), "http://localhost:3000/auth/spotify/callback"), linkedin.New(os.Getenv("LINKEDIN_KEY"), os.Getenv("LINKEDIN_SECRET"), "http://localhost:3000/auth/linkedin/callback"), lastfm.New(os.Getenv("LASTFM_KEY"), os.Getenv("LASTFM_SECRET"), "http://localhost:3000/auth/lastfm/callback"), ) // Assign the GetState function variable so we can return the // state string we want to get back at the end of the oauth process. // Only works with facebook and gplus providers. gothic.GetState = func(req *http.Request) string { // Get the state string from the query parameters. return req.URL.Query().Get("state") } p := pat.New() p.Get("/auth/{provider}/callback", func(res http.ResponseWriter, req *http.Request) { // print our state string to the console fmt.Println(gothic.GetState(req)) user, err := gothic.CompleteUserAuth(res, req) if err != nil { fmt.Fprintln(res, err) return } t, _ := template.New("foo").Parse(userTemplate) t.Execute(res, user) }) p.Get("/auth/{provider}", gothic.BeginAuthHandler) p.Get("/", func(res http.ResponseWriter, req *http.Request) { t, _ := template.New("foo").Parse(indexTemplate) t.Execute(res, nil) }) http.ListenAndServe(":3000", p) }
func linkedinProvider() *linkedin.Provider { return linkedin.New(os.Getenv("LINKEDIN_KEY"), os.Getenv("LINKEDIN_SECRET"), "/foo", "r_basicprofile", "r_emailaddress") }