azureoauth-2.0exchange-serverexchangeliboutlook.com

How to set up an (Azure) OAuth2 application for personal Outlook.com accounts (Exchange) for usage with exchangelib?


As Outlook.com seems to require OAuth2 authentication, setting up an OAuth2 application seems to be required for using exchangelib.

As a personal user, I did not really find good documentation on that. Following https://learn.microsoft.com/en-us/exchange/client-developer/legacy-protocols/how-to-authenticate-an-imap-pop-smtp-application-by-using-oauth advises using Microsoft Entra with an Azure account: https://learn.microsoft.com/en-us/entra/identity-platform/quickstart-register-app?tabs=certificate.

I did that and set up an application:

Now, I can't find the required Exchange API permissions in the selection for the app.

What I am looking for (from https://ecederstrand.github.io/exchangelib/#impersonation-oauth-on-office-365):

API Access Screenshot

How it looks for me:

API Access Selection Screenshot

Does anybody know how this is supposed to work?

Corresponding issue in the exchangelib repository: https://github.com/ecederstrand/exchangelib/issues/1347


Solution

  • If your tenant does not have active Microsoft 365 license/subscription, Office 365 Exchange Online API permissions won't appear like this:

    enter image description here

    To resolve this, make sure to acquire an active Microsoft 365 license for your tenant as below:

    enter image description here

    After acquiring that license, you can find Office 365 Exchange Online API permissions like this:

    enter image description here

    In your case, you can activate a free trial subscription for Microsoft 365, which temporarily grants you access to the "Office 365 Exchange Online" API permissions but not permanently.

    Alternatively, you can make use of Microsoft Graph API but it's not suitable for exchangelib.

    Reference:

    cannot found Office 365 Exchange Online api - Microsoft Q&A by Vasil Michev