python ruby-programming-language Smalltalk Vue.js Knockoutjs TypeScript JavaScript, OOPs JavaScript Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 4 Angular 2 AngularJs 1.x NodeJs Perl Programming R Programming RequireJs Rust Programming Backbonejs closure programming language go-programming-language kotlin-programming-language
Firebase Features

How To Enable Facebook Authentication in Firebase?

Firebase - Facebook Authentication -
There are following steps involved to Enable Facebook Authentication in Firebase i.e.
1.     Enable Facebook Auth
2.     Create Facebook App
3.     Connect to Facebook SDK
4.     Create Buttons
5.     Create Auth Functions

Enable Facebook Auth –
In the Sign-In method tab, enable the Facebook sign-in method and specify the App-ID and App Secret you got from Facebook.

Create Facebook App –
For create facebook app, visit facebook’s developers site                              -https://developers.facebook.com/

Now, you find input field Valid OAuth redirect URIs where you need to copy the OAuth Redirect URI from Firebase.

Connect to Facebook SDK –
Use the below code to connect to Facebook
<script>
   window.fbAsyncInit = function() {
      FB.init ({
         appId      : 'APP_ID',
         xfbml      : true,
         version    : 'v2.6'
      });
   };

   (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 = "//connect.facebook.net/en_US/sdk.js";
      fjs.parentNode.insertBefore(js, fjs);
   } (document, 'script', 'facebook-jssdk'));
    
</script>

Create Buttons –
Use the below code to create buttons
<button onclick = "facebookSignIn()"> Signin </button>
<button onclick = "facebookSignOut()"> Signout </button>

Create Auth Functions –
Use the below code to create authentication functions
<script>
    var provider = new firebase.auth.FacebookAuthProvider();

    function facebookSignIn() {
    firebase.auth().signInWithPopup(provider)  
        .then(function(result) {
            var token = result.credential.accessToken;
            var user = result.user;           
        }).catch(function(error) {
            console.log(error.code);
            console.log(error.message);
        });
    }

    function facebookSignOut() {
    firebase.auth().signOut()  
        .then(function() {
            console.log('Successful Signout!');
        }, function(error) {
            console.log('Signout failed');
        });
    }
</script>

Stayed Informed - Firebase Tutorial for Android and IOS

I hope you are enjoying with this post! Please share with you friends. Thank you so much!
ANIL SINGH

Hi there! Welcome to my blog. My name is Anil Singh. I'm a author of this blog. For more detail about me, kindly refer to this link..
My Blogs - http://code-sample.com and http://code-sample.xyz
My Books - Interview Questions and Answers Books- Get Your Book in 15+ Digital Stores Worldwide..

You Might Also Like
www.code-sample.com/. Powered by Blogger.
ASK Questions