Unable to make an IMAP connection (OAuth2) with Microsoft Account with Azure registered App

Jorge Ortega 0 Reputation points
2023-12-30T15:58:12.59+00:00

Hello,

I have created an application in Azure for OAuth 2 authentication, to use it in a web application.

The problem is that I have already set all the corresponding permissions following the https://learn.microsoft.com/en-us/exchange/client-developer/legacy-protocols/how-to-authenticate-an-imap-pop-smtp-application-by-using-oauth site, it gets the token correctly, but it does not connect to the IMAP server.

The screenshot of the applied permissions:User's image

The scopes used to get the access token are: openid, profile, email, offline_access and https://graph.microsoft.com/IMAP.AccessAsUser.All.

The web application is in a development environment, and I use a Rust library to make the connection.

The configuration used is:

Server: outlook.office365.com

Port: 993

Even updating the access token using the refresh token works correctly, but not the connection to the IMAP server.

The error I get when trying to authenticate is: NO AUTHENTICATE failed

Maybe it is necessary to add the users in some Azure service, to later give public access to the users when the application is published and verified?

Thank you for your support,

Jorge

Outlook | Windows | Classic Outlook for Windows | For business
Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Vasil Michev 119.7K Reputation points MVP Volunteer Moderator
    2023-12-30T16:21:55.2733333+00:00

    The screenshot does not show the https://graph.microsoft.com/IMAP.AccessAsUser.All. permission as added, make sure it has been added to your app registration first . similarly, make sure the access token you obtain contains it. You can use tools such as jwt.ms to decode the token and verify the scopes/roles therein.

    The user's mailbox itself must be enabled for IMAP access.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.