E
E
Emil Revencu2018-03-25 20:25:21
Facebook
Emil Revencu, 2018-03-25 20:25:21

How to login to the site through Facebook?

Using Javascript FB SDK I get status='connected'

<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId      : 'app-id',
      cookie     : true,
      xfbml      : true,
      version    : 'v2.12'
    });
      
    FB.AppEvents.logPageView();   
  };

  (function(d, s, id){
     var js, fjs = d.getElementsByTagName(s)[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement(s); js.id = id;
     js.src = "https://connect.facebook.net/en_US/sdk.js";
     fjs.parentNode.insertBefore(js, fjs);
   }(document, 'script', 'facebook-jssdk'));

function facebook_login(){
  FB.login(function(response) {
    if (response.status === 'connected') 
    {
    var userID=response.authResponse.userID
      FB.api('/'+userID+'?fields=id,name,email,birthday,gender,picture', function(userinfo) 
      	{ 
                        console.log(userinfo.email)
      	});
    } 
    else 
    {}
    })
}
</script>

But how to find out on the backend that the user's email is in the database? Just checking the received email is not like - anyone can make such a request. Maybe FB is pinging some page on my site with some token?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Emil Revencu, 2018-03-25
@Revencu

I found a solution:
return the email on the backend via:

https://graph.facebook.com/me?fields=email&access_token={{token}}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question