-
-
Save mchampaneri/afd45678a51f26ea95be90b650e31872 to your computer and use it in GitHub Desktop.
facebook oauth
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
////////////////////////////// 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