Created
December 15, 2017 10:20
-
-
Save anonymous/94d9a3d8176e794ab7df96f80c685770 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 fbHandler(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