2

When I call gapi.auth.signIn it is called twice: before opening login popup and after user clicks login button. But in both cases authResponse parameter is not changed.

Here is my code sample:

gapi.auth.signIn({
  scope: 'https://www.googleapis.com/auth/plus.login',
  callback: function(authResponse) {
    console.log(authResponse);
  }
)};

And this is how authResponse object looks like in both cases

{
  client_id: /* my client id */
  cookie_policy: undefined
  error: "immediate_failed"
  error_subtype: "access_denied"
  expires_at: "1422353634"
  expires_in: "86400"
  g_user_cookie_policy: undefined
  issued_at: "1422267234"
  response_type: "token"
  scope: "https://www.googleapis.com/auth/plus.login"
  state: ""
  status: 
       {
         google_logged_in: false
         method: null
         signed_in: false
       }
 }

EDIT: Before sign in I try to check if user is already authorized in google, here is this code:

gapi.auth.authorize({
      client_id: _googleClientId,
      immediate: true,
      scope: 'https://www.googleapis.com/auth/plus.login'
    }, function(response) {
      if (response.status.signed_in) {
        connectGoogleSuccess(response);
      } else {
        gapi.auth.signIn({
          scope: 'https://www.googleapis.com/auth/plus.login',
          callback: function(authResponse) {
            console.log(authResponse);
          }
        )};
      }
    }
 );

How to make to change authResponse object properly after user clicked 'Login' button?

Any help is appreciated)

2
  • I am stuck with exactly this problem. Any workaround yet? Commented Mar 15, 2015 at 23:39
  • 1
    @VarunArora, sorry for long feedback, but I've found solution, it is described below, hope it will help you) Commented Apr 25, 2015 at 13:34

1 Answer 1

1

Okey, here is the workaround I've got.

  1. At first, I call gapi.auth.authorize method with using parameter "immediate"=true, so login popup won't be shown.

    gapi.auth.authorize({ client_id: _googleClientId, immediate: true, scope: 'https://www.googleapis.com/auth/plus.login' }, function(response) { if (response.status.signed_in) { connectGoogleSuccess(response); } else { connectGoogle(); } });

  2. Then I call again gapi.auth.authorize method with "immediate"=true, so user can input his credentials.

    connectGoogle() { gapi.auth.authorize({ client_id: _googleClientId, immediate: false, scope: 'https://www.googleapis.com/auth/plus.login' }, function(response) { if (response.status.signed_in) { connectGoogleSuccess(response); } }); };

Hope this will help someone!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.