menu

Adding social login in ionic using Firebase

  • date_range 18/07/2015 00:00 info
    sort label
Steps to add social login button for github in ionic
  1. Create a new application in github from here.
  2. Once the GitHub app is created, we’ll take a client ID and a client secret and paste them into the GitHub authentication section in our Firebase app dashboard.
  3. Create a new app in ionic
  4.  $ ionic start myApp blank
     $ cd myApp
     $ ionic plugin add cordova-plugin-inappbrowser
     $ ionic add angularfire
    
  5.  Add the following files in ionic
  6.  <script src="lib/firebase/firebase.js"></script>
     <script src="lib/angularfire/dist/angularfire.min.js"></script>
    
  7. Inject Firebase as a dependency of your app as follow in app.js
  8.  angular.module('starter', ['ionic', 'firebase'])
    
  9. Inside contoller add the following function
  10.   $scope.loginGithub = function(authMethod) {
         var ref = new Firebase("https://gurinder.firebaseio.com");
         ref.authWithOAuthPopup("github", function(error, authDataGithub) {
           if (error) {
             console.log("Login Failed!", error);
           } else {
             $scope.authDataGithub = authDataGithub;
             console.log("Authenticated successfully with payload:", authDataGithub);
           }
         });
       };
    
  11. Call this function on button click inside HTML file
  12.  <ion-pane ng-controller="AppCtrl">
      <ion-content>
       <button class="button button-royal icon ion-social-github" ng-click="loginGithub()"></button>
      </ion-content>
     </ion-pane>
    
We need just few changes to Login using other social sites like facebook, twiiter etc. Refer to this link to do that.