mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-20 15:52:24 +02:00
N°5102 - Allow to send emails using GSuite SMTP and OAuth - Rework
This commit is contained in:
@@ -18,7 +18,7 @@ Dict::Add('CS CZ', 'Czech', 'Čeština', [
|
||||
'itop-oauth-client:UsedForSMTP' => 'This OAuth client is used for SMTP~~',
|
||||
'itop-oauth-client:TestSMTP' => 'Email send test~~',
|
||||
'itop-oauth-client:MissingOAuthClient' => 'Missing Oauth client for user name %1$s~~',
|
||||
'itop-oauth-client:Message:OAuthClientCreated' => 'Generate access tokens before using this OAuth client~~',
|
||||
'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~~',
|
||||
]);
|
||||
|
||||
@@ -18,7 +18,7 @@ Dict::Add('DA DA', 'Danish', 'Dansk', [
|
||||
'itop-oauth-client:UsedForSMTP' => 'This OAuth client is used for SMTP~~',
|
||||
'itop-oauth-client:TestSMTP' => 'Email send test~~',
|
||||
'itop-oauth-client:MissingOAuthClient' => 'Missing Oauth client for user name %1$s~~',
|
||||
'itop-oauth-client:Message:OAuthClientCreated' => 'Generate access tokens before using this OAuth client~~',
|
||||
'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~~',
|
||||
]);
|
||||
|
||||
@@ -101,7 +101,9 @@
|
||||
if (!$bEditMode) {
|
||||
$oConfig = utils::GetConfig();
|
||||
$sScope = $this->Get('scope');
|
||||
if (($sScope == 'SMTP' || $sScope == 'EMail') && $oConfig->Get('email_transport_smtp.username') == $this->Get('name')) {
|
||||
if (empty($this->Get('token'))) {
|
||||
$oPage->p('<b>'.Dict::S('itop-oauth-client:Message:MissingToken').'</b>');
|
||||
} 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';
|
||||
@@ -131,6 +133,36 @@
|
||||
}
|
||||
]]></code>
|
||||
</method>
|
||||
<method id="GetAccessToken">
|
||||
<static>false</static>
|
||||
<access>public</access>
|
||||
<code><![CDATA[
|
||||
public function GetAccessToken()
|
||||
{
|
||||
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',
|
||||
]);
|
||||
}
|
||||
]]></code>
|
||||
</method>
|
||||
<method id="SetAccessToken">
|
||||
<static>false</static>
|
||||
<access>public</access>
|
||||
<code><![CDATA[
|
||||
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->DBUpdate();
|
||||
}
|
||||
]]></code>
|
||||
</method>
|
||||
</methods>
|
||||
<presentation>
|
||||
<details>
|
||||
|
||||
@@ -10,15 +10,15 @@ Dict::Add('DE DE', 'German', 'Deutsch', [
|
||||
'Menu:CreateMailbox' => 'Create a mailbox...~~',
|
||||
'Menu:OAuthClient' => 'OAuth Client~~',
|
||||
'Menu:OAuthClient+' => '~~',
|
||||
'Menu:GenerateTokens' => 'Generate access tokens...~~',
|
||||
'Menu:RegenerateTokens' => 'Regenerate access tokens...~~',
|
||||
'Menu:GenerateTokens' => 'Generate access token...~~',
|
||||
'Menu:RegenerateTokens' => 'Regenerate access token...~~',
|
||||
|
||||
'itop-oauth-client/Operation:CreateMailBox/Title' => 'Mailbox creation~~',
|
||||
|
||||
'itop-oauth-client:UsedForSMTP' => 'This OAuth client is used for SMTP~~',
|
||||
'itop-oauth-client:TestSMTP' => 'Email send test~~',
|
||||
'itop-oauth-client:MissingOAuthClient' => 'Missing Oauth client for user name %1$s~~',
|
||||
'itop-oauth-client:Message:OAuthClientCreated' => 'Generate access tokens before using this OAuth client~~',
|
||||
'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~~',
|
||||
]);
|
||||
|
||||
@@ -10,15 +10,15 @@ Dict::Add('EN US', 'English', 'English', [
|
||||
'Menu:CreateMailbox' => 'Create a mailbox...',
|
||||
'Menu:OAuthClient' => 'OAuth Client',
|
||||
'Menu:OAuthClient+' => '',
|
||||
'Menu:GenerateTokens' => 'Generate access tokens...',
|
||||
'Menu:RegenerateTokens' => 'Regenerate access tokens...',
|
||||
'Menu:GenerateTokens' => 'Generate access token...',
|
||||
'Menu:RegenerateTokens' => 'Regenerate access token...',
|
||||
|
||||
'itop-oauth-client/Operation:CreateMailBox/Title' => 'Mailbox creation',
|
||||
|
||||
'itop-oauth-client:UsedForSMTP' => 'This OAuth client is used for SMTP',
|
||||
'itop-oauth-client:TestSMTP' => 'Email send test',
|
||||
'itop-oauth-client:MissingOAuthClient' => 'Missing Oauth client for user name %1$s',
|
||||
'itop-oauth-client:Message:OAuthClientCreated' => 'Generate access tokens before using this OAuth client',
|
||||
'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',
|
||||
]);
|
||||
|
||||
@@ -18,7 +18,7 @@ Dict::Add('ES CR', 'Spanish', 'Español, Castellaño', [
|
||||
'itop-oauth-client:UsedForSMTP' => 'This OAuth client is used for SMTP~~',
|
||||
'itop-oauth-client:TestSMTP' => 'Email send test~~',
|
||||
'itop-oauth-client:MissingOAuthClient' => 'Missing Oauth client for user name %1$s~~',
|
||||
'itop-oauth-client:Message:OAuthClientCreated' => 'Generate access tokens before using this OAuth client~~',
|
||||
'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~~',
|
||||
]);
|
||||
|
||||
@@ -17,7 +17,7 @@ Dict::Add('FR FR', 'French', 'Français', [
|
||||
'itop-oauth-client:UsedForSMTP' => 'Ce client Oauth est utilisé pour SMTP',
|
||||
'itop-oauth-client:TestSMTP' => 'Tester l\'envoi de mail',
|
||||
'itop-oauth-client:MissingOAuthClient' => 'Il n\'y a pas de client OAuth pour l\'utilisateur %1$s',
|
||||
'itop-oauth-client:Message:OAuthClientCreated' => 'Générez les jetons d\'accès avant d\'utiliser cd client OAuth',
|
||||
'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é',
|
||||
]);
|
||||
|
||||
@@ -18,7 +18,7 @@ Dict::Add('HU HU', 'Hungarian', 'Magyar', [
|
||||
'itop-oauth-client:UsedForSMTP' => 'This OAuth client is used for SMTP~~',
|
||||
'itop-oauth-client:TestSMTP' => 'Email send test~~',
|
||||
'itop-oauth-client:MissingOAuthClient' => 'Missing Oauth client for user name %1$s~~',
|
||||
'itop-oauth-client:Message:OAuthClientCreated' => 'Generate access tokens before using this OAuth client~~',
|
||||
'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~~',
|
||||
]);
|
||||
|
||||
@@ -18,7 +18,7 @@ Dict::Add('IT IT', 'Italian', 'Italiano', [
|
||||
'itop-oauth-client:UsedForSMTP' => 'This OAuth client is used for SMTP~~',
|
||||
'itop-oauth-client:TestSMTP' => 'Email send test~~',
|
||||
'itop-oauth-client:MissingOAuthClient' => 'Missing Oauth client for user name %1$s~~',
|
||||
'itop-oauth-client:Message:OAuthClientCreated' => 'Generate access tokens before using this OAuth client~~',
|
||||
'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~~',
|
||||
]);
|
||||
|
||||
@@ -18,7 +18,7 @@ Dict::Add('JA JP', 'Japanese', '日本語', [
|
||||
'itop-oauth-client:UsedForSMTP' => 'This OAuth client is used for SMTP~~',
|
||||
'itop-oauth-client:TestSMTP' => 'Email send test~~',
|
||||
'itop-oauth-client:MissingOAuthClient' => 'Missing Oauth client for user name %1$s~~',
|
||||
'itop-oauth-client:Message:OAuthClientCreated' => 'Generate access tokens before using this OAuth client~~',
|
||||
'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~~',
|
||||
]);
|
||||
|
||||
@@ -28,7 +28,6 @@ SetupWebPage::AddModule(
|
||||
'src/Model/OAuthClientGoogle.php',
|
||||
'src/Model/OAuthClientAzure.php',
|
||||
'src/Service/PopupMenuExtension.php',
|
||||
'src/Service/ApplicationObjectExtension.php',
|
||||
),
|
||||
'webservice' => array(
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ Dict::Add('NL NL', 'Dutch', 'Nederlands', [
|
||||
'itop-oauth-client:UsedForSMTP' => 'This OAuth client is used for SMTP~~',
|
||||
'itop-oauth-client:TestSMTP' => 'Email send test~~',
|
||||
'itop-oauth-client:MissingOAuthClient' => 'Missing Oauth client for user name %1$s~~',
|
||||
'itop-oauth-client:Message:OAuthClientCreated' => 'Generate access tokens before using this OAuth client~~',
|
||||
'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~~',
|
||||
]);
|
||||
|
||||
@@ -18,7 +18,7 @@ Dict::Add('PT BR', 'Brazilian', 'Brazilian', [
|
||||
'itop-oauth-client:UsedForSMTP' => 'This OAuth client is used for SMTP~~',
|
||||
'itop-oauth-client:TestSMTP' => 'Email send test~~',
|
||||
'itop-oauth-client:MissingOAuthClient' => 'Missing Oauth client for user name %1$s~~',
|
||||
'itop-oauth-client:Message:OAuthClientCreated' => 'Generate access tokens before using this OAuth client~~',
|
||||
'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~~',
|
||||
]);
|
||||
|
||||
@@ -18,7 +18,7 @@ Dict::Add('RU RU', 'Russian', 'Русский', [
|
||||
'itop-oauth-client:UsedForSMTP' => 'This OAuth client is used for SMTP~~',
|
||||
'itop-oauth-client:TestSMTP' => 'Email send test~~',
|
||||
'itop-oauth-client:MissingOAuthClient' => 'Missing Oauth client for user name %1$s~~',
|
||||
'itop-oauth-client:Message:OAuthClientCreated' => 'Generate access tokens before using this OAuth client~~',
|
||||
'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~~',
|
||||
]);
|
||||
|
||||
@@ -18,7 +18,7 @@ Dict::Add('SK SK', 'Slovak', 'Slovenčina', [
|
||||
'itop-oauth-client:UsedForSMTP' => 'This OAuth client is used for SMTP~~',
|
||||
'itop-oauth-client:TestSMTP' => 'Email send test~~',
|
||||
'itop-oauth-client:MissingOAuthClient' => 'Missing Oauth client for user name %1$s~~',
|
||||
'itop-oauth-client:Message:OAuthClientCreated' => 'Generate access tokens before using this OAuth client~~',
|
||||
'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~~',
|
||||
]);
|
||||
|
||||
@@ -25,19 +25,15 @@ class AjaxOauthClientController extends Controller
|
||||
|
||||
IssueLog::Debug("GetAuthorizationUrl for $sClass::$sId", self::LOG_CHANNEL);
|
||||
|
||||
$oObject = MetaModel::GetObject($sClass, $sId);
|
||||
/** @var \OAuthClient $oOAuthClient */
|
||||
$oOAuthClient = MetaModel::GetObject($sClass, $sId);
|
||||
|
||||
$aResult = ['status' => 'success', 'data' => []];
|
||||
$sProvider = $oObject->Get('provider');
|
||||
$sClientId = $oObject->Get('client_id');
|
||||
$sClientSecret = $oObject->Get('client_secret');
|
||||
$sScope = $oObject->GetScope();
|
||||
$aAdditional = [];
|
||||
$sAuthorizationUrl = OAuthClientProviderFactory::getVendorProviderForAccessUrl($sProvider, $sClientId, $sClientSecret, $sScope, $aAdditional);
|
||||
|
||||
$sAuthorizationUrl = OAuthClientProviderFactory::GetAuthorizationUrl($oOAuthClient);
|
||||
$aResult['data']['authorization_url'] = $sAuthorizationUrl;
|
||||
|
||||
$this->DisplayJSONPage($aResult);
|
||||
|
||||
}
|
||||
|
||||
public function OperationGetDisplayAuthenticationResults()
|
||||
@@ -47,14 +43,9 @@ class AjaxOauthClientController extends Controller
|
||||
|
||||
IssueLog::Debug("GetDisplayAuthenticationResults for $sClass::$sId", self::LOG_CHANNEL);
|
||||
|
||||
$oObject = MetaModel::GetObject($sClass, $sId);
|
||||
$bIsCreation = empty($oObject->Get('token'));
|
||||
|
||||
$sProvider = $oObject->Get('provider');
|
||||
$sClientId = $oObject->Get('client_id');
|
||||
$sClientSecret = $oObject->Get('client_secret');
|
||||
$sScope = $oObject->GetScope();
|
||||
$aAdditional = [];
|
||||
/** @var \OAuthClient $oOAuthClient */
|
||||
$oOAuthClient = MetaModel::GetObject($sClass, $sId);
|
||||
$bIsCreation = empty($oOAuthClient->Get('token'));
|
||||
|
||||
$sRedirectUrl = utils::ReadParam('redirect_url', '', false, 'raw');
|
||||
|
||||
@@ -63,12 +54,9 @@ class AjaxOauthClientController extends Controller
|
||||
$aQuery = [];
|
||||
parse_str($sRedirectUrlQuery, $aQuery);
|
||||
$sCode = $aQuery['code'];
|
||||
$oProvider = OAuthClientProviderFactory::getVendorProvider($sProvider, $sClientId, $sClientSecret, $sScope, $aAdditional);
|
||||
$oAccessToken = OAuthClientProviderFactory::getAccessTokenFromCode($oProvider, $sCode);
|
||||
$oAccessToken = OAuthClientProviderFactory::GetAccessTokenFromCode($oOAuthClient, $sCode);
|
||||
|
||||
$oObject->Set('token', $oAccessToken->getToken());
|
||||
$oObject->Set('refresh_token', $oAccessToken->getRefreshToken());
|
||||
$oObject->DBUpdate();
|
||||
$oOAuthClient->SetAccessToken($oAccessToken);
|
||||
|
||||
cmdbAbstractObject::SetSessionMessage(
|
||||
$sClass,
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
use Combodo\iTop\Core\Authentication\Client\OAuth\OAuthClientProviderAbstract;
|
||||
use Combodo\iTop\Core\Authentication\Client\OAuth\OAuthClientProviderFactory;
|
||||
|
||||
class OAuthClientAzure extends OAuthClient
|
||||
{
|
||||
@@ -40,10 +40,10 @@ class OAuthClientAzure extends OAuthClient
|
||||
MetaModel::Init_Params($aParams);
|
||||
MetaModel::Init_InheritAttributes();
|
||||
MetaModel::Init_AddAttribute(new AttributeEnum('scope', [
|
||||
'allowed_values' => new ValueSetEnum('SMTP,IMAP'),
|
||||
'allowed_values' => new ValueSetEnum('EMail'),
|
||||
'display_style' => 'list',
|
||||
'sql' => 'scope',
|
||||
'default_value' => 'SMTP',
|
||||
'default_value' => 'EMail',
|
||||
'is_null_allowed' => false,
|
||||
'depends_on' => [],
|
||||
'always_load_in_tables' => true,
|
||||
@@ -70,7 +70,7 @@ class OAuthClientAzure extends OAuthClient
|
||||
public function PrefillCreationForm(&$aContextParam)
|
||||
{
|
||||
$this->Set('provider', 'Azure');
|
||||
$this->Set('redirect_url', OAuthClientProviderAbstract::GetRedirectUri());
|
||||
$this->Set('redirect_url', OAuthClientProviderFactory::GetRedirectUri());
|
||||
|
||||
parent::PrefillCreationForm($aContextParam);
|
||||
}
|
||||
@@ -90,15 +90,10 @@ class OAuthClientAzure extends OAuthClient
|
||||
$this->Set('provider', 'Azure');
|
||||
}
|
||||
if (empty($this->Get('redirect_url'))) {
|
||||
$this->Set('redirect_url', OAuthClientProviderAbstract::GetRedirectUri());
|
||||
$this->Set('redirect_url', OAuthClientProviderFactory::GetRedirectUri());
|
||||
}
|
||||
}
|
||||
|
||||
public function GetDefaultMailServer()
|
||||
{
|
||||
return 'outlook.office365.com';
|
||||
}
|
||||
|
||||
public function GetAttributeFlags($sAttCode, &$aReasons = array(), $sTargetState = '')
|
||||
{
|
||||
if ($sAttCode == 'provider' || $sAttCode == 'redirect_url') {
|
||||
@@ -117,31 +112,13 @@ class OAuthClientAzure extends OAuthClient
|
||||
return parent::GetInitialStateAttributeFlags($sAttCode, $aReasons);
|
||||
}
|
||||
|
||||
public function GetDefaultMailServer()
|
||||
{
|
||||
return 'outlook.office365.com';
|
||||
}
|
||||
|
||||
public function GetScope()
|
||||
{
|
||||
$sScope = $this->Get('scope');
|
||||
if ($sScope == 'IMAP') {
|
||||
return 'https://outlook.office.com/IMAP.AccessAsUser.All offline_access';
|
||||
}
|
||||
|
||||
// default is smtp
|
||||
return 'https://outlook.office.com/SMTP.Send offline_access';
|
||||
}
|
||||
|
||||
public function AfterInsert()
|
||||
{
|
||||
parent::AfterInsert();
|
||||
$sClass = get_class($this);
|
||||
$sId = $this->GetKey();
|
||||
cmdbAbstractObject::SetSessionMessage(
|
||||
$sClass,
|
||||
$sId,
|
||||
"$sClass:$sId:OAuthClientCreated",
|
||||
Dict::S('itop-oauth-client:Message:OAuthClientCreated'),
|
||||
'info',
|
||||
100,
|
||||
true
|
||||
);
|
||||
return 'https://outlook.office.com/IMAP.AccessAsUser.All https://outlook.office.com/SMTP.Send offline_access';
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
use Combodo\iTop\Core\Authentication\Client\OAuth\OAuthClientProviderAbstract;
|
||||
use Combodo\iTop\Core\Authentication\Client\OAuth\OAuthClientProviderFactory;
|
||||
|
||||
class OAuthClientGoogle extends OAuthClient
|
||||
{
|
||||
@@ -72,16 +72,11 @@ class OAuthClientGoogle extends OAuthClient
|
||||
{
|
||||
$this->Set('provider', 'Google');
|
||||
$this->Set('scope', 'EMail');
|
||||
$this->Set('redirect_url', OAuthClientProviderAbstract::GetRedirectUri());
|
||||
$this->Set('redirect_url', OAuthClientProviderFactory::GetRedirectUri());
|
||||
|
||||
parent::PrefillCreationForm($aContextParam);
|
||||
}
|
||||
|
||||
public function GetDefaultMailServer()
|
||||
{
|
||||
return 'imap.gmail.com';
|
||||
}
|
||||
|
||||
public function GetAttributeFlags($sAttCode, &$aReasons = array(), $sTargetState = '')
|
||||
{
|
||||
if ($sAttCode == 'provider' || $sAttCode == 'scope' || $sAttCode == 'redirect_url') {
|
||||
@@ -115,31 +110,21 @@ class OAuthClientGoogle extends OAuthClient
|
||||
$this->Set('provider', 'Google');
|
||||
}
|
||||
if (empty($this->Get('redirect_url'))) {
|
||||
$this->Set('redirect_url', OAuthClientProviderAbstract::GetRedirectUri());
|
||||
$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/';
|
||||
}
|
||||
|
||||
public function AfterInsert()
|
||||
{
|
||||
parent::AfterInsert();
|
||||
$sClass = get_class($this);
|
||||
$sId = $this->GetKey();
|
||||
cmdbAbstractObject::SetSessionMessage(
|
||||
$sClass,
|
||||
$sId,
|
||||
"$sClass:$sId:OAuthClientCreated",
|
||||
Dict::S('itop-oauth-client:Message:OAuthClientCreated'),
|
||||
'info',
|
||||
100,
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2022 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\OAuthClient\Service;
|
||||
|
||||
use AbstractApplicationObjectExtension;
|
||||
use Exception;
|
||||
use OAuthClient;
|
||||
|
||||
class ApplicationObjectExtension extends AbstractApplicationObjectExtension
|
||||
{
|
||||
|
||||
public function OnDBInsert($oObject, $oChange = null)
|
||||
{
|
||||
if ($oObject instanceof OAuthClient) {
|
||||
try {
|
||||
// Ask for tokens the first time
|
||||
|
||||
//$response = utils::DoPostRequest($sRestUrl, $aPostedData);
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
|
||||
}
|
||||
parent::OnDBInsert($oObject, $oChange); // TODO: Change the autogenerated stub
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,7 +7,7 @@
|
||||
namespace Combodo\iTop\OAuthClient\Service;
|
||||
|
||||
use ApplicationContext;
|
||||
use Combodo\iTop\Core\Authentication\Client\OAuth\OAuthClientProviderAbstract;
|
||||
use Combodo\iTop\Core\Authentication\Client\OAuth\OAuthClientProviderFactory;
|
||||
use Dict;
|
||||
use iPopupMenuExtension;
|
||||
use JSPopupMenuItem;
|
||||
@@ -42,7 +42,7 @@ class PopupMenuExtension implements \iPopupMenuExtension
|
||||
$sAjaxUri = utils::GetAbsoluteUrlModulePage(static::MODULE_CODE, 'ajax.php');
|
||||
// Add a new menu item that triggers a custom JS function defined in our own javascript file: js/sample.js
|
||||
$sJSFileUrl = utils::GetAbsoluteUrlModulesRoot().static::MODULE_CODE.'/assets/js/oauth_connect.js';
|
||||
$sRedirectUri = OAuthClientProviderAbstract::GetRedirectUri();
|
||||
$sRedirectUri = OAuthClientProviderFactory::GetRedirectUri();
|
||||
$aResult[] = new JSPopupMenuItem(
|
||||
$sMenu.' from '.$sObjClass,
|
||||
Dict::S($sMenu),
|
||||
@@ -52,7 +52,7 @@ class PopupMenuExtension implements \iPopupMenuExtension
|
||||
|
||||
if ($bHasToken) {
|
||||
$sScope = $oObj->Get('scope');
|
||||
if ($sScope == 'IMAP' || $sScope == 'EMail') {
|
||||
if ($sScope == 'EMail') {
|
||||
$aParams = $oAppContext->GetAsHash();
|
||||
$sMenu = 'Menu:CreateMailbox';
|
||||
$sObjClass = get_class($oObj);
|
||||
|
||||
@@ -18,7 +18,7 @@ Dict::Add('TR TR', 'Turkish', 'Türkçe', [
|
||||
'itop-oauth-client:UsedForSMTP' => 'This OAuth client is used for SMTP~~',
|
||||
'itop-oauth-client:TestSMTP' => 'Email send test~~',
|
||||
'itop-oauth-client:MissingOAuthClient' => 'Missing Oauth client for user name %1$s~~',
|
||||
'itop-oauth-client:Message:OAuthClientCreated' => 'Generate access tokens before using this OAuth client~~',
|
||||
'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~~',
|
||||
]);
|
||||
|
||||
@@ -8,7 +8,6 @@ $baseDir = dirname($vendorDir);
|
||||
return array(
|
||||
'Combodo\\iTop\\OAuthClient\\Controller\\AjaxOauthClientController' => $baseDir . '/src/Controller/AjaxOauthClientController.php',
|
||||
'Combodo\\iTop\\OAuthClient\\Controller\\OAuthClientController' => $baseDir . '/src/Controller/OAuthClientController.php',
|
||||
'Combodo\\iTop\\OAuthClient\\Service\\ApplicationObjectExtension' => $baseDir . '/src/Service/ApplicationObjectExtension.php',
|
||||
'Combodo\\iTop\\OAuthClient\\Service\\PopupMenuExtension' => $baseDir . '/src/Service/PopupMenuExtension.php',
|
||||
'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',
|
||||
);
|
||||
|
||||
@@ -23,7 +23,6 @@ class ComposerStaticInitd52424b43ff18219f2ec935428aff074
|
||||
public static $classMap = array (
|
||||
'Combodo\\iTop\\OAuthClient\\Controller\\AjaxOauthClientController' => __DIR__ . '/../..' . '/src/Controller/AjaxOauthClientController.php',
|
||||
'Combodo\\iTop\\OAuthClient\\Controller\\OAuthClientController' => __DIR__ . '/../..' . '/src/Controller/OAuthClientController.php',
|
||||
'Combodo\\iTop\\OAuthClient\\Service\\ApplicationObjectExtension' => __DIR__ . '/../..' . '/src/Service/ApplicationObjectExtension.php',
|
||||
'Combodo\\iTop\\OAuthClient\\Service\\PopupMenuExtension' => __DIR__ . '/../..' . '/src/Service/PopupMenuExtension.php',
|
||||
'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php',
|
||||
);
|
||||
|
||||
@@ -18,7 +18,7 @@ Dict::Add('ZH CN', 'Chinese', '简体中文', [
|
||||
'itop-oauth-client:UsedForSMTP' => 'This OAuth client is used for SMTP~~',
|
||||
'itop-oauth-client:TestSMTP' => 'Email send test~~',
|
||||
'itop-oauth-client:MissingOAuthClient' => 'Missing Oauth client for user name %1$s~~',
|
||||
'itop-oauth-client:Message:OAuthClientCreated' => 'Generate access tokens before using this OAuth client~~',
|
||||
'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~~',
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user