Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Cordova plugin to login with Google Sign-In on iOS

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.08k
    Comment on it

    Hello Readers,

     

    In today's post we will learn about Cordova plugin to login with Google Sign-In on iOS. This plugin allow users with Google Sign-In on iOS application and you will get the user's profile information such as email, user id, profile name, profile picture URL. By using this plugin you can only access the Google Sign-In API.

     

    First of all, to access the Google Sign-In API we need to do some setup. For iOS application we need your application's package name. You can get the package name from your config.xml file.

     

    For Example:

     

    In config.xml

    <?xml version='1.0' encoding='utf-8'?>
    <widget id="com.demo">
    ...
    </widget>


    In the above example com.demo is the package name.

     

    Setup for iOS application: We need to generate a configuration file. To generate configuration file Click Here. You have to create or choose existing app and need to add their respective package name then click on the Choose and Configure Services. Now click on the Generate Configuration Files then download the GoogleService-Info.plist file. This file contains the Reversed Client Id. Which you'll need during plugin installation.

     

    Now we will move to the installation of plugin -

     

    Install plugin through CLI:

    $ cordova plugin add cordova-plugin-googleplus --save --variable REVERSED_CLIENT_ID=myreversedclientid

     

    Or from Github

     

    $ cordova plugin add https://github.com/EddyVerbruggen/cordova-plugin-googleplus --save --variable REVERSED_CLIENT_ID=myreversedclientid

     

    Now we will see the examples how we can use Google Sign-In on iOS:

     

    • For login:

     

    window.plugins.googleplus.login({
         'scopes': '',
         'webClientId': '',
         'offline': true,
    },function (obj) {
         console.log(JSON.stringify(obj));
    },function (msg) {
         console.log('error: ' + msg);
    });

     

    In the above example

    scopes  are optional, you can add list of scopes with space separated, defaults scopes are profile and email.

    webClientId Not required in iOS app.

     

    • Try Silent Login:  This function helps to check user is already signed in to the app and logged in silently. You will get the same object when succeeds.

     

    window.plugins.googleplus.trySilentLogin({
         'scopes': '',
         'webClientId': '',
         'offline': true,
    },function (obj) {
         console.log(JSON.stringify(obj));
    },function (msg) {
         console.log('error: ' + msg);
    });

     

    In the above example

    scopes  are optional, you can add list of scopes with space separated, defaults scopes are profile and email.

    webClientId Not required in iOS app.

     

    • logout: 

     

    window.plugins.googleplus.logout(
        function (msg) {
          console.log(msg);
        }
    );

    This function clears the OAuth2 token.

     

    For more details Click here. Hope this will help you :)

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: