How to authenticate a backend Java IMAP Application using OAuth 2.0

Ahrshia Rezai 21 Reputation points
2022-05-31T20:08:24.593+00:00

Hi,

I have a backend application that polls my outlook email and then depending on the email found does a job for them. This application currently uses basic authentication.

It has been brought to my attention that Microsoft intends to deprecate basic authentication this coming October 2022 per the following article.
https://learn.microsoft.com/en-us/exchange/clients-and-mobile-in-exchange-online/deprecation-of-basic-authentication-exchange-online

The documents points out that instead of using basic authentication we should be using OAuth 2.0 authentication instead as it is more secure. I have found documentation on getting IMAP to work with OAuth 2.0 from the following article:
https://learn.microsoft.com/en-us/exchange/client-developer/legacy-protocols/how-to-authenticate-an-imap-pop-smtp-application-by-using-oauth#get-an-access-token

From looking at the documentation on using OAuth 2.0 in IMAP there is a distinct problem with using these two in a backend application. Per the above documentation "client credentials grant flow" which is the flow that should be used for backend daemon application to get the OAuth 2.0 token is not allowed to be used on IMAP and the article goes on to say we should use the Graph API instead.

I just want to confirm that after basic authentication is removed in October 2022 there will be no way a backend application (an application that requires no human input) that uses IMAP can connect to a window's mailbox? Any application that uses IMAP will now always require a user to authenticate it via a front end URL? All application that need no human input will need to rewritten to use the Graph API instead?

Community Center Not monitored
{count} votes

Accepted answer
  1. Alfredo Revilla - Upwork Top Talent | IAM SWE SWA 27,521 Reputation points Moderator
    2022-06-01T00:58:26.31+00:00

    Hello @Ahrshia Rezai , users will need to acquire a token interactively to get access tokens for IMAP, POP and SMTP Auth. You can use Sign-in frequency, Stay signed in and refresh tokens to minimize the need to re-authenticate. For a pure server to server scenario the only option is trough MS Graph which is a more robust and secure solution than using legacy protocols. That being said, provided a careful approach to security is kept, nothing prevents you from building a daemon application that stores user credentials (Managed Identities and Key Vault can be used to secure their management) which in tandem with the ROPC can be used to acquire user access tokens that allow the aforementioned legacy protocols to be used.

    Let us know if this answer was helpful to you or if you need additional assistance. If it was helpful, please remember to accept it so that others in the community with similar questions can more easily find a solution.


0 additional answers

Sort by: Most helpful

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.