loading
Please wait while loading...
Back Google Oauth 2.0 ask permission every time

I have made a application using google account for login. Reference to google's example, it's easy make the login work well. However, I'm face to a serious problem that google ask for permission approval every time. For a openid login, like facebook, we will ask permission in the first time only and for the next time, it should automatically complete the login and no need to approve by user again. For this purpose, I search from the internet and finally found the solution as following:

To make the application just ask permission for once, add the following line in the config

$client->setApprovalPrompt(auto);
 

Example for a full code:

require_once('src/Google_Client.php');
require_once 'src/contrib/Google_Oauth2Service.php';
$client = new Google_Client();
if ($client->getAccessToken()) {
  //alwaydy login redirect to user account
} else {
  $client->setApprovalPrompt(auto);
  $authUrl = $client->createAuthUrl();
}
Comments
comments powered by Disqus