Search code examples
google-plusgoogle-signingoogle-api-clientgoogle-auth-library

Google plus API shutdown, How it will affect Google auth2 login for web sites?


I am confused with shutdown notification mails from Google one of the recent mail mentioned as

projects directly requesting the “plus.me” scope are affected. This scope may have been listed in some emails, even if not directly requested by your project. We apologize for any confusion caused.

I am using following JS code for login, may I know will it affect anyway due to Google plus api shutdown?

<script async defer src="https://apis.google.com/js/api.js" onload="this.onload=function(){};HandleGoogleApiLibrary()" onreadystatechange="if (this.readyState === 'complete') this.onload()"></script>

<script type="text/javascript">
//google login starts
function HandleGoogleApiLibrary() {
    // Load "client" & "auth2" libraries
    gapi.load('client:auth2', {
        callback: function() {
            // Initialize client library
            // clientId & scope is provided => automatically initializes auth2 library
            gapi.client.init({
                apiKey: 'API KEY HERE',
                clientId: 'XXXXXXXXXXXXXXXXX.apps.googleusercontent.com',
                scope: 'https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email'                        
            }).then(
                // On success
                function(success) {
                    // After library is successfully loaded then enable the login button
                    //CODE AFTER SUCCESS
                }, 
                // On error
                function(error) {                    
                    alert('Error : Failed to Load Library');
                }
            );
        },
        onerror: function() {
            // Failed to load libraries
        }
    });
}

// Click on login button
$("#login-button").on('click', function() {
    // API call for Google login
    gapi.auth2.getAuthInstance().signIn().then(
        // On success
        function(success) {
            // API call to get user information
            gapi.client.request({ path: 'https://www.googleapis.com/plus/v1/people/me' }).then(
                // On success
                function(success) {
                    console.log(success);
                    var user_info = JSON.parse(success.body);                       
                    //VALIDATION                 
                },
                // On error
                function(error) {                                               
                    alert('Error : Failed to login');
                }
            );
        },
        // On error
        function(error) {
            $("#login-button").removeAttr('disabled');
            alert('Error : Login Failed');
        }
    );
});

Solution

  • There is good news and bad news.

    The good news is that you're not using any of the plus scopes.

    The bad news is that you're using the plus API, which is also being shut down, and which was mentioned in a previous email that should have been sent to you.

    Specifically, this chunk of code:

    gapi.client.request({ path: 'https://www.googleapis.com/plus/v1/people/me' }).then(
    

    calls the "plus.people.me" API.

    Fortunately, you should be able to switch to a different API, such as the "userinfo" API, by changing endpoints to

    https://www.googleapis.com/oauth2/v2/userinfo
    

    You may also wish to look into the more modern People API, which works very similarly, and is slightly more complicated, but can provide other profile fields.