Office365 mailbox connection using EWS gives "Unauthorized"

Alwin Leibbrandt 21 Reputation points
2022-03-10T12:24:46.69+00:00

I cannot connect to a cloud hosted Office365 mailbox using .net code, I am trying to connect using plain username/password with EWS.
No matter what I do I always get the error "Unauthorized", this was all working up until a couple days ago but suddenly stopped without any code/config changes.

I can connect to outlook.com in the browser just fine with the same credentials.

The tool I am using connects to https://outlook.office365.com/ews/exchange.asmx, when I try manually to connect to this url (using the browser) I just keep getting prompted for login (as though authentication fails) - should I be able to login manually like this?

When I test the connection using https://testconnectivity.microsoft.com/tests/O365EwsAccess/input, I get the results as below.

Please can someone help to shed some light on this problem.

181915-2022-03-10-14-02-16.png

Exchange Server Development
Exchange Server Development
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Development: The process of researching, productizing, and refining new or existing technologies.
518 questions
Exchange Server Management
Exchange Server Management
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Management: The act or process of organizing, handling, directing or controlling something.
7,390 questions
{count} votes

Accepted answer
  1. Kael Yao-MSFT 37,576 Reputation points Microsoft Vendor
    2022-03-11T01:56:16.183+00:00

    Hi @Alwin Leibbrandt

    Since this question is related to EWS and Exchange Development, I have added the tag "office-exchange-server-dev" to it.
    Thanks for your understanding.


    Have you disabled security defaults in your tenant? If not, it may also block basic auth.
    And if you have this user added to Conditional Access policy, it may also be the possible cause of this issue.

    If the above didn't help with this issue, you may also use the self-help tool to check and modify the settings in your tenant: Basic Auth self-help diagnostic
    Example:
    182014-36.png


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Alwin Leibbrandt 21 Reputation points
    2022-03-11T07:56:03.317+00:00

    Thank you for the info!

    I already had disabled security defaults and no conditional access policy active so it wasn't that causing the problem.

    Running the basic auth self help utility solved my problem! well partially....the self help showed that all my protocols were not enabled for basic auth, enabling EWS via the utility got things working but only for one user (myself). So I have two questions:

    1. Where do I find (form the gui) the settings that the self-help utility controls? Prior to running it I had already checked under "Admin | Org Settings | Modern authentication" and all were enabled for basic authentication but the utility shows all were disabled.
    2. Enabling from the utility only worked for my user, another user with exactly the same rights still cannot access EWS, both users have EWS enabled as a mail app on the mailbox.
      Any idea why this would be so?