hasProvider($providerId)) { $oAuth->cleanSession(); $log->fatal("The specified OAuth2 provider '$providerId' is not supported or not properly configured"); exit('The specified OAuth2 providers is not supported or not properly configured'); } if (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) { $oAuth->cleanSession(); exit('Invalid state'); } $code = $_GET['code'] ?? ''; $request = json_encode($_GET, JSON_THROW_ON_ERROR) ?? ''; $oAuth->log('debug', 'setExternalOAuthToken::request', $request); $token = $oAuth->getAccessToken($providerId, $code); if ($token === null) { exit('Not able to get access token. Check logs for more details'); } $mappedToken = $oAuth->mapToken($providerId, $token); $ss = new Sugar_Smarty(); $ss->assign('token', $mappedToken); $tpl = __DIR__ . '/../tpl/setToken.tpl'; echo $ss->fetch($tpl); exit;