How to do native Google login in an Ionic 2 app?


#1

Google is changing their OAuth policy and we can no longer use the InAppBrowser plugin to handle the authentication flow. There’s a blog from Ionic that shows an alternative solution using the cordova-plugin-googleplus but currently it’s not working for me.

Does anyone knows other solutions, tutorials or plugins that do native Google authentication (without the InAppBrowser plugin)?


#2

Looking for the same. Any luck ?


#3

I use https://github.com/EddyVerbruggen/cordova-plugin-googleplus, and its working fine on my apps. You just need to put the RESERVED_CLIENT_ID


#4

I will try it out. Thank you.


#5

This is a working solution. ( Even thought Google.logout fails once I exit app and reopen )

import { Facebook , GooglePlus} from 'ionic-native'

     googleLogin(){
        let permissions =  {'webClientId':  "YOUR_ID.apps.googleusercontent.com" } ;
        return GooglePlus.login( permissions )
        .then( (res) => {
          console.log( res);
          let idToken = { id_token: res.idToken } ;
          return this.login( idToken ,'googleUrl').toPromise(); // handle app specific login
        }).catch( this.handleError );
      }

  logout(){
    switch (this.user.provider) {
      case "facebook":
      Facebook.logout().catch( this.handleError );
      break;
      case "google":
      GooglePlus.logout().catch( this.handleError );
    }
    let headers = this.httpHeader() ;
    this.storage.remove('user');
    this.user = null;
    return this.emailLogout( headers ); // handle app specific logout
  }