In my webapp I want to implement the following flow
- User clicks Log in with Google button
- User selects account in the redirected screen
- I recieve a JWT with the account ID and email address
- I set the account ID as login hint and set the prompt for 'consent' only
- I create the Auth URL and redirect to Google again for the consent
- In this next consent screen the user should only have to approve the consent and not select his account for the 2nd time
- I process the callback from the consent
According to the docs I implemented the callback from the "login with Google button" as following;
$payload = $client->verifyIdToken($id_token); //Process the JWT
if ($payload) {
$userid = $payload['sub']; //Get the user's unique Google ID
$client->setLoginHint($userid); //Set the user ID as hint for next consent
$client->setPrompt('consent'); //Set the approval prompt to consent only
$client->setScopes(...);
$client->setAccessType('offline');
$client->setRedirectUri(...);
//Create auth URL for consent
$auth_url = $client->createAuthUrl();
header('Location: ' . filter_var($auth_url, FILTER_SANITIZE_URL));
https://developers.google.com/identity/protocols/oauth2/web-server#creatingclient
Observed behavior:
- User clicks Login with Google button
- User clicks account & JWT is provided
- User is redirected to consent screen
- User has to select the account again <-- Unwanted behavior
- User agrees to the consent
- User is redirected to the callback
How do I implement this OAuth2 consent correctly so that I don't have to ask the user to select his account 2 times?