roll back
This commit is contained in:
parent
27cd482758
commit
0f467d1c42
@ -885,30 +885,6 @@ class CMailFile
|
|||||||
|
|
||||||
$storage = new DoliStorage($db, $conf);
|
$storage = new DoliStorage($db, $conf);
|
||||||
try {
|
try {
|
||||||
$tokenobj = $storage->retrieveAccessToken($OAUTH_SERVICENAME);
|
|
||||||
$expire = true;
|
|
||||||
// Is token expired or will token expire in the next 30 seconds
|
|
||||||
if (is_object($tokenobj)) {
|
|
||||||
$expire = ($tokenobj->getEndOfLife() !== -9002 && $tokenobj->getEndOfLife() !== -9001 && time() > ($tokenobj->getEndOfLife() - 30));
|
|
||||||
}
|
|
||||||
// Token expired so we refresh it
|
|
||||||
if (is_object($tokenobj) && $expire) {
|
|
||||||
$credentials = new Credentials(
|
|
||||||
getDolGlobalString('OAUTH_'.getDolGlobalString('MAIN_MAIL_SMTPS_OAUTH_SERVICE').'_ID'),
|
|
||||||
getDolGlobalString('OAUTH_'.getDolGlobalString('MAIN_MAIL_SMTPS_OAUTH_SERVICE').'_SECRET'),
|
|
||||||
getDolGlobalString('OAUTH_'.getDolGlobalString('MAIN_MAIL_SMTPS_OAUTH_SERVICE').'_URLAUTHORIZE')
|
|
||||||
);
|
|
||||||
$serviceFactory = new \OAuth\ServiceFactory();
|
|
||||||
$oauthname = explode('-', $OAUTH_SERVICENAME);
|
|
||||||
// ex service is Google-Emails we need only the first part Google
|
|
||||||
$apiService = $serviceFactory->createService($oauthname[0], $credentials, $storage, array());
|
|
||||||
// We have to save the token because Google give it only once
|
|
||||||
$refreshtoken = $tokenobj->getRefreshToken();
|
|
||||||
$tokenobj = $apiService->refreshAccessToken($tokenobj);
|
|
||||||
$tokenobj->setRefreshToken($refreshtoken);
|
|
||||||
$storage->storeAccessToken($OAUTH_SERVICENAME, $tokenobj);
|
|
||||||
}
|
|
||||||
|
|
||||||
$tokenobj = $storage->retrieveAccessToken($OAUTH_SERVICENAME);
|
$tokenobj = $storage->retrieveAccessToken($OAUTH_SERVICENAME);
|
||||||
if (is_object($tokenobj)) {
|
if (is_object($tokenobj)) {
|
||||||
$this->smtps->setToken($tokenobj->getAccessToken());
|
$this->smtps->setToken($tokenobj->getAccessToken());
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user