Which methods of Google OAuth2 API accept login_hint as a parameter

3.5k Views Asked by At

I am using the Google Sign-In JavaScript client and also referencing the Example App

The example app (app.js) tells me that login_hint is a valid option for the signIn method:

    // If the user is not signed in with expected account, let sign in.
return auth2.signIn({
  // Set `login_hint` to specify an intended user account,
  // otherwise user selection dialog will popup.
  login_hint: id || ''
});

But the reference manual does not say it does anything there but is only effective with the authorize() method. Elsewhere on the Web I see examples of it being also used with the init() method.

Can someone please clarify any/all places where the login_hint option is functionally active?

1

There are 1 best solutions below

0
On

From the login_hint

Optional. If your application knows which user is trying to authenticate, it can use this parameter to provide a hint to the Google Authentication Server. The server uses the hint to simplify the login flow either by prefilling the email field in the sign-in form or by selecting the appropriate multi-login session.

Set the parameter value to an email address or sub identifier, which is equivalent to the user's Google ID.

To set this value in PHP, call the setLoginHint function:

$client->setLoginHint('[email protected]');

Code for you:

options = new gapi.auth2.SigninOptionsBuilder();
options.setAppPackageName('com.example.app');
options.setFetchBasicProfile(True);
//options.setPrompt('select_account');
options.setLoginHint('[email protected]');
options.setScope('profile').setScope('email');

auth2.signIn(options);