Garethp / php-ews

PHP Exchange Web Services
BSD 3-Clause "New" or "Revised" License
112 stars 45 forks source link

Authorization stopped working suddenly #239

Open boindil opened 1 year ago

boindil commented 1 year ago

Hi, the authorization suddenly stopped working without me doing anything. No password changes, no code changes. Might this be related to microsoft disabling basic auth?

@Garethp maybe you have any ideas? My code can only run fully unattended (printing specific mails and faxes). If it's actually basic-auth related, how to solve without user interaction? :/

    $host           = 'outlook.office365.com';
    $username       = 'xxx1@xxx.com';
    $password       = '';
    $email          = 'xxx2@xxx.com';

    $api = \garethp\ews\MailAPI::withUsernameAndPassword(
        $host,
        $username,
        $password,
        [
            'primarySmtpEmailAddress' => $email
        ]
    );
    $box = $api->getFolderByDistinguishedId('inbox');
    $items = $api->getMailItems($box->getFolderId());
PHP Fatal error:  Uncaught garethp\ews\API\Exception\UnauthorizedException in /root/autoprint/vendor/garethp/php-ews/src/API/ExchangeWebServices.php:454
Stack trace:
#0 /root/autoprint/vendor/garethp/php-ews/src/API/ExchangeWebServices.php(372): garethp\ews\API\ExchangeWebServices->handleNonSuccessfulResponses(NULL, 401)
#1 /root/autoprint/vendor/garethp/php-ews/src/API/ExchangeWebServices/MiddlewareFactory.php(57): garethp\ews\API\ExchangeWebServices->processResponse(NULL)
#2 /root/autoprint/vendor/garethp/php-ews/src/API/ExchangeWebServices.php(516): garethp\ews\API\ExchangeWebServices->garethp\ews\API\ExchangeWebServices\{closure}(Object(garethp\ews\API\MiddlewareRequest), Object(Closure))
#3 /root/autoprint/vendor/garethp/php-ews/src/API/ExchangeWebServices/MiddlewareFactory.php(66): garethp\ews\API\ExchangeWebServices->garethp\ews\API\{closure}(Object(garethp\ews\API\MiddlewareRequest))
#4 /root/autoprint/vendor/garethp/php-ews/src/API/ExchangeWebServices.php(516): garethp\ews\API\ExchangeWebServices->garethp\ews\API\Exch in /root/autoprint/vendor/garethp/php-ews/src/API/ExchangeWebServices.php on line 454
tguk70 commented 1 year ago

It's related to basic auth as I am having the same issue with my powershell scripts and having to use oAuth instead. Check on the Microsoft exchange web services page to find your alternative method.