I’m connecting via IMAP protocol to an Azure account, so I must use OAuth2 and I follow the ROPC flow from Access Mail Services using OAuth|Documentation. But now, there are some accounts which are using MFA, and I can’t found the way to break the second factor, since I’ve no user interaction and I don’t want it.
But the solution provided, requires user interaction in order to set the password and MFA, and I would like to avoid using interaction, because after the IMAP integration, I need to set the modern authentication in SMTP connection, that I use in batch mail sending.
Anyway, using your solution, how it’s recommended to check the validity of the token? Should I get it for each request? Or check manually the expiration? I understand that I can reuse the ImapClient and set the AccessToken.
I’ve tried your solution, and it works (like ROPC solution) when the user has not MFA, but it throws the same message (ROPC) when the user has MFA enabled:
… AADSTS50076: Due to a configuration change made by your administrator, or because you moved to a new location, you must use multi-factor authentication to access …
I would implement (if it’s possible) a way to bypass MFA without the user interaction (to use in batch mail processes).
There doesn’t seem to be a way to bypass MFA without user interaction to access Exchange server via IMAP. You may clarify this with corresponding Microsoft support.
Hi, I started a thread in Microsoft support, but meanhwile I will solve my problem by the following way (now only in a mockup):
In the interface, where the user cofingures the email account, I will remove the password field (I could remove the mail address too, but I’ll leave it for legacy) and I put a button to validate against Azure SSO.
The connection against Azure, will use a IConfidentialClientApplication (ConfidentialClientApplicationBuilder).
After the validation, it will call to AcquireTokenByAuthorizationCode and through the UserTokenCache, it will serialize the token(cache) against the db (in a file in my mockup).
By the other way, in a console program, the app reads the token from the file (stored previously), and uses it to connect to the IMAP (or SMTP) Azure server, using AcquireTokenSilent from MSAL IConfidentialClientApplication.