diff --git a/dictionaries/cs.dictionary.itop.ui.php b/dictionaries/cs.dictionary.itop.ui.php index 5a9651419..7d91469f9 100755 --- a/dictionaries/cs.dictionary.itop.ui.php +++ b/dictionaries/cs.dictionary.itop.ui.php @@ -466,6 +466,8 @@ Dict::Add('CS CZ', 'Czech', 'Čeština', array( 'UI:Error:MaintenanceTitle' => 'Maintenance~~', 'UI:Error:InvalidToken' => 'Error: the requested operation has already been performed (CSRF token not found)~~', + 'UI:Error:SMTP:UnknownVendor' => 'OAuth SMTP provider %1$s does not exist (email_transport_smtp.oauth.provider)~~', + 'UI:GroupBy:Count' => 'Množství', 'UI:GroupBy:Count+' => 'Množství prvků', 'UI:CountOfObjects' => 'Počet objektů odpovídajícíh ktritériím: %1$d', diff --git a/dictionaries/da.dictionary.itop.ui.php b/dictionaries/da.dictionary.itop.ui.php index aa2c546d5..945a1fa12 100644 --- a/dictionaries/da.dictionary.itop.ui.php +++ b/dictionaries/da.dictionary.itop.ui.php @@ -453,6 +453,8 @@ Dict::Add('DA DA', 'Danish', 'Dansk', array( 'UI:Error:MaintenanceTitle' => 'Maintenance~~', 'UI:Error:InvalidToken' => 'Error: the requested operation has already been performed (CSRF token not found)~~', + 'UI:Error:SMTP:UnknownVendor' => 'OAuth SMTP provider %1$s does not exist (email_transport_smtp.oauth.provider)~~', + 'UI:GroupBy:Count' => 'Antal', 'UI:GroupBy:Count+' => 'Antal af elementer', 'UI:CountOfObjects' => '%1$d objekter opfylder kriteriet.', diff --git a/dictionaries/de.dictionary.itop.ui.php b/dictionaries/de.dictionary.itop.ui.php index 1ef51b3b5..21193745a 100644 --- a/dictionaries/de.dictionary.itop.ui.php +++ b/dictionaries/de.dictionary.itop.ui.php @@ -452,6 +452,8 @@ Dict::Add('DE DE', 'German', 'Deutsch', array( 'UI:Error:MaintenanceTitle' => 'Wartung', 'UI:Error:InvalidToken' => 'Error: the requested operation has already been performed (CSRF token not found)~~', + 'UI:Error:SMTP:UnknownVendor' => 'OAuth SMTP provider %1$s does not exist (email_transport_smtp.oauth.provider)~~', + 'UI:GroupBy:Count' => 'Anzahl', 'UI:GroupBy:Count+' => 'Anzahl der Elemente', 'UI:CountOfObjects' => '%1$d Objekte, die das Kriterium erfüllen.', diff --git a/dictionaries/en.dictionary.itop.ui.php b/dictionaries/en.dictionary.itop.ui.php index 18420b2d8..b6ddfcf7f 100644 --- a/dictionaries/en.dictionary.itop.ui.php +++ b/dictionaries/en.dictionary.itop.ui.php @@ -468,6 +468,8 @@ Dict::Add('EN US', 'English', 'English', array( 'UI:Error:MaintenanceTitle' => 'Maintenance', 'UI:Error:InvalidToken' => 'Error: the requested operation has already been performed (CSRF token not found)', + 'UI:Error:SMTP:UnknownVendor' => 'OAuth SMTP provider %1$s does not exist (email_transport_smtp.oauth.provider)', + 'UI:GroupBy:Count' => 'Count', 'UI:GroupBy:Count+' => 'Number of elements', 'UI:CountOfObjects' => '%1$d objects matching the criteria.', diff --git a/dictionaries/es_cr.dictionary.itop.ui.php b/dictionaries/es_cr.dictionary.itop.ui.php index b24fd05fb..c940bb277 100644 --- a/dictionaries/es_cr.dictionary.itop.ui.php +++ b/dictionaries/es_cr.dictionary.itop.ui.php @@ -465,6 +465,8 @@ Dict::Add('ES CR', 'Spanish', 'Español, Castellaño', array( 'UI:Error:MaintenanceTitle' => 'Mantenimiento', 'UI:Error:InvalidToken' => 'Error: the requested operation has already been performed (CSRF token not found)~~', + 'UI:Error:SMTP:UnknownVendor' => 'OAuth SMTP provider %1$s does not exist (email_transport_smtp.oauth.provider)~~', + 'UI:GroupBy:Count' => 'Cuenta', 'UI:GroupBy:Count+' => 'Número de Elementos', 'UI:CountOfObjects' => '%1$d Elementos cumplen Criterio.', diff --git a/dictionaries/fr.dictionary.itop.ui.php b/dictionaries/fr.dictionary.itop.ui.php index 344c75b98..c39162895 100644 --- a/dictionaries/fr.dictionary.itop.ui.php +++ b/dictionaries/fr.dictionary.itop.ui.php @@ -451,6 +451,8 @@ Dict::Add('FR FR', 'French', 'Français', array( 'UI:Error:MaintenanceTitle' => 'Maintenance', 'UI:Error:InvalidToken' => 'Erreur: l\'opération a déjà été effectuée (CSRF token not found)', + 'UI:Error:SMTP:UnknownVendor' => 'Le provider SMTP Oauth 2.0 %1$s n\'existe pas', + 'UI:GroupBy:Count' => 'Nombre', 'UI:GroupBy:Count+' => 'Nombre d\'éléments', 'UI:CountOfObjects' => '%1$d objets correspondants aux critères.', diff --git a/dictionaries/hu.dictionary.itop.ui.php b/dictionaries/hu.dictionary.itop.ui.php index b7b048515..8c8d2d0a6 100755 --- a/dictionaries/hu.dictionary.itop.ui.php +++ b/dictionaries/hu.dictionary.itop.ui.php @@ -451,6 +451,8 @@ Dict::Add('HU HU', 'Hungarian', 'Magyar', array( 'UI:Error:MaintenanceTitle' => 'Maintenance~~', 'UI:Error:InvalidToken' => 'Error: the requested operation has already been performed (CSRF token not found)~~', + 'UI:Error:SMTP:UnknownVendor' => 'OAuth SMTP provider %1$s does not exist (email_transport_smtp.oauth.provider)~~', + 'UI:GroupBy:Count' => 'Számossága', 'UI:GroupBy:Count+' => '', 'UI:CountOfObjects' => '%1$d darab objektum felel meg a kritériumoknak.', diff --git a/dictionaries/it.dictionary.itop.ui.php b/dictionaries/it.dictionary.itop.ui.php index f1a4f99c0..010995b19 100644 --- a/dictionaries/it.dictionary.itop.ui.php +++ b/dictionaries/it.dictionary.itop.ui.php @@ -464,6 +464,8 @@ Dict::Add('IT IT', 'Italian', 'Italiano', array( 'UI:Error:MaintenanceTitle' => 'Maintenance~~', 'UI:Error:InvalidToken' => 'Error: the requested operation has already been performed (CSRF token not found)~~', + 'UI:Error:SMTP:UnknownVendor' => 'OAuth SMTP provider %1$s does not exist (email_transport_smtp.oauth.provider)~~', + 'UI:GroupBy:Count' => 'Conteggio', 'UI:GroupBy:Count+' => '', 'UI:CountOfObjects' => '%1$d oggetti corrispondenti ai criteri.', diff --git a/dictionaries/ja.dictionary.itop.ui.php b/dictionaries/ja.dictionary.itop.ui.php index e30db1132..ec58e1697 100644 --- a/dictionaries/ja.dictionary.itop.ui.php +++ b/dictionaries/ja.dictionary.itop.ui.php @@ -451,6 +451,8 @@ Dict::Add('JA JP', 'Japanese', '日本語', array( 'UI:Error:MaintenanceTitle' => 'Maintenance~~', 'UI:Error:InvalidToken' => 'Error: the requested operation has already been performed (CSRF token not found)~~', + 'UI:Error:SMTP:UnknownVendor' => 'OAuth SMTP provider %1$s does not exist (email_transport_smtp.oauth.provider)~~', + 'UI:GroupBy:Count' => 'カウント', 'UI:GroupBy:Count+' => '要素数', 'UI:CountOfObjects' => '%1$d 個のオブジェクトが条件にマッチしました。', diff --git a/dictionaries/nl.dictionary.itop.ui.php b/dictionaries/nl.dictionary.itop.ui.php index 3c269cb75..011056ed1 100644 --- a/dictionaries/nl.dictionary.itop.ui.php +++ b/dictionaries/nl.dictionary.itop.ui.php @@ -470,6 +470,8 @@ Dict::Add('NL NL', 'Dutch', 'Nederlands', array( 'UI:Error:MaintenanceTitle' => 'Onderhoud', 'UI:Error:InvalidToken' => 'Error: the requested operation has already been performed (CSRF token not found)~~', + 'UI:Error:SMTP:UnknownVendor' => 'OAuth SMTP provider %1$s does not exist (email_transport_smtp.oauth.provider)~~', + 'UI:GroupBy:Count' => 'Aantal', 'UI:GroupBy:Count+' => 'Aantal objecten', 'UI:CountOfObjects' => '%1$d objecten voldoen aan de criteria.', diff --git a/dictionaries/pt_br.dictionary.itop.ui.php b/dictionaries/pt_br.dictionary.itop.ui.php index c0d934124..6a51d4410 100644 --- a/dictionaries/pt_br.dictionary.itop.ui.php +++ b/dictionaries/pt_br.dictionary.itop.ui.php @@ -464,6 +464,8 @@ Dict::Add('PT BR', 'Brazilian', 'Brazilian', array( 'UI:Error:MaintenanceTitle' => 'Maintenance~~', 'UI:Error:InvalidToken' => 'Error: the requested operation has already been performed (CSRF token not found)~~', + 'UI:Error:SMTP:UnknownVendor' => 'OAuth SMTP provider %1$s does not exist (email_transport_smtp.oauth.provider)~~', + 'UI:GroupBy:Count' => 'Número', 'UI:GroupBy:Count+' => 'Número de elementos', 'UI:CountOfObjects' => '%1$d objetos correspondem aos critérios.', diff --git a/dictionaries/ru.dictionary.itop.ui.php b/dictionaries/ru.dictionary.itop.ui.php index 1a10d0b74..c2b968113 100644 --- a/dictionaries/ru.dictionary.itop.ui.php +++ b/dictionaries/ru.dictionary.itop.ui.php @@ -443,6 +443,8 @@ Dict::Add('RU RU', 'Russian', 'Русский', array( 'UI:Error:MaintenanceTitle' => 'Техническое обслуживание', 'UI:Error:InvalidToken' => 'Error: the requested operation has already been performed (CSRF token not found)~~', + 'UI:Error:SMTP:UnknownVendor' => 'OAuth SMTP provider %1$s does not exist (email_transport_smtp.oauth.provider)~~', + 'UI:GroupBy:Count' => 'Количество', 'UI:GroupBy:Count+' => 'Количество элементов', 'UI:CountOfObjects' => '%1$d объектов соответствует критериям.', diff --git a/dictionaries/sk.dictionary.itop.ui.php b/dictionaries/sk.dictionary.itop.ui.php index 74290f499..854232778 100644 --- a/dictionaries/sk.dictionary.itop.ui.php +++ b/dictionaries/sk.dictionary.itop.ui.php @@ -451,6 +451,8 @@ Dict::Add('SK SK', 'Slovak', 'Slovenčina', array( 'UI:Error:MaintenanceTitle' => 'Maintenance~~', 'UI:Error:InvalidToken' => 'Error: the requested operation has already been performed (CSRF token not found)~~', + 'UI:Error:SMTP:UnknownVendor' => 'OAuth SMTP provider %1$s does not exist (email_transport_smtp.oauth.provider)~~', + 'UI:GroupBy:Count' => 'Počet', 'UI:GroupBy:Count+' => '', 'UI:CountOfObjects' => '%1$d objekt/y/ov sa nezhoduje s kritériami.', diff --git a/dictionaries/tr.dictionary.itop.ui.php b/dictionaries/tr.dictionary.itop.ui.php index f87d86e6b..32a7015d3 100644 --- a/dictionaries/tr.dictionary.itop.ui.php +++ b/dictionaries/tr.dictionary.itop.ui.php @@ -465,6 +465,8 @@ Dict::Add('TR TR', 'Turkish', 'Türkçe', array( 'UI:Error:MaintenanceTitle' => 'Maintenance~~', 'UI:Error:InvalidToken' => 'Error: the requested operation has already been performed (CSRF token not found)~~', + 'UI:Error:SMTP:UnknownVendor' => 'OAuth SMTP provider %1$s does not exist (email_transport_smtp.oauth.provider)~~', + 'UI:GroupBy:Count' => 'Say', 'UI:GroupBy:Count+' => 'Eleman sayısı', 'UI:CountOfObjects' => 'Kritere uyan %1$d nesne bulundu.', diff --git a/dictionaries/zh_cn.dictionary.itop.ui.php b/dictionaries/zh_cn.dictionary.itop.ui.php index ee498ef97..fc2cbd798 100644 --- a/dictionaries/zh_cn.dictionary.itop.ui.php +++ b/dictionaries/zh_cn.dictionary.itop.ui.php @@ -464,6 +464,8 @@ Dict::Add('ZH CN', 'Chinese', '简体中文', array( 'UI:Error:MaintenanceTitle' => '维护', 'UI:Error:InvalidToken' => 'Error: the requested operation has already been performed (CSRF token not found)~~', + 'UI:Error:SMTP:UnknownVendor' => 'OAuth SMTP provider %1$s does not exist (email_transport_smtp.oauth.provider)~~', + 'UI:GroupBy:Count' => '个数', 'UI:GroupBy:Count+' => '元素数量', 'UI:CountOfObjects' => '%1$d 个对象符合指定的条件.', diff --git a/sources/Core/Authentication/Client/OAuth/OAuthClientProviderFactory.php b/sources/Core/Authentication/Client/OAuth/OAuthClientProviderFactory.php index 8ede0f6fe..d484b26ba 100644 --- a/sources/Core/Authentication/Client/OAuth/OAuthClientProviderFactory.php +++ b/sources/Core/Authentication/Client/OAuth/OAuthClientProviderFactory.php @@ -2,47 +2,68 @@ namespace Combodo\iTop\Core\Authentication\Client\OAuth; +use CoreException; +use Dict; use GuzzleHttp\Client; use League\OAuth2\Client\Token\AccessTokenInterface; use MetaModel; -class OAuthClientProviderFactory { +class OAuthClientProviderFactory +{ + /** + * @return mixed + * @throws \CoreException + */ public static function getProviderForSMTP() { $sProviderVendor = MetaModel::GetConfig()->Get('email_transport_smtp.oauth.provider'); // email_transport_smtp.oauth.provider - $sProviderClass = "\Combodo\iTop\Core\Authentication\Client\OAuth\OAuthClientProvider".$sProviderVendor; + $sProviderClass = self::getProviderClass($sProviderVendor); $aProviderVendorParams = [ 'clientId' => MetaModel::GetConfig()->Get('email_transport_smtp.oauth.client_id'), // email_transport_smtp.oauth.client_id 'clientSecret' => MetaModel::GetConfig()->Get('email_transport_smtp.oauth.client_secret'),// email_transport_smtp.oauth.client_secret 'redirectUri' => $sProviderClass::GetRedirectUri(), - 'scope' => $sProviderClass::GetRequiredSMTPScope() + 'scope' => $sProviderClass::GetRequiredSMTPScope(), ]; $aAccessTokenParams = [ "access_token" => MetaModel::GetConfig()->Get('email_transport_smtp.oauth.access_token'), // email_transport_smtp.oauth.access_token "refresh_token" => MetaModel::GetConfig()->Get('email_transport_smtp.oauth.refresh_token'), // email_transport_smtp.oauth.refresh_token - 'scope' => $sProviderClass::GetRequiredSMTPScope() + 'scope' => $sProviderClass::GetRequiredSMTPScope(), ]; $aCollaborators = [ 'httpClient' => new Client(['verify' => false]), ]; - + return new $sProviderClass($aProviderVendorParams, $aCollaborators, $aAccessTokenParams); } - public static function getVendorProvider($sProviderVendor, $sClientId, $sClientSecret, $sScope, $aAdditional){ + + /** + * @param $sProviderVendor + * @param $sClientId + * @param $sClientSecret + * @param $sScope + * @param $aAdditional + * + * @return mixed + * @throws \CoreException + */ + public static function getVendorProvider($sProviderVendor, $sClientId, $sClientSecret, $sScope, $aAdditional) + { $sRedirectUrl = OAuthClientProviderAbstract::GetRedirectUri(); - $sProviderClass = "\Combodo\iTop\Core\Authentication\Client\OAuth\OAuthClientProvider".$sProviderVendor; + $sProviderClass = self::getProviderClass($sProviderVendor); $aCollaborators = [ 'httpClient' => new Client(['verify' => false]), ]; return new $sProviderClass(array_merge(['clientId' => $sClientId, 'clientSecret' => $sClientSecret, 'redirectUri' => $sRedirectUrl, 'scope' => $sScope], $aAdditional), $aCollaborators); } - - public static function getVendorProviderForAccessUrl($sProviderVendor, $sClientId, $sClientSecret, $sScope, $aAdditional){ + + public static function getVendorProviderForAccessUrl($sProviderVendor, $sClientId, $sClientSecret, $sScope, $aAdditional) + { $oProvider = static::getVendorProvider($sProviderVendor, $sClientId, $sClientSecret, $sScope, $aAdditional); + return $oProvider->GetVendorProvider()->getAuthorizationUrl([ 'scope' => [ - $sScope + $sScope, ], ]); } @@ -58,16 +79,33 @@ class OAuthClientProviderFactory { { return $oProvider->GetVendorProvider()->getAccessToken('authorization_code', ['code' => $sCode, 'scope' => $oProvider->GetScope()]); } - + public static function getConfFromRedirectUrl($sProviderVendor, $sClientId, $sClientSecret, $sRedirectUrlQuery) { $sRedirectUrl = OAuthClientProviderAbstract::GetRedirectUri(); - $sProviderClass = "\Combodo\iTop\Core\Authentication\Client\OAuth\OAuthClientProvider".$sProviderVendor; + $sProviderClass = self::getProviderClass($sProviderVendor); $aQuery = []; parse_str($sRedirectUrlQuery, $aQuery); $sCode = $aQuery['code']; $oProvider = new $sProviderClass(['clientId' => $sClientId, 'clientSecret' => $sClientSecret, 'redirectUri' => $sRedirectUrl]); + return $sProviderClass::getConfFromAccessToken($oProvider->GetVendorProvider()->getAccessToken('authorization_code', ['code' => $sCode]), $sClientId, $sClientSecret); } + /** + * @param $sProviderVendor + * + * @return string + * @throws \CoreException + */ + public static function getProviderClass($sProviderVendor): string + { + $sProviderClass = "\Combodo\iTop\Core\Authentication\Client\OAuth\OAuthClientProvider".$sProviderVendor; + if (!class_exists($sProviderClass)) { + throw new CoreException(dict::Format('UI:Error:SMTP:UnknownVendor', $sProviderVendor)); + } + + return $sProviderClass; + } + } \ No newline at end of file