You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm having an issue configuring an IMAP connection to an Outlook365 account with oAuth token.
First of all, I attach the steps configured in Microsoft Entra ID, with this guide: Microsoft Answers
After configuring and testing the output of the Powershell script, I can read and access without problems to the folders of the mailbox.
But when I'm configuring the PHP-IMAP library for this connection, I reach the conection (user is authenticated) but when I try to read the folders ($client->getFolders();) it throws the error.
`include 'includes/php-imap/vendor/autoload.php';
use Webklex\PHPIMAP\ClientManager;
$CLIENT_ID="/* censored data */";
$CLIENT_SECRET="/* censored data */";
$TENANT="/* censored data */";
$REFRESH_TOKEN="/* censored data */";
$url= "https://login.microsoftonline.com/$TENANT/oauth2/v2.0/token";
$param_post_curl = [
'client_id'=>$CLIENT_ID,
'client_secret'=>$CLIENT_SECRET,
'refresh_token'=>$REFRESH_TOKEN,
'grant_type'=>'refresh_token' ];
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POSTFIELDS, http_build_query($param_post_curl));
curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
//ONLY USE CURLOPT_SSL_VERIFYPEER AT FALSE IF YOU ARE IN LOCALHOST !!!
$oResult=curl_exec($ch);
if(!empty($oResult)){
//The token is a JSON object
$array_php_resul = json_decode($oResult,true);
if( isset($array_php_resul["access_token"]) ){
$access_token = $array_php_resul["access_token"];
//$cm = new ClientManager($options = ["options" => ["debug" => true]]);
$cm = new ClientManager();
$client = $cm->make([
'host' => 'outlook.office365.com',
'port' => 993,
'encryption' => 'ssl',
'validate_cert' => false,
'username' => '/* censored data */',
'password' => $access_token,
'protocol' => 'imap',
'authentication' => "oauth",
"timeout" => 30,
"extensions" => []
]);
try {
//Connect to the IMAP Server
$client->connect();
//$client->checkConnection();
$folders = $client->getFolders();
}catch (Exception $e) {
echo 'Exception : ', $e->getMessage(), "\n";
}
} else {
echo('Error : '.$array_php_resul["error_description"]);
}
}`
After contacting Microsoft Azure support, their answer is that with Powershell works, the problem is in the library or code configured.
I've been searching for a solution with no result, maybe some1 had the same problem and can help me?
Adittional information needed please aske me for it.
Best regards
The text was updated successfully, but these errors were encountered:
Hi
I'm having an issue configuring an IMAP connection to an Outlook365 account with oAuth token.
First of all, I attach the steps configured in Microsoft Entra ID, with this guide: Microsoft Answers
After configuring and testing the output of the Powershell script, I can read and access without problems to the folders of the mailbox.
![prueba imap censored](https://private-user-images.githubusercontent.com/151068695/321182990-6ce89a94-5269-47b6-b583-b6d5dc69a171.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTkwNDIyODEsIm5iZiI6MTcxOTA0MTk4MSwicGF0aCI6Ii8xNTEwNjg2OTUvMzIxMTgyOTkwLTZjZTg5YTk0LTUyNjktNDdiNi1iNTgzLWI2ZDVkYzY5YTE3MS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNjIyJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDYyMlQwNzM5NDFaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1iMDYzNWZmYTYxNzIxYmI1ZTgyYTFlYzlhNjg5NjU0ZjE2MzFlNmU1ZWVkNzJjM2ZlMGE0Zjk1MWVhYzk1NjY5JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.YKYc_MB5gpnDzO3MqFvsYIIDdZGQMUmvJ83v1gODCMw)
But when I'm configuring the PHP-IMAP library for this connection, I reach the conection (user is authenticated) but when I try to read the folders ($client->getFolders();) it throws the error.
After contacting Microsoft Azure support, their answer is that with Powershell works, the problem is in the library or code configured.
I've been searching for a solution with no result, maybe some1 had the same problem and can help me?
Adittional information needed please aske me for it.
Best regards
The text was updated successfully, but these errors were encountered: