Get OAuth2 Access Tokens Microsoft 365 with Entra ID

I discuss the importance of having a OAuth2 access token for Microsoft 365 and explain how to obtain it using Microsoft Entra ID.

By Last Updated: June 24, 2024 2 minutes read

Before you even get started coding against the Office 365 APIs, you need to get an OAuth2 access token that is trusted by Office 365. Microsoft has set up Microsoft Entra ID as the trust and token issuer for Office 365 which is a great solution because you can use it to store your users or you can configure it to federate logins with your on-premises Active Directory or third party authentication system.

In order to obtain the access token you have to create an application in Microsoft Entra ID that has been given the necessary permissions to access resources in Office 365 like reading your calendar or writing to your contacts. Once you do that, when a user successfully authenticates against Microsoft Entra ID, before retrieving an access token, if they haven’t already done so Microsoft Entra ID will prompt them to grant consent to the application to do the things that the developer configured in the app such as reading your calendar and singing you in:

Microsoft Entra ID Authentication

Microsoft Entra ID Authentication

So how do you create this Microsoft Entra ID app? There are two ways at the present time. You can use the Add Connected Service dialog in Visual Studio 2013 to do this or you can create it manually form the Azure Management Portal.

So let’s get started. You can read through the next two posts in order, or just jump to the one that interests you: