Skip to content

Instantly share code, notes, and snippets.

@mchampaneri
Forked from anonymous/facebook-auth.go
Created December 15, 2017 10:21
Show Gist options
  • Save mchampaneri/afd45678a51f26ea95be90b650e31872 to your computer and use it in GitHub Desktop.
Save mchampaneri/afd45678a51f26ea95be90b650e31872 to your computer and use it in GitHub Desktop.
facebook oauth
////////////////////////////// Routes /////////////////////////////////////////
routes.HandleFunc("/fb/auth",fbHandler)
//This route will process response returned from the facebook Oauth process
routes.HandleFunc("/fb/callback",fbCallbackHandler)
//////////////////////////// FbOauth Handler //////////////////////////////////
func fbHandler(w http.ResponseWriter, r *http.Request) {
// Get facebook access token.
conf := &oauth2.Config{
ClientID: "client id you get from the facebook app",
ClientSecret: "client secret of your facebook app",
RedirectURL: "your redirect url ", // Url that handels the response given
// after authentication from the facebook.
Scopes: []string{"email"}, // The permission you want for the app
Endpoint: oauth2fb.Endpoint,
}
url := conf.AuthCodeURL("state", oauth2.AccessTypeOffline)
http.Redirect(w, r, url, 301) // This will redirect to the facebook login page for
//authentication
}
///////////////////////////// FbOauthCallBack Handler ////////////////////////////////////
func fbCallBackHandler(w http.ResponseWriter, r *http.Request) {
// Handle it on your way
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment