forked from Wavyzz/dolibarr
Debug v17
This commit is contained in:
@@ -421,10 +421,13 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
||||
//$debugtext = "Host: ".$this->host."<br>Port: ".$this->port."<br>Login: ".$this->login."<br>Password: ".$this->password."<br>access type: ".$this->acces_type."<br>oauth service: ".$this->oauth_service."<br>Max email per collect: ".$this->maxemailpercollect;
|
||||
//dol_syslog($debugtext);
|
||||
|
||||
$token = '';
|
||||
|
||||
$storage = new DoliStorage($db, $conf, $keyforprovider);
|
||||
|
||||
try {
|
||||
$tokenobj = $storage->retrieveAccessToken($OAUTH_SERVICENAME);
|
||||
|
||||
$expire = true;
|
||||
// Is token expired or will token expire in the next 30 seconds
|
||||
// if (is_object($tokenobj)) {
|
||||
@@ -439,11 +442,15 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
||||
);
|
||||
$serviceFactory = new \OAuth\ServiceFactory();
|
||||
$oauthname = explode('-', $OAUTH_SERVICENAME);
|
||||
|
||||
// ex service is Google-Emails we need only the first part Google
|
||||
$apiService = $serviceFactory->createService($oauthname[0], $credentials, $storage, array());
|
||||
|
||||
// We have to save the token because Google give it only once
|
||||
$refreshtoken = $tokenobj->getRefreshToken();
|
||||
//var_dump($tokenobj);
|
||||
$tokenobj = $apiService->refreshAccessToken($tokenobj);
|
||||
|
||||
$tokenobj->setRefreshToken($refreshtoken);
|
||||
$storage->storeAccessToken($OAUTH_SERVICENAME, $tokenobj);
|
||||
}
|
||||
@@ -491,6 +498,15 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
||||
}
|
||||
if (!$error) {
|
||||
try {
|
||||
// To emulate the command connect, you can run
|
||||
// openssl s_client -crlf -connect outlook.office365.com:993
|
||||
// TAG1 AUTHENTICATE XOAUTH2 dXN...
|
||||
// TO Get debug log, you can set protected $debug = true; in Protocol.php file
|
||||
//
|
||||
// A MS bug make this not working !
|
||||
// See https://github.com/MicrosoftDocs/office-developer-exchange-docs/issues/100
|
||||
// See github.com/MicrosoftDocs/office-developer-exchange-docs/issues/87
|
||||
// See github.com/Webklex/php-imap/issues/81
|
||||
$client->connect();
|
||||
|
||||
$f = $client->getFolders(false, $object->source_directory);
|
||||
|
||||
@@ -32,7 +32,7 @@ if (isModEnabled('stripe')) {
|
||||
$supportedoauth2array['OAUTH_STRIPE_LIVE_NAME'] = array('callbackfile' => 'stripelive', 'picto' => 'stripe', 'urlforapp' => '', 'name'=>'StripeLive', 'urlforcredentials'=>'', 'availablescopes'=>'read_write', 'returnurl'=>'/core/modules/oauth/stripelive_oauthcallback.php');
|
||||
}
|
||||
$supportedoauth2array['OAUTH_GITHUB_NAME'] = array('callbackfile' => 'github', 'picto' => 'github', 'urlforapp' => 'OAUTH_GITHUB_DESC', 'name'=>'GitHub', 'urlforcredentials'=>'https://github.com/settings/developers', 'availablescopes'=>'user,public_repo', 'returnurl'=>'/core/modules/oauth/github_oauthcallback.php');
|
||||
$supportedoauth2array['OAUTH_MICROSOFT_NAME'] = array('callbackfile' => 'microsoft', 'picto' => 'microsoft', 'urlforapp' => 'OAUTH_MICROSOFT_DESC', 'name'=>'Microsoft', 'urlforcredentials'=>'https://portal.azure.com/', 'availablescopes'=>'openid,offline_access,profile,email,IMAP.AccessAsUser.All,SMTP.Send,Mail.Read,Mail.Send', 'returnurl'=>'/core/modules/oauth/microsoft_oauthcallback.php');
|
||||
$supportedoauth2array['OAUTH_MICROSOFT_NAME'] = array('callbackfile' => 'microsoft', 'picto' => 'microsoft', 'urlforapp' => 'OAUTH_MICROSOFT_DESC', 'name'=>'Microsoft', 'urlforcredentials'=>'https://portal.azure.com/', 'availablescopes'=>'openid,offline_access,profile,email,User.Read,https://outlook.office365.com/IMAP.AccessAsUser.All,https://outlook.office365.com/SMTP.Send', 'returnurl'=>'/core/modules/oauth/microsoft_oauthcallback.php');
|
||||
if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) {
|
||||
$supportedoauth2array['OAUTH_OTHER_NAME'] = array('callbackfile' => 'generic', 'picto' => 'generic', 'urlforapp' => 'OAUTH_OTHER_DESC', 'name'=>'Other', 'urlforcredentials'=>'', 'availablescopes'=>'Standard', 'returnurl'=>'/core/modules/oauth/generic_oauthcallback.php');
|
||||
// See https://learn.microsoft.com/fr-fr/azure/active-directory/develop/quickstart-register-app#register-an-application
|
||||
|
||||
@@ -155,11 +155,16 @@ if (GETPOST('code') || GETPOST('error')) { // We are coming from oauth provi
|
||||
if (GETPOST('error')) {
|
||||
setEventMessages(GETPOST('error').' '.GETPOST('error_description'), null, 'errors');
|
||||
} else {
|
||||
//print GETPOST('code');exit;
|
||||
|
||||
//$token = $apiService->requestAccessToken(GETPOST('code'), $state);
|
||||
$token = $apiService->requestAccessToken(GETPOST('code'));
|
||||
//print $token;
|
||||
// Microsoft is a service that does not need state to be stored as second paramater of requestAccessToken
|
||||
|
||||
//print $token->getAccessToken().'<br><br>';
|
||||
//print $token->getExtraParams()['id_token'].'<br>';
|
||||
//print $token->getRefreshToken().'<br>';exit;
|
||||
|
||||
setEventMessages($langs->trans('NewTokenStored'), null, 'mesgs'); // Stored into object managed by class DoliStorage so into table oauth_token
|
||||
}
|
||||
|
||||
|
||||
@@ -1082,10 +1082,13 @@ class EmailCollector extends CommonObject
|
||||
//$debugtext = "Host: ".$this->host."<br>Port: ".$this->port."<br>Login: ".$this->login."<br>Password: ".$this->password."<br>access type: ".$this->acces_type."<br>oauth service: ".$this->oauth_service."<br>Max email per collect: ".$this->maxemailpercollect;
|
||||
//dol_syslog($debugtext);
|
||||
|
||||
$token = '';
|
||||
|
||||
$storage = new DoliStorage($db, $conf, $keyforprovider);
|
||||
|
||||
try {
|
||||
$tokenobj = $storage->retrieveAccessToken($OAUTH_SERVICENAME);
|
||||
|
||||
$expire = true;
|
||||
// Is token expired or will token expire in the next 30 seconds
|
||||
// if (is_object($tokenobj)) {
|
||||
@@ -1122,7 +1125,6 @@ class EmailCollector extends CommonObject
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
$cm = new ClientManager();
|
||||
$client = $cm->make([
|
||||
'host' => $this->host,
|
||||
|
||||
@@ -57,6 +57,7 @@ class StreamClient extends AbstractClient
|
||||
}
|
||||
$extraHeaders['Content-length'] = 'Content-length: '.strlen($requestBody);
|
||||
|
||||
//var_dump($requestBody); var_dump($extraHeaders);var_dump($method);exit;
|
||||
$context = $this->generateStreamContext($requestBody, $extraHeaders, $method);
|
||||
|
||||
$level = error_reporting(0);
|
||||
|
||||
@@ -223,6 +223,8 @@ abstract class AbstractService extends BaseAbstractService implements ServiceInt
|
||||
$parameters,
|
||||
$this->getExtraOAuthHeaders()
|
||||
);
|
||||
//print $responseBody;exit; // We must have a result "{"token_type":"Bearer","scope...
|
||||
|
||||
$token = $this->parseAccessTokenResponse($responseBody);
|
||||
$this->storage->storeAccessToken($this->service(), $token);
|
||||
|
||||
|
||||
@@ -38,8 +38,9 @@ class Microsoft extends AbstractService
|
||||
const SCOPE_APPLICATIONS = 'applications';
|
||||
const SCOPE_APPLICATIONS_CREATE = 'applications_create';
|
||||
const SCOPE_IMAP = 'imap';
|
||||
const SOCPE_IMAP_ACCESSASUSERALL = 'IMAP.AccessAsUser.All';
|
||||
const SOCPE_SMTPSEND = 'SMTP.Send';
|
||||
const SOCPE_IMAP_ACCESSASUSERALL = 'https://outlook.office365.com/IMAP.AccessAsUser.All';
|
||||
const SOCPE_SMTPSEND = 'https://outlook.office365.com/SMTP.Send';
|
||||
const SOCPE_USERREAD = 'User.Read';
|
||||
const SOCPE_MAILREAD = 'Mail.Read';
|
||||
const SOCPE_MAILSEND = 'Mail.Send';
|
||||
|
||||
|
||||
@@ -353,6 +353,7 @@ class Client {
|
||||
} catch (Exceptions\RuntimeException $e) {
|
||||
throw new ConnectionFailedException("connection setup failed - run exception", 0, $e);
|
||||
}
|
||||
|
||||
$this->authenticate();
|
||||
|
||||
return $this;
|
||||
|
||||
@@ -31,7 +31,7 @@ OAUTH_GITHUB_SECRET=OAuth GitHub Secret
|
||||
OAUTH_URL_FOR_CREDENTIAL=Go to <a class="notasortlink" href="%s" target="_blank" rel="noopener noreferrer external">this page<span class="fas fa-external-link-alt paddingleft"></span></a> to create or get your OAuth ID and Secret
|
||||
OAUTH_STRIPE_TEST_NAME=OAuth Stripe Test
|
||||
OAUTH_STRIPE_LIVE_NAME=OAuth Stripe Live
|
||||
OAUTH_ID=OAuth ID
|
||||
OAUTH_ID=OAuth Client ID
|
||||
OAUTH_SECRET=OAuth secret
|
||||
OAUTH_TENANT=OAuth tenant
|
||||
OAuthProviderAdded=OAuth provider added
|
||||
|
||||
Reference in New Issue
Block a user