Get Trusted OAuth2 Access Token for Office 365 with Azure AD

I discuss the importance of having a trusted OAuth2 access token by Office 365 and explain how to obtain it using Azure AD. Read on for more details.

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 setup Azure AD 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 Azure AD 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 Azure AD, before retrieving an access token, if they haven’t already done so Azure AD 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:

Azure AD Authentication

Azure AD Authentication

So how do you create this Azure AD 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 .

At present the Azure Preview Portal does not give you the ability to create and manage Azure AD apps so you have to use the full portal for now.

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

Andrew Connell
Developer & Chief Course Artisan, Voitanos LLC. | Microsoft MVP
Written by Andrew Connell

Andrew Connell is a web developer with a focus on Microsoft Azure & Microsoft 365. He’s received Microsoft’s MVP award every year since 2005 and has helped thousands of developers through the various courses he’s authored & taught. Andrew’s the founder of Voitanos and is dedicated to delivering industry-leading on-demand video training to professional developers. He lives with his wife & two kids in Florida.