Fix oauth2 token generation for Google. The refresh token was not

received.
This commit is contained in:
Laurent Destailleur 2017-01-17 20:05:10 +01:00
parent bb95f139a8
commit 82492dc023
3 changed files with 20 additions and 2 deletions

View File

@ -84,8 +84,11 @@ if ($action != 'delete' && empty($requestedpermissionsarray))
$apiService = $serviceFactory->createService('Google', $credentials, $storage, $requestedpermissionsarray);
// access type needed to have oauth provider refreshing token
// alos note that a refresh token is sent only after a prompt
$apiService->setAccessType('offline');
$apiService->setApprouvalPrompt('force');
$langs->load("oauth");

View File

@ -450,6 +450,7 @@ class printing_printgcp extends PrintingDriver
}
$responsedata = json_decode($response, true);
//$html .= '<pre>'.print_r($responsedata,true).'</pre>';
$html .= '<div class="div-table-responsive">';
$html .= '<table width="100%" class="noborder">';
$html .= '<tr class="liste_titre">';
$html .= '<td>'.$langs->trans("Id").'</td>';
@ -483,10 +484,11 @@ class printing_printgcp extends PrintingDriver
else
{
$html .= '<tr '.$bc[$var].'>';
$html .= '<td colspan="6" class="opacitymedium">'.$langs->trans("None").'</td>';
$html .= '<td colspan="7" class="opacitymedium">'.$langs->trans("None").'</td>';
$html .= '</tr>';
}
$html .= '</table>';
$html .= '</div>';
$this->resprint = $html;

View File

@ -140,12 +140,25 @@ class Google extends AbstractService
$this->accessType = $accessType;
}
// LDR CHANGE Add approval_prompt to force the prompt if value is set to 'force' so it force return of a "refresh token" in addition to "standard token"
public $approvalPrompt='auto';
public function setApprouvalPrompt($prompt)
{
if (!in_array($prompt, array('auto', 'force'), true)) {
// @todo Maybe could we rename this exception
throw new InvalidAccessTypeException('Invalid approuvalPrompt, expected either auto or force.');
}
$this->approvalPrompt = $prompt;
}
/**
* {@inheritdoc}
*/
public function getAuthorizationEndpoint()
{
return new Uri('https://accounts.google.com/o/oauth2/auth?access_type=' . $this->accessType);
// LDR CHANGE Add approval_prompt to force the prompt if value is set to 'force' so it force return of a "refresh token" in addition to "standard token"
//return new Uri('https://accounts.google.com/o/oauth2/auth?access_type='.$this->accessType);
return new Uri('https://accounts.google.com/o/oauth2/auth?'.($this->approvalPrompt?'approval_prompt='.$this->approvalPrompt.'&':'').'access_type='.$this->accessType);
}
/**