OfficeDev / ews-managed-api

Other
584 stars 316 forks source link

EWS stopped working with Office365 account #207

Closed ngelsi closed 5 years ago

ngelsi commented 5 years ago

Hi Everyone,

Since some days ago, EWS stopped working with my Office365 account. The autodiscovery service no longer finds the exchange URL, and while setting it to a previously used URL creates the service, every service call results in a 401 Unauthorized exception. As a double check i have asked a colleague with a different Office365 account to run a test project, and the result is the same. I have also tried to set the domain in the WebCredentials constructor, but it still doesnt work. The code has not been changed in any way since it stopped working.

The project is using basic authentication. I am aware that it is planned to be obsoleted, but the online articles say until 2020. It seems like its already in effect. Can that really be the case?

Here is the example project code which i tried to run without success:

` var service = new ExchangeService(); service.Credentials = new WebCredentials("email@domain.com", "password");

        //Autodiscover url
        //Timeouts, could not locate autodiscovery url
        service.AutodiscoverUrl("email@domain.com", (url) =>
        {
            // The default for the validation callback is to reject the URL.
            bool result = false;

            Uri redirectionUri = new Uri(url);

            // Validate the contents of the redirection URL. In this simple validation
            // callback, the redirection URL is considered valid if it is using HTTPS
            // to encrypt the authentication credentials. 
            if (redirectionUri.Scheme == "https")
            {
                result = true;
            }
            return result;
        });

        //Manually set url
        //If URL is manually set, it throws 401 Unauthorized exception on every service item retrieval
        service.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx");

        //Get inbox items
        //Throws 401 Unauthorized exception
        var view = new ItemView(5, 0, OffsetBasePoint.Beginning);
        var items = service.FindItems(WellKnownFolderName.Inbox, view);`

Any help or guidelines would be appreciated. Many thanks.

pkropachev commented 5 years ago

@Silpelit Is problem still exist?

ghost commented 5 years ago

Maybe your Exchange admin has disabled the possibility to use basic auth? https://blogs.technet.microsoft.com/exchange/2018/10/17/disabling-basic-authentication-in-exchange-online-public-preview-now-available/

ngelsi commented 5 years ago

Thank you very much for the help.

In the end the problem was that my O365 password has expired. What made this not that easy to recognize is that the OWA was working fine, probably because the authentication token in the browser was still valid for a while after the expiration.

How i found this out is that i added the trace listeners to EWS and saved down the communications into xml files and took a look at them. I used the approach written in this article:

https://docs.microsoft.com/en-us/previous-versions/office/developer/exchange-server-2010/dd633676(v=exchg.80)

The XML result from the AutoDiscovery communication stated clearly that the password expired.

alpha079 commented 2 years ago

Hi , We are still getting this Inner exception: 08:39:06 Microsoft.Exchange.WebServices.Data.AutodiscoverLocalException: The Autodiscover service couldn't be located. 08:39:06 Source: Microsoft.Exchange.WebServices 08:39:06 StackTrace: 08:39:06 at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.InternalGetLegacyUserSettings[TSettings](String emailAddress, List1 redirectionEmailAddresses, Int32& currentHop) 08:39:06 at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.InternalGetLegacyUserSettings[TSettings](String emailAddress, List1 redirectionEmailAddresses, Int32& currentHop) 08:39:06 at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetLegacyUserSettings[TSettings](String emailAddress) 08:39:06 at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.InternalGetLegacyUserSettings(String emailAddress, List`1 requestedSettings) 08:39:06 at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetUserSettings(String userSmtpAddress, UserSettingName[] userSettingNames) 08:39:06 at Quest.AM.Autodiscover.EWSAutodiscover.ExecuteAutoDiscover(AutodiscoverService ewsService, String emailAddress, EWSAutodiscoverOptions options) 08:39:06 at Quest.AM.Autodiscover.EWSAutodiscover.DoAutodiscover(String emailAddress, String url, Boolean useScpLookup, NetworkCredential creds, String o365Provider, String connectionUri, EWSAutodiscoverOptions options, Int32 exchangeVersion, String overrideSettings, TimeSpan timeout) 08:39:06 at Quest.AM.Autodiscover.EWSAutodiscover.<>c__DisplayClass3_0.b__2() 08:39:06 at System.Threading.Tasks.Task.InnerInvoke() 08:39:06 at System.Threading.Tasks.Task.Execute()