From 48957fd2f02066672b933870412b25e57d50611e Mon Sep 17 00:00:00 2001 From: Eric Espie Date: Tue, 5 Jul 2022 17:37:49 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B05102=20-=20Allow=20to=20send=20emails=20?= =?UTF-8?q?using=20GSuite=20SMTP=20and=20OAuth=20-=20refactor=20scopes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr.dict.itop-core-update.php | 2 +- .../datamodel.itop-oauth-client.xml | 658 ++++++++++++++++-- .../en.dict.itop-oauth-client.php | 45 +- .../fr.dict.itop-oauth-client.php | 51 +- .../module.itop-oauth-client.php | 2 - .../src/Model/OAuthClientAzure.php | 128 ---- .../src/Model/OAuthClientGoogle.php | 134 ---- .../src/Service/PopupMenuExtension.php | 4 +- lib/autoload.php | 5 - lib/composer/ClassLoader.php | 2 +- lib/composer/autoload_classmap.php | 2 +- lib/composer/autoload_files.php | 10 +- lib/composer/autoload_namespaces.php | 2 +- lib/composer/autoload_psr4.php | 2 +- lib/composer/autoload_real.php | 30 +- lib/composer/autoload_static.php | 8 +- lib/composer/include_paths.php | 2 +- .../OAuth/OAuthClientProviderFactory.php | 4 +- 18 files changed, 712 insertions(+), 379 deletions(-) delete mode 100644 datamodels/2.x/itop-oauth-client/src/Model/OAuthClientAzure.php delete mode 100644 datamodels/2.x/itop-oauth-client/src/Model/OAuthClientGoogle.php diff --git a/datamodels/2.x/itop-core-update/fr.dict.itop-core-update.php b/datamodels/2.x/itop-core-update/fr.dict.itop-core-update.php index fb80f2644..29f39993c 100644 --- a/datamodels/2.x/itop-core-update/fr.dict.itop-core-update.php +++ b/datamodels/2.x/itop-core-update/fr.dict.itop-core-update.php @@ -73,7 +73,7 @@ Dict::Add('FR FR', 'French', 'Français', array( 'iTopUpdate:UI:CanCoreUpdate:ErrorFileNotExist' => 'Échec de la vérification des fichiers (Fichier manquant %1$s)', 'iTopUpdate:UI:CanCoreUpdate:Failed' => 'Échec de la vérification des fichiers', 'iTopUpdate:UI:CanCoreUpdate:Yes' => 'L\'application peut être mise à jour', - 'iTopUpdate:UI:CanCoreUpdate:No' => 'L\'application ne peut pas être mise à jour : %1$s', + 'iTopUpdate:UI:CanCoreUpdate:No' => 'L\'application ne peut pas être mise à jour : %1$s', 'iTopUpdate:UI:CanCoreUpdate:Warning' => 'Attention : la mise à jour de l\'application peut échouer : %1$s', 'iTopUpdate:UI:CannotUpdateUseSetup' => 'Des fichiers modifiés ont été détectés, une mise à jour partielle ne peut pas être effectuée.
Suivez la procedure pour mettre à jour manuellement votre iTop. Vous devez utiliser la page d\'installation pour mettre à jour l\'application.', 'iTopUpdate:UI:CheckInProgress'=>'Veuillez patienter pendant la vérification d\'intégrité', diff --git a/datamodels/2.x/itop-oauth-client/datamodel.itop-oauth-client.xml b/datamodels/2.x/itop-oauth-client/datamodel.itop-oauth-client.xml index a40a51436..b141584bb 100644 --- a/datamodels/2.x/itop-oauth-client/datamodel.itop-oauth-client.xml +++ b/datamodels/2.x/itop-oauth-client/datamodel.itop-oauth-client.xml @@ -105,22 +105,22 @@ public Overload-DBObject Get('scope'); - if ($this->Get('status') == 'inactive') { - $oPage->p(''.Dict::S('itop-oauth-client:Message:MissingToken').''); - } elseif (($sScope == 'SMTP' || $sScope == 'EMail') && $oConfig->Get('email_transport_smtp.username') == $this->Get('name')) { - $sLabel = Dict::S('itop-oauth-client:UsedForSMTP'); - $sTestLabel = Dict::S('itop-oauth-client:TestSMTP'); - $sTestURL = utils::GetAbsoluteUrlAppRoot().'setup/email.test.php'; - $oPage->p("$sLabel $sTestLabel"); - } - } - } + public function DisplayBareHeader(WebPage $oPage, $bEditMode = false) + { + parent::DisplayBareHeader($oPage, $bEditMode); + if (!$bEditMode) { + $oConfig = utils::GetConfig(); + $aScopes = $this->Get('scope')->GetValues(); + if ($this->Get('status') == 'inactive') { + $oPage->p(''.Dict::S('itop-oauth-client:Message:MissingToken').''); + } elseif (in_array('SMTP', $aScopes) && $oConfig->Get('email_transport_smtp.username') == $this->Get('name')) { + $sLabel = Dict::S('itop-oauth-client:UsedForSMTP'); + $sTestLabel = Dict::S('itop-oauth-client:TestSMTP'); + $sTestURL = utils::GetAbsoluteUrlAppRoot().'setup/email.test.php'; + $oPage->p("$sLabel $sTestLabel"); + } + } + } ]]> @@ -128,14 +128,14 @@ public Overload-DBObject @@ -143,68 +143,68 @@ public Overload-DBObject false public Get('provider').'.com'; - } + public function GetDefaultMailServer() + { + return 'imap.'.$this->Get('provider').'.com'; + } ]]> false public false public Get('status') == 'active') { - return new \League\OAuth2\Client\Token\AccessToken([ - 'access_token' => $this->Get('token'), - 'expires_in' => date_format(new DateTime($this->Get('token_expiration')), 'U') - time(), - 'refresh_token' => $this->Get('refresh_token'), - 'token_type' => 'Bearer', - ]); - } - return null; - } + public function GetAccessToken() + { + if ($this->Get('status') == 'active') { + return new \League\OAuth2\Client\Token\AccessToken([ + 'access_token' => $this->Get('token'), + 'expires_in' => date_format(new DateTime($this->Get('token_expiration')), 'U') - time(), + 'refresh_token' => $this->Get('refresh_token'), + 'token_type' => 'Bearer', + ]); + } + return null; + } ]]> false public Set('token', $oAccessToken->getToken()); - $this->Set('token_expiration', date(AttributeDateTime::GetSQLFormat(), $oAccessToken->getExpires())); - if (!empty($oAccessToken->getRefreshToken())) { - $this->Set('refresh_token', $oAccessToken->getRefreshToken()); - } - $this->Set('status', 'active'); - $this->DBUpdate(); - } + public function SetAccessToken(\League\OAuth2\Client\Token\AccessTokenInterface $oAccessToken) + { + $this->Set('token', $oAccessToken->getToken()); + $this->Set('token_expiration', date(AttributeDateTime::GetSQLFormat(), $oAccessToken->getExpires())); + if (!empty($oAccessToken->getRefreshToken())) { + $this->Set('refresh_token', $oAccessToken->getRefreshToken()); + } + $this->Set('status', 'active'); + $this->DBUpdate(); + } ]]> @@ -266,6 +266,544 @@ + + OAuthClient + + cloud,searchable + false + autoincrement + priv_oauth_client_azure + id + + + + + + + + + + + + + + + + + + + + + true + + + + + + + + true + + + + + + true + + SMTP + IMAP + + scope + SMTP,IMAP + true + + + advanced_scope + + true + + + true + + simple + advanced + + used_scope + simple + false + + + + + + + +
+ + + 10 + + + 10 + + + 10 + + + 20 + + + 30 + + + 40 + + + 50 + + + 60 + + + 70 + + + 80 + + + + + + + 20 + + + 10 + + + 10 + + + 20 + + + 30 + + + + + + +
+ + + + 10 + + + 10 + + + + + + + 10 + + + 10 + + + 10 + + + +
+ + + false + public + Overload-DBObject + Set('provider', 'Azure'); + $this->Set('redirect_url', Combodo\iTop\Core\Authentication\Client\OAuth\OAuthClientProviderFactory::GetRedirectUri()); + $this->Set('scope', 'SMTP, IMAP'); + + parent::PrefillCreationForm($aContextParam); + } + ]]> + + + false + public + Overload-DBObject + Get('provider'))) { + $this->Set('provider', 'Azure'); + } + if (empty($this->Get('redirect_url'))) { + $this->Set('redirect_url', Combodo\iTop\Core\Authentication\Client\OAuth\OAuthClientProviderFactory::GetRedirectUri()); + } + if (empty($this->Get('advanced_scope'))) { + $this->Set('used_scope', 'simple'); + if (count($this->Get('scope')->GetValues()) == 0) { + $this->Set('scope', 'SMTP, IMAP'); + } + } else { + $this->Set('used_scope', 'advanced'); + $this->Set('scope', ''); + } + } + ]]> + + + false + public + Overload-DBObject + + + + false + public + Overload-DBObject + + + + false + public + + + + false + public + Get('advanced_scope'))) { + return $this->Get('advanced_scope'); + } + $aScopes = $this->Get('scope')->GetValues(); + $aRawScopes = ['offline_access']; + foreach ($aScopes as $sScope) { + switch ($sScope) { + case 'SMTP': + $aRawScopes[] = 'https://outlook.office.com/SMTP.Send'; + break; + + case 'IMAP': + $aRawScopes[] = 'https://outlook.office.com/IMAP.AccessAsUser.All'; + break; + } + } + return implode(' ', $aRawScopes); + } + ]]> + + +
+ + OAuthClient + + cloud,searchable + false + autoincrement + priv_oauth_client_google + id + + + + + + + + + + + + + + + + + + + + + true + + + + + + + + true + + + + + + true + + SMTP + IMAP + + scope + SMTP,IMAP + true + + + advanced_scope + + true + + + true + + simple + advanced + + used_scope + simple + false + + + + + + + +
+ + + 10 + + + 10 + + + 10 + + + 20 + + + 30 + + + 40 + + + 50 + + + 60 + + + 70 + + + 80 + + + + + + + 20 + + + 10 + + + 10 + + + 20 + + + 30 + + + + + + +
+ + + + 10 + + + 10 + + + + + + + 10 + + + 10 + + + 10 + + + +
+ + + false + public + Overload-DBObject + Set('provider', 'Google'); + $this->Set('redirect_url', Combodo\iTop\Core\Authentication\Client\OAuth\OAuthClientProviderFactory::GetRedirectUri()); + $this->Set('scope', 'SMTP, IMAP'); + + parent::PrefillCreationForm($aContextParam); + } + ]]> + + + false + public + Overload-DBObject + Get('provider'))) { + $this->Set('provider', 'Google'); + } + if (empty($this->Get('redirect_url'))) { + $this->Set('redirect_url', Combodo\iTop\Core\Authentication\Client\OAuth\OAuthClientProviderFactory::GetRedirectUri()); + } + if (empty($this->Get('advanced_scope'))) { + $this->Set('used_scope', 'simple'); + if (count($this->Get('scope')->GetValues()) == 0) { + $this->Set('scope', 'SMTP, IMAP'); + } + } else { + $this->Set('used_scope', 'advanced'); + $this->Set('scope', ''); + } + } + ]]> + + + false + public + Overload-DBObject + + + + false + public + Overload-DBObject + + + + false + public + + + + false + public + Get('advanced_scope'))) { + return $this->Get('advanced_scope'); + } + $aScopes = $this->Get('scope')->GetValues(); + $aRawScopes = []; + foreach ($aScopes as $sScope) { + switch ($sScope) { + case 'SMTP': + $aRawScopes['https://mail.google.com/'] = 'https://mail.google.com/'; + break; + + case 'IMAP': + $aRawScopes['https://mail.google.com/'] = 'https://mail.google.com/'; + break; + } + } + return implode(' ', $aRawScopes); + } + ]]> + + +
diff --git a/datamodels/2.x/itop-oauth-client/en.dict.itop-oauth-client.php b/datamodels/2.x/itop-oauth-client/en.dict.itop-oauth-client.php index 1a91fb173..510e01cbe 100644 --- a/datamodels/2.x/itop-oauth-client/en.dict.itop-oauth-client.php +++ b/datamodels/2.x/itop-oauth-client/en.dict.itop-oauth-client.php @@ -21,6 +21,9 @@ Dict::Add('EN US', 'English', 'English', [ 'itop-oauth-client:Message:MissingToken' => 'Generate access token before using this OAuth client', 'itop-oauth-client:Message:TokenCreated' => 'Access token created', 'itop-oauth-client:Message:TokenRecreated' => 'Access token regenerated', + + 'OAuthClient:baseinfo' => 'Base Information', + 'OAuthClient:scope' => 'Scope', ]); // @@ -33,8 +36,6 @@ Dict::Add('EN US', 'English', 'English', [ 'Class:OAuthClient/Attribute:provider+' => '', 'Class:OAuthClient/Attribute:name' => 'Login', 'Class:OAuthClient/Attribute:name+' => '', - 'Class:OAuthClient/Attribute:scope' => 'Scope', - 'Class:OAuthClient/Attribute:scope+' => '', 'Class:OAuthClient/Attribute:status' => 'Status', 'Class:OAuthClient/Attribute:status+' => '', 'Class:OAuthClient/Attribute:status/Value:active' => 'Access token generated', @@ -62,17 +63,45 @@ Dict::Add('EN US', 'English', 'English', [ // // Class: OAuthClientAzure // -Dict::Add('EN US', 'English', 'English', [ + +Dict::Add('EN US', 'English', 'English', array( 'Class:OAuthClientAzure' => 'OAuth client for Microsoft Azure', 'Class:OAuthClientAzure/Name' => '%1$s (%2$s)', - -]); + 'Class:OAuthClientAzure/Attribute:scope' => 'Scope', + 'Class:OAuthClientAzure/Attribute:scope+' => '', + 'Class:OAuthClientAzure/Attribute:scope/Value:SMTP' => 'SMTP', + 'Class:OAuthClientAzure/Attribute:scope/Value:SMTP+' => '', + 'Class:OAuthClientAzure/Attribute:scope/Value:IMAP' => 'IMAP', + 'Class:OAuthClientAzure/Attribute:scope/Value:IMAP+' => '', + 'Class:OAuthClientAzure/Attribute:advanced_scope' => 'Advanced scope', + 'Class:OAuthClientAzure/Attribute:advanced_scope+' => '', + 'Class:OAuthClientAzure/Attribute:used_scope' => 'Used scope', + 'Class:OAuthClientAzure/Attribute:used_scope+' => '', + 'Class:OAuthClientAzure/Attribute:used_scope/Value:simple' => 'Simple', + 'Class:OAuthClientAzure/Attribute:used_scope/Value:simple+' => '', + 'Class:OAuthClientAzure/Attribute:used_scope/Value:advanced' => 'Advanced', + 'Class:OAuthClientAzure/Attribute:used_scope/Value:advanced+' => '', +)); // // Class: OAuthClientGoogle // -Dict::Add('EN US', 'English', 'English', [ + +Dict::Add('EN US', 'English', 'English', array( 'Class:OAuthClientGoogle' => 'OAuth client for Google', 'Class:OAuthClientGoogle/Name' => '%1$s (%2$s)', -]); - + 'Class:OAuthClientGoogle/Attribute:scope' => 'Scope', + 'Class:OAuthClientGoogle/Attribute:scope+' => '', + 'Class:OAuthClientGoogle/Attribute:scope/Value:SMTP' => 'SMTP', + 'Class:OAuthClientGoogle/Attribute:scope/Value:SMTP+' => '', + 'Class:OAuthClientGoogle/Attribute:scope/Value:IMAP' => 'IMAP', + 'Class:OAuthClientGoogle/Attribute:scope/Value:IMAP+' => '', + 'Class:OAuthClientGoogle/Attribute:advanced_scope' => 'Advanced scope', + 'Class:OAuthClientGoogle/Attribute:advanced_scope+' => '', + 'Class:OAuthClientGoogle/Attribute:used_scope' => 'Used scope', + 'Class:OAuthClientGoogle/Attribute:used_scope+' => '', + 'Class:OAuthClientGoogle/Attribute:used_scope/Value:simple' => 'Simple', + 'Class:OAuthClientGoogle/Attribute:used_scope/Value:simple+' => '', + 'Class:OAuthClientGoogle/Attribute:used_scope/Value:advanced' => 'Advanced', + 'Class:OAuthClientGoogle/Attribute:used_scope/Value:advanced+' => '', +)); diff --git a/datamodels/2.x/itop-oauth-client/fr.dict.itop-oauth-client.php b/datamodels/2.x/itop-oauth-client/fr.dict.itop-oauth-client.php index e8461b535..82837874b 100644 --- a/datamodels/2.x/itop-oauth-client/fr.dict.itop-oauth-client.php +++ b/datamodels/2.x/itop-oauth-client/fr.dict.itop-oauth-client.php @@ -20,6 +20,9 @@ Dict::Add('FR FR', 'French', 'Français', [ 'itop-oauth-client:Message:MissingToken' => 'Générez le jeton d\'accès avant d\'utiliser ce client OAuth', 'itop-oauth-client:Message:TokenCreated' => 'Le jeton d\'accès à été créé', 'itop-oauth-client:Message:TokenRecreated' => 'Le jeton d\'accès à été renouvelé', + + 'OAuthClient:baseinfo' => 'Information', + 'OAuthClient:scope' => 'Scope', ]); // @@ -32,8 +35,10 @@ Dict::Add('FR FR', 'French', 'Français', [ 'Class:OAuthClient/Attribute:provider+' => '', 'Class:OAuthClient/Attribute:name' => 'Login', 'Class:OAuthClient/Attribute:name+' => '', - 'Class:OAuthClient/Attribute:scope' => 'Niveaux d\'accès', - 'Class:OAuthClient/Attribute:scope+' => '', + 'Class:OAuthClient/Attribute:status' => 'Statut', + 'Class:OAuthClient/Attribute:status+' => '', + 'Class:OAuthClient/Attribute:status/Value:active' => 'Jeton d\'accès créé', + 'Class:OAuthClient/Attribute:status/Value:inactive' => 'Pas de jeton d\'accès', 'Class:OAuthClient/Attribute:description' => 'Description', 'Class:OAuthClient/Attribute:description+' => '', 'Class:OAuthClient/Attribute:client_id' => 'ID Client', @@ -57,22 +62,44 @@ Dict::Add('FR FR', 'French', 'Français', [ // // Class: OAuthClientAzure // -Dict::Add('FR FR', 'French', 'Français', [ + +Dict::Add('FR FR', 'French', 'Français', array( 'Class:OAuthClientAzure' => 'Client OAuth pour Microsoft Azure', 'Class:OAuthClientAzure/Name' => '%1$s (%2$s)', - -]); + 'Class:OAuthClientAzure/Attribute:scope' => 'Niveaux d\'accès', + 'Class:OAuthClientAzure/Attribute:scope+' => '', + 'Class:OAuthClientAzure/Attribute:scope/Value:SMTP' => 'SMTP', + 'Class:OAuthClientAzure/Attribute:scope/Value:SMTP+' => '', + 'Class:OAuthClientAzure/Attribute:scope/Value:IMAP' => 'IMAP', + 'Class:OAuthClientAzure/Attribute:scope/Value:IMAP+' => '', + 'Class:OAuthClientAzure/Attribute:advanced_scope' => 'Niveaux d\'accès avancé', + 'Class:OAuthClientAzure/Attribute:advanced_scope+' => '', + 'Class:OAuthClientAzure/Attribute:used_scope' => 'Niveaux d\'accès utilisés', + 'Class:OAuthClientAzure/Attribute:used_scope+' => '', + 'Class:OAuthClientAzure/Attribute:used_scope/Value:simple' => 'Simple', + 'Class:OAuthClientAzure/Attribute:used_scope/Value:simple+' => '', + 'Class:OAuthClientAzure/Attribute:used_scope/Value:advanced' => 'Avancé', + 'Class:OAuthClientAzure/Attribute:used_scope/Value:advanced+' => '', +)); // // Class: OAuthClientGoogle // -Dict::Add('FR FR', 'French', 'Français', [ + +Dict::Add('FR FR', 'French', 'Français', array( 'Class:OAuthClientGoogle' => 'Client OAuth pour Google', 'Class:OAuthClientGoogle/Name' => '%1$s (%2$s)', -]); - - -// Additional language entries not present in English dict -Dict::Add('FR FR', 'French', 'Français', array( - 'Class:OAuthClient/Name' => '%1$s-%%2$~', + 'Class:OAuthClientGoogle/Attribute:scope' => 'Niveaux d\'accès', + 'Class:OAuthClientGoogle/Attribute:scope+' => '', + 'Class:OAuthClientGoogle/Attribute:scope/Value:SMTP' => 'SMTP', + 'Class:OAuthClientGoogle/Attribute:scope/Value:SMTP+' => '', + 'Class:OAuthClientGoogle/Attribute:scope/Value:IMAP' => 'IMAP', + 'Class:OAuthClientGoogle/Attribute:scope/Value:IMAP+' => '', + 'Class:OAuthClientGoogle/Attribute:advanced_scope' => 'Niveaux d\'accès avancé', + 'Class:OAuthClientGoogle/Attribute:advanced_scope+' => '', + 'Class:OAuthClientGoogle/Attribute:used_scope' => 'Niveaux d\'accès utilisés', + 'Class:OAuthClientGoogle/Attribute:used_scope+' => '', + 'Class:OAuthClientGoogle/Attribute:used_scope/Value:simple' => 'Simple', + 'Class:OAuthClientGoogle/Attribute:used_scope/Value:advanced' => 'Avancé', + 'Class:OAuthClientGoogle/Attribute:used_scope/Value:advanced+' => '', )); diff --git a/datamodels/2.x/itop-oauth-client/module.itop-oauth-client.php b/datamodels/2.x/itop-oauth-client/module.itop-oauth-client.php index 632ede130..e0c681df8 100644 --- a/datamodels/2.x/itop-oauth-client/module.itop-oauth-client.php +++ b/datamodels/2.x/itop-oauth-client/module.itop-oauth-client.php @@ -25,8 +25,6 @@ SetupWebPage::AddModule( 'datamodel' => array( 'vendor/autoload.php', 'model.itop-oauth-client.php', // Contains the PHP code generated by the "compilation" of datamodel.remote-authent-oauth.xml - 'src/Model/OAuthClientGoogle.php', - 'src/Model/OAuthClientAzure.php', 'src/Service/PopupMenuExtension.php', ), 'webservice' => array( diff --git a/datamodels/2.x/itop-oauth-client/src/Model/OAuthClientAzure.php b/datamodels/2.x/itop-oauth-client/src/Model/OAuthClientAzure.php deleted file mode 100644 index eb798e64d..000000000 --- a/datamodels/2.x/itop-oauth-client/src/Model/OAuthClientAzure.php +++ /dev/null @@ -1,128 +0,0 @@ - 'cloud', - 'key_type' => 'autoincrement', - 'name_attcode' => ['name', 'scope'], - 'state_attcode' => '', - 'reconc_keys' => ['provider', 'name'], - 'db_table' => 'priv_oauth_client_azure', - 'db_key_field' => 'id', - 'icon' => utils::GetAbsoluteUrlModulesRoot().'itop-oauth-client/assets/img/icons8-azure.svg', - 'db_finalclass_field' => '', - 'uniqueness_rules' => [ - 'Username for scope' => - [ - 'attributes' => ['name', 'scope'], - 'filter' => null, - 'disabled' => false, - 'is_blocking' => true, - ], - 'OAuth Server' => - [ - 'attributes' => ['provider', 'scope', 'client_id', 'client_secret'], - 'filter' => null, - 'disabled' => false, - 'is_blocking' => true, - ], - ], - ]; - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeEnum('scope', [ - 'allowed_values' => new ValueSetEnum('EMail'), - 'display_style' => 'list', - 'sql' => 'scope', - 'default_value' => 'EMail', - 'is_null_allowed' => false, - 'depends_on' => [], - 'always_load_in_tables' => true, - ])); - - MetaModel::Init_SetZListItems('details', [ - 'name', - 'status', - 'description', - 'provider', - 'scope', - 'redirect_url', - 'client_id', - 'client_secret', - 'mailbox_list', - ]); - MetaModel::Init_SetZListItems('standard_search', [ - 'name', - 'provider', - 'status', - ]); - MetaModel::Init_SetZListItems('list', [ - 'status', - 'provider', - ]); - } - - public function PrefillCreationForm(&$aContextParam) - { - $this->Set('provider', 'Azure'); - $this->Set('redirect_url', OAuthClientProviderFactory::GetRedirectUri()); - - parent::PrefillCreationForm($aContextParam); - } - - /** - * Compute read-only values - * - * @return void - * @throws \ArchivedObjectException - * @throws \CoreException - * @throws \CoreUnexpectedValue - */ - public function ComputeValues() - { - parent::ComputeValues(); - if (empty($this->Get('provider'))) { - $this->Set('provider', 'Azure'); - } - if (empty($this->Get('redirect_url'))) { - $this->Set('redirect_url', OAuthClientProviderFactory::GetRedirectUri()); - } - } - - public function GetAttributeFlags($sAttCode, &$aReasons = array(), $sTargetState = '') - { - if ($sAttCode == 'provider' || $sAttCode == 'redirect_url') { - return OPT_ATT_READONLY; - } - - return parent::GetAttributeFlags($sAttCode, $aReasons, $sTargetState); - } - - public function GetInitialStateAttributeFlags($sAttCode, &$aReasons = array()) - { - if ($sAttCode == 'provider' || $sAttCode == 'redirect_url') { - return OPT_ATT_READONLY; - } - - return parent::GetInitialStateAttributeFlags($sAttCode, $aReasons); - } - - public function GetDefaultMailServer() - { - return 'outlook.office365.com'; - } - - public function GetScope() - { - return 'https://outlook.office.com/IMAP.AccessAsUser.All https://outlook.office.com/SMTP.Send offline_access'; - } -} \ No newline at end of file diff --git a/datamodels/2.x/itop-oauth-client/src/Model/OAuthClientGoogle.php b/datamodels/2.x/itop-oauth-client/src/Model/OAuthClientGoogle.php deleted file mode 100644 index 83c111852..000000000 --- a/datamodels/2.x/itop-oauth-client/src/Model/OAuthClientGoogle.php +++ /dev/null @@ -1,134 +0,0 @@ - 'cloud', - 'key_type' => 'autoincrement', - 'name_attcode' => ['name', 'scope'], - 'state_attcode' => '', - 'reconc_keys' => ['provider', 'name'], - 'db_table' => 'priv_oauth_client_google', - 'db_key_field' => 'id', - 'icon' => utils::GetAbsoluteUrlModulesRoot().'itop-oauth-client/assets/img/icons8-google.svg', - 'db_finalclass_field' => '', - 'uniqueness_rules' => [ - 'Username for scope' => - [ - 'attributes' => ['name', 'scope'], - 'filter' => null, - 'disabled' => false, - 'is_blocking' => true, - ], - 'OAuth Server' => - [ - 'attributes' => ['provider', 'scope', 'client_id', 'client_secret'], - 'filter' => null, - 'disabled' => false, - 'is_blocking' => true, - ], - ], - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeEnum('scope', [ - 'allowed_values' => new ValueSetEnum('EMail'), - 'display_style' => 'list', - 'sql' => 'scope', - 'default_value' => 'EMail', - 'is_null_allowed' => false, - 'depends_on' => [], - 'always_load_in_tables' => true, - ])); - - MetaModel::Init_SetZListItems('details', [ - 'name', - 'status', - 'description', - 'provider', - 'scope', - 'redirect_url', - 'client_id', - 'client_secret', - 'mailbox_list', - ]); - MetaModel::Init_SetZListItems('standard_search', [ - 'name', - 'provider', - 'status', - ]); - MetaModel::Init_SetZListItems('list', [ - 'status', - 'provider', - ]); - } - - public function PrefillCreationForm(&$aContextParam) - { - $this->Set('provider', 'Google'); - $this->Set('scope', 'EMail'); - $this->Set('redirect_url', OAuthClientProviderFactory::GetRedirectUri()); - - parent::PrefillCreationForm($aContextParam); - } - - public function GetAttributeFlags($sAttCode, &$aReasons = array(), $sTargetState = '') - { - if ($sAttCode == 'provider' || $sAttCode == 'scope' || $sAttCode == 'redirect_url') { - return OPT_ATT_READONLY; - } - - return parent::GetAttributeFlags($sAttCode, $aReasons, $sTargetState); - } - - public function GetInitialStateAttributeFlags($sAttCode, &$aReasons = array()) - { - if ($sAttCode == 'provider' || $sAttCode == 'scope' || $sAttCode == 'redirect_url') { - return OPT_ATT_READONLY; - } - - return parent::GetInitialStateAttributeFlags($sAttCode, $aReasons); - } - - /** - * Compute read-only values - * - * @return void - * @throws \ArchivedObjectException - * @throws \CoreException - * @throws \CoreUnexpectedValue - */ - public function ComputeValues() - { - parent::ComputeValues(); - if (empty($this->Get('provider'))) { - $this->Set('provider', 'Google'); - } - if (empty($this->Get('redirect_url'))) { - $this->Set('redirect_url', OAuthClientProviderFactory::GetRedirectUri()); - } - if (empty($this->Get('scope'))) { - $this->Set('scope', 'EMail'); - } - } - - - public function GetDefaultMailServer() - { - return 'imap.gmail.com'; - } - - public function GetScope() - { - return 'https://mail.google.com/'; - } -} \ No newline at end of file diff --git a/datamodels/2.x/itop-oauth-client/src/Service/PopupMenuExtension.php b/datamodels/2.x/itop-oauth-client/src/Service/PopupMenuExtension.php index 6ca4783b4..31189de73 100644 --- a/datamodels/2.x/itop-oauth-client/src/Service/PopupMenuExtension.php +++ b/datamodels/2.x/itop-oauth-client/src/Service/PopupMenuExtension.php @@ -51,8 +51,8 @@ class PopupMenuExtension implements \iPopupMenuExtension ); if ($bHasToken) { - $sScope = $oObj->Get('scope'); - if ($sScope == 'EMail') { + $aScopes = $oObj->Get('scope')->GetValues(); + if (in_array('IMAP', $aScopes)) { $aParams = $oAppContext->GetAsHash(); $sMenu = 'Menu:CreateMailbox'; $sObjClass = get_class($oObj); diff --git a/lib/autoload.php b/lib/autoload.php index 64168f99a..79c1600b5 100644 --- a/lib/autoload.php +++ b/lib/autoload.php @@ -2,11 +2,6 @@ // autoload.php @generated by Composer -if (PHP_VERSION_ID < 50600) { - echo 'Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.'.PHP_EOL; - exit(1); -} - require_once __DIR__ . '/composer/autoload_real.php'; return ComposerAutoloaderInit0018331147de7601e7552f7da8e3bb8b::getLoader(); diff --git a/lib/composer/ClassLoader.php b/lib/composer/ClassLoader.php index afef3fa2a..0cd6055d1 100644 --- a/lib/composer/ClassLoader.php +++ b/lib/composer/ClassLoader.php @@ -149,7 +149,7 @@ class ClassLoader /** * @return string[] Array of classname => path - * @psalm-return array + * @psalm-var array */ public function getClassMap() { diff --git a/lib/composer/autoload_classmap.php b/lib/composer/autoload_classmap.php index e104d3fc3..08653fc66 100644 --- a/lib/composer/autoload_classmap.php +++ b/lib/composer/autoload_classmap.php @@ -2,7 +2,7 @@ // autoload_classmap.php @generated by Composer -$vendorDir = dirname(__DIR__); +$vendorDir = dirname(dirname(__FILE__)); $baseDir = dirname($vendorDir); return array( diff --git a/lib/composer/autoload_files.php b/lib/composer/autoload_files.php index ae02e5199..7be757bea 100644 --- a/lib/composer/autoload_files.php +++ b/lib/composer/autoload_files.php @@ -2,25 +2,25 @@ // autoload_files.php @generated by Composer -$vendorDir = dirname(__DIR__); +$vendorDir = dirname(dirname(__FILE__)); $baseDir = dirname($vendorDir); return array( '320cde22f66dd4f5d3fd621d3e88b98f' => $vendorDir . '/symfony/polyfill-ctype/bootstrap.php', + '0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => $vendorDir . '/symfony/polyfill-mbstring/bootstrap.php', '5255c38a0faeba867671b61dfda6d864' => $vendorDir . '/paragonie/random_compat/lib/random.php', '023d27dca8066ef29e6739335ea73bad' => $vendorDir . '/symfony/polyfill-php70/bootstrap.php', - '0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => $vendorDir . '/symfony/polyfill-mbstring/bootstrap.php', + '32dcc8afd4335739640db7d200c1971d' => $vendorDir . '/symfony/polyfill-apcu/bootstrap.php', + '667aeda72477189d0494fecd327c3641' => $vendorDir . '/symfony/var-dumper/Resources/functions/dump.php', + 'bd9634f2d41831496de0d3dfe4c94881' => $vendorDir . '/symfony/polyfill-php56/bootstrap.php', '7e9bd612cc444b3eed788ebbe46263a0' => $vendorDir . '/laminas/laminas-zendframework-bridge/src/autoload.php', 'e69f7f6ee287b969198c3c9d6777bd38' => $vendorDir . '/symfony/polyfill-intl-normalizer/bootstrap.php', '25072dd6e2470089de65ae7bf11d3109' => $vendorDir . '/symfony/polyfill-php72/bootstrap.php', 'f598d06aa772fa33d905e87be6398fb1' => $vendorDir . '/symfony/polyfill-intl-idn/bootstrap.php', '7b11c4dc42b3b3023073cb14e519683c' => $vendorDir . '/ralouphie/getallheaders/src/getallheaders.php', - 'bd9634f2d41831496de0d3dfe4c94881' => $vendorDir . '/symfony/polyfill-php56/bootstrap.php', 'c964ee0ededf28c96ebd9db5099ef910' => $vendorDir . '/guzzlehttp/promises/src/functions_include.php', 'a0edc8309cc5e1d60e3047b5df6b7052' => $vendorDir . '/guzzlehttp/psr7/src/functions_include.php', '37a3dc5111fe8f707ab4c132ef1dbc62' => $vendorDir . '/guzzlehttp/guzzle/src/functions_include.php', - '32dcc8afd4335739640db7d200c1971d' => $vendorDir . '/symfony/polyfill-apcu/bootstrap.php', 'def43f6c87e4f8dfd0c9e1b1bab14fe8' => $vendorDir . '/symfony/polyfill-iconv/bootstrap.php', - '667aeda72477189d0494fecd327c3641' => $vendorDir . '/symfony/var-dumper/Resources/functions/dump.php', '2c102faa651ef8ea5874edb585946bce' => $vendorDir . '/swiftmailer/swiftmailer/lib/swift_required.php', ); diff --git a/lib/composer/autoload_namespaces.php b/lib/composer/autoload_namespaces.php index e6117c750..d12922d08 100644 --- a/lib/composer/autoload_namespaces.php +++ b/lib/composer/autoload_namespaces.php @@ -2,7 +2,7 @@ // autoload_namespaces.php @generated by Composer -$vendorDir = dirname(__DIR__); +$vendorDir = dirname(dirname(__FILE__)); $baseDir = dirname($vendorDir); return array( diff --git a/lib/composer/autoload_psr4.php b/lib/composer/autoload_psr4.php index 651c9f0c1..ca8b4b9f6 100644 --- a/lib/composer/autoload_psr4.php +++ b/lib/composer/autoload_psr4.php @@ -2,7 +2,7 @@ // autoload_psr4.php @generated by Composer -$vendorDir = dirname(__DIR__); +$vendorDir = dirname(dirname(__FILE__)); $baseDir = dirname($vendorDir); return array( diff --git a/lib/composer/autoload_real.php b/lib/composer/autoload_real.php index 752e35fbd..661cd2543 100644 --- a/lib/composer/autoload_real.php +++ b/lib/composer/autoload_real.php @@ -25,20 +25,33 @@ class ComposerAutoloaderInit0018331147de7601e7552f7da8e3bb8b require __DIR__ . '/platform_check.php'; spl_autoload_register(array('ComposerAutoloaderInit0018331147de7601e7552f7da8e3bb8b', 'loadClassLoader'), true, true); - self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__)); + self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__))); spl_autoload_unregister(array('ComposerAutoloaderInit0018331147de7601e7552f7da8e3bb8b', 'loadClassLoader')); $includePaths = require __DIR__ . '/include_paths.php'; $includePaths[] = get_include_path(); set_include_path(implode(PATH_SEPARATOR, $includePaths)); - require __DIR__ . '/autoload_static.php'; - call_user_func(\Composer\Autoload\ComposerStaticInit0018331147de7601e7552f7da8e3bb8b::getInitializer($loader)); + $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded()); + if ($useStaticLoader) { + require __DIR__ . '/autoload_static.php'; + + call_user_func(\Composer\Autoload\ComposerStaticInit0018331147de7601e7552f7da8e3bb8b::getInitializer($loader)); + } else { + $classMap = require __DIR__ . '/autoload_classmap.php'; + if ($classMap) { + $loader->addClassMap($classMap); + } + } $loader->setClassMapAuthoritative(true); $loader->register(true); - $includeFiles = \Composer\Autoload\ComposerStaticInit0018331147de7601e7552f7da8e3bb8b::$files; + if ($useStaticLoader) { + $includeFiles = Composer\Autoload\ComposerStaticInit0018331147de7601e7552f7da8e3bb8b::$files; + } else { + $includeFiles = require __DIR__ . '/autoload_files.php'; + } foreach ($includeFiles as $fileIdentifier => $file) { composerRequire0018331147de7601e7552f7da8e3bb8b($fileIdentifier, $file); } @@ -47,16 +60,11 @@ class ComposerAutoloaderInit0018331147de7601e7552f7da8e3bb8b } } -/** - * @param string $fileIdentifier - * @param string $file - * @return void - */ function composerRequire0018331147de7601e7552f7da8e3bb8b($fileIdentifier, $file) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { - $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; - require $file; + + $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; } } diff --git a/lib/composer/autoload_static.php b/lib/composer/autoload_static.php index 647f5274a..d7b35becd 100644 --- a/lib/composer/autoload_static.php +++ b/lib/composer/autoload_static.php @@ -8,21 +8,21 @@ class ComposerStaticInit0018331147de7601e7552f7da8e3bb8b { public static $files = array ( '320cde22f66dd4f5d3fd621d3e88b98f' => __DIR__ . '/..' . '/symfony/polyfill-ctype/bootstrap.php', + '0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php', '5255c38a0faeba867671b61dfda6d864' => __DIR__ . '/..' . '/paragonie/random_compat/lib/random.php', '023d27dca8066ef29e6739335ea73bad' => __DIR__ . '/..' . '/symfony/polyfill-php70/bootstrap.php', - '0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php', + '32dcc8afd4335739640db7d200c1971d' => __DIR__ . '/..' . '/symfony/polyfill-apcu/bootstrap.php', + '667aeda72477189d0494fecd327c3641' => __DIR__ . '/..' . '/symfony/var-dumper/Resources/functions/dump.php', + 'bd9634f2d41831496de0d3dfe4c94881' => __DIR__ . '/..' . '/symfony/polyfill-php56/bootstrap.php', '7e9bd612cc444b3eed788ebbe46263a0' => __DIR__ . '/..' . '/laminas/laminas-zendframework-bridge/src/autoload.php', 'e69f7f6ee287b969198c3c9d6777bd38' => __DIR__ . '/..' . '/symfony/polyfill-intl-normalizer/bootstrap.php', '25072dd6e2470089de65ae7bf11d3109' => __DIR__ . '/..' . '/symfony/polyfill-php72/bootstrap.php', 'f598d06aa772fa33d905e87be6398fb1' => __DIR__ . '/..' . '/symfony/polyfill-intl-idn/bootstrap.php', '7b11c4dc42b3b3023073cb14e519683c' => __DIR__ . '/..' . '/ralouphie/getallheaders/src/getallheaders.php', - 'bd9634f2d41831496de0d3dfe4c94881' => __DIR__ . '/..' . '/symfony/polyfill-php56/bootstrap.php', 'c964ee0ededf28c96ebd9db5099ef910' => __DIR__ . '/..' . '/guzzlehttp/promises/src/functions_include.php', 'a0edc8309cc5e1d60e3047b5df6b7052' => __DIR__ . '/..' . '/guzzlehttp/psr7/src/functions_include.php', '37a3dc5111fe8f707ab4c132ef1dbc62' => __DIR__ . '/..' . '/guzzlehttp/guzzle/src/functions_include.php', - '32dcc8afd4335739640db7d200c1971d' => __DIR__ . '/..' . '/symfony/polyfill-apcu/bootstrap.php', 'def43f6c87e4f8dfd0c9e1b1bab14fe8' => __DIR__ . '/..' . '/symfony/polyfill-iconv/bootstrap.php', - '667aeda72477189d0494fecd327c3641' => __DIR__ . '/..' . '/symfony/var-dumper/Resources/functions/dump.php', '2c102faa651ef8ea5874edb585946bce' => __DIR__ . '/..' . '/swiftmailer/swiftmailer/lib/swift_required.php', ); diff --git a/lib/composer/include_paths.php b/lib/composer/include_paths.php index af33c1491..d4fb96718 100644 --- a/lib/composer/include_paths.php +++ b/lib/composer/include_paths.php @@ -2,7 +2,7 @@ // include_paths.php @generated by Composer -$vendorDir = dirname(__DIR__); +$vendorDir = dirname(dirname(__FILE__)); $baseDir = dirname($vendorDir); return array( diff --git a/sources/Core/Authentication/Client/OAuth/OAuthClientProviderFactory.php b/sources/Core/Authentication/Client/OAuth/OAuthClientProviderFactory.php index 58445c3b7..7d5f3b721 100644 --- a/sources/Core/Authentication/Client/OAuth/OAuthClientProviderFactory.php +++ b/sources/Core/Authentication/Client/OAuth/OAuthClientProviderFactory.php @@ -43,8 +43,8 @@ class OAuthClientProviderFactory throw new CoreException(Dict::Format('itop-oauth-client:MissingOAuthClient', $sUsername)); } while ($oOAuthClient = $oSet->Fetch()) { - $sScope = $oOAuthClient->Get('scope'); - if ($sScope == 'EMail') { + $aScopes = $oOAuthClient->Get('scope')->GetValues(); + if (in_array('SMTP', $aScopes)) { return $oOAuthClient; } }