diff --git a/dev/dolibarr_changes.txt b/dev/dolibarr_changes.txt
index 9f748af3c10..23f59227f7c 100644
--- a/dev/dolibarr_changes.txt
+++ b/dev/dolibarr_changes.txt
@@ -355,7 +355,9 @@ PHP PARSEDOWN
PHP OAUTH
---------
-Add into Class Google of file OAuth2/Service/Google:
+Restore old OAuth2/Service/Google.php file and OAuth2/Service/Microsoft.php and OAuth2/Service/Microsoft2.php
+
+Or add into Class Google of file OAuth2/Service/Google:
// 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';
@@ -369,6 +371,17 @@ Add into Class Google of file OAuth2/Service/Google:
}
+Modify function
+
+ public function getAuthorizationEndpoint()
+ {
+ // 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);
+ $url = 'https://accounts.google.com/o/oauth2/auth?'.($this->approvalPrompt?'approval_prompt='.$this->approvalPrompt.'&':'').'access_type='.$this->accessType;
+ return new Uri($url);
+ }
+
+
JS JSGANTT:
-----------
diff --git a/htdocs/admin/oauthlogintokens.php b/htdocs/admin/oauthlogintokens.php
index 47c76a3a928..505bf30b692 100644
--- a/htdocs/admin/oauthlogintokens.php
+++ b/htdocs/admin/oauthlogintokens.php
@@ -129,9 +129,12 @@ if ($action == 'refreshtoken' && $user->admin) {
try {
// $OAUTH_SERVICENAME is for example 'Google-keyforprovider'
print ''."\n";
+
+ dol_syslog("oauthlogintokens.php: Read token for service ".$OAUTH_SERVICENAME);
$tokenobj = $storage->retrieveAccessToken($OAUTH_SERVICENAME);
+
$expire = ($tokenobj->getEndOfLife() !== -9002 && $tokenobj->getEndOfLife() !== -9001 && time() > ($tokenobj->getEndOfLife() - 30));
- // We have to save the refresh token because Google give it only once
+ // We have to save the refresh token in a memory variable because Google give it only once
$refreshtoken = $tokenobj->getRefreshToken();
print '';
@@ -139,7 +142,6 @@ if ($action == 'refreshtoken' && $user->admin) {
//print $tokenobj->getAccessToken().'
';
//print $tokenobj->getRefreshToken().'
';
-
//var_dump($expire);
// We do the refresh even if not expired, this is the goal of action.
@@ -155,9 +157,14 @@ if ($action == 'refreshtoken' && $user->admin) {
if ($apiService instanceof OAuth\OAuth2\Service\AbstractService || $apiService instanceof OAuth\OAuth1\Service\AbstractService) {
// ServiceInterface does not provide refreshAccessToekn, AbstractService does
- $tokenobj = $apiService->refreshAccessToken($tokenobj);
+ dol_syslog("oauthlogintokens.php: call refreshAccessToken to get the new access token");
+ $tokenobj = $apiService->refreshAccessToken($tokenobj); // This call refresh and store the new token (but does not include the refresh token)
+
+ dol_syslog("oauthlogintokens.php: call setRefreshToken");
$tokenobj->setRefreshToken($refreshtoken); // Restore the refresh token
- $storage->storeAccessToken($OAUTH_SERVICENAME, $tokenobj);
+
+ dol_syslog("oauthlogintokens.php: call storeAccessToken to save the new access token + the old refresh token");
+ $storage->storeAccessToken($OAUTH_SERVICENAME, $tokenobj); // This save the new token including the refresh token
if ($expire) {
setEventMessages($langs->trans("OldTokenWasExpiredItHasBeenRefresh"), null, 'mesgs');
@@ -168,6 +175,7 @@ if ($action == 'refreshtoken' && $user->admin) {
dol_print_error($db, 'apiService is not a correct OAUTH2 Abstract service');
}
+ dol_syslog("oauthlogintokens.php: Read token again for service ".$OAUTH_SERVICENAME);
$tokenobj = $storage->retrieveAccessToken($OAUTH_SERVICENAME);
} catch (Exception $e) {
// Return an error if token not found
diff --git a/htdocs/includes/OAuth/Common/Http/Client/StreamClient.php b/htdocs/includes/OAuth/Common/Http/Client/StreamClient.php
index 9849afd4a32..e91288bbe0b 100644
--- a/htdocs/includes/OAuth/Common/Http/Client/StreamClient.php
+++ b/htdocs/includes/OAuth/Common/Http/Client/StreamClient.php
@@ -60,6 +60,13 @@ class StreamClient extends AbstractClient
//var_dump($requestBody); var_dump($extraHeaders);var_dump($method);exit;
$context = $this->generateStreamContext($requestBody, $extraHeaders, $method);
+ /*
+ var_dump($endpoint->getAbsoluteUri());
+ var_dump($requestBody);
+ var_dump($method);
+ var_dump($extraHeaders);
+ */
+
$level = error_reporting(0);
$response = file_get_contents($endpoint->getAbsoluteUri(), false, $context);
error_reporting($level);