From f1e45a3f694e2fbbe153fcbdc2d68857f90e8a0b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 13 Jan 2026 15:24:26 +0100 Subject: [PATCH] Fix add missing message once token has been saved --- .../modules/oauth/google_oauthcallback.php | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/htdocs/core/modules/oauth/google_oauthcallback.php b/htdocs/core/modules/oauth/google_oauthcallback.php index 7584f781f9a..4e4816d676e 100644 --- a/htdocs/core/modules/oauth/google_oauthcallback.php +++ b/htdocs/core/modules/oauth/google_oauthcallback.php @@ -249,16 +249,26 @@ if (!GETPOST('code')) { $db->begin(); - // This requests the token from the received OAuth code (call of the https://oauth2.googleapis.com/token endpoint) - // Result is stored into object managed by class DoliStorage into includes/OAuth/Common/Storage/DoliStorage.php and into database table llx_oauth_token - $token = $apiService->requestAccessToken(GETPOST('code'), $state); + try { + // This requests the token from the received OAuth code (call of the https://oauth2.googleapis.com/token endpoint) + // Result is stored into object managed by class DoliStorage into includes/OAuth/Common/Storage/DoliStorage.php and into database table llx_oauth_token + $token = $apiService->requestAccessToken(GETPOST('code'), $state); + } catch (Exception $e) { + dol_syslog("Failed to get token with requestAccessToken: ".$e->getMessage(), LOG_ERR); + setEventMessages("Failed to get token with requestAccessToken: ".$e->getMessage(), null, 'errors'); + $errorincheck++; + } // The refresh token is inside the object token if the prompt was forced only. //$refreshtoken = $token->getRefreshToken(); //var_dump($refreshtoken); + dol_syslog("requestAccessToken complete"); // Note: The extraparams has the 'id_token' than contains a lot of information about the user. - $extraparams = $token->getExtraParams(); + $extraparams = array(); + if ($token) { + $extraparams = $token->getExtraParams(); + } $jwt = explode('.', $extraparams['id_token']); $username = ''; @@ -347,6 +357,8 @@ if (!GETPOST('code')) { dol_syslog($errormessage); } + } else { + setEventMessages("TokenSaved", null); } } else { // If call back to url for a OAUTH2 login