Search code examples
google-plusgoogle-plus-signin

Prevent auto sign in with Google plus


I am trying to implement Google+ sign in for web sites.

My desired flow is:

  1. User lands on login page
  2. Clicks Google Sign In button
  3. I receive email and processing it on server side

The problem is, whatever script I try, Google always invoking and UNWANTED auto sign in. I want it to be initiated only when user clicks the button and prevent auto triggering google events.


Solution

  • The 'auto sign in' thing you mention is how the Google+ Sign In method functions by default. If you want full control of the sign in process, you need to use the Google Plus API and manually go through the whole OAuth process. I don't know what platform you're developing on but there are plenty of client libraries for the Google+ API.

    If you insist on using the Google+ JavaScript library, here's one option: The Google Plus Sign In button has a data-callback attribute. An object is passed into this callback function. That object has a status property which you can use to check whether the sign-in was made 'automatically' as you mention, or was made after the user clicked the sign-in button.

    function google_plus_signin_callback(authResult){
        if(authResult.status.method == 'AUTO'){
            // handle auto sign-in scenario
        }else if(authResult.status.method == 'PROMPT') {
            // handle user initiated sign-in scenario
        }
    }
    

    So if the user was signed in automatically, you can use the sign out method to sign her out or you can try doing something else depending on how you want your application to behave.