Adding google plus login to ionic app

Steps to Configure authentication in Device(android)

  1. ionic start newApp
  2. ionic platform add android
  3. cordova plugin add cordova-plugin-inappbrowser
  4. bower install ngCordova
  5. bower install ng-cordova-oauth -S
  6. include both script into index.html above cordova.js

    <script src="https://stackoverflow.com/questions/37523038/lib/ngCordova/dist/ng-cordova.min.js"></script>
    <script src="lib/ng-cordova-oauth/dist/ng-cordova-oauth.js"></script>
    <script src="https://stackoverflow.com/questions/37523038/cordova.js"></script>
    
  7. Dependency injection

  8. include below code

    $scope.googleLogin = function() {
    console.log('In My Method');
    $cordovaOauth.google("Client ID", ["https://www.googleapis.com/auth/urlshortener", "https://www.googleapis.com/auth/userinfo.email"]).then(function(result) {
        console.log(JSON.stringify(result));
        // results
    }, function(error) {
        // error
        console.log('In Error');
        console.log(error);
    });
    }
    
  9. add button to view file and call the function

Leave a Comment