Office 365 – Microsoft Graph – Part 3 – Azure Access Token: to call Graph APIs from CSOM

Hi All,

In this article we will discuss most important concept “Azure Access Token”, which we require to call Graph APIs.

In last couple of articles, we started discussion about Microsoft Graph and one simple use case – to fetch Office 365 groups using Microsoft Graph APIs and using CSOM.

We have certain steps to use Graph APIs and in last following couple of articles we are discussing those steps

Office 365 – Microsoft Graph and Graph Explorer

Office 365 – Microsoft Graph beginning – Part 1

Office 365 – Microsoft Graph – Part 2 – Granting permission to Azure Apps to use Microsoft Graph APIs using CSOM

In this article we will discuss most important concept – Azure Access Token, we require Access Token to call the Graph APIs.

Let’s begin the show:

What is Access Token?

Access Token is 64-bit encoded JSON Web Token (JWT)



Access token contains information about

  1. our app (claim).
  2. Permission app has for the resource (Microsoft cloud service => Office 365 Groups, Users, Mail, contact etc.) – ensures that caller has proper permissions
  3. It contains information about API available through Microsoft Graph

Steps to get the Access Token in CSOM code

  1. To call Microsoft Graph, our app must acquire an access token from Azure Active Directory (AD), Microsoft cloud identity service.
  2. Our app need to be able to authenticate with Azure AD.
  3. We attach the access token as a Bearer token to the Authorization header in HTTP request as


Authorization: Bearer EwAoA8l6BAAU … 7PqHGsykYj7A0XqHCjbKKgWSkcAg==

Host:` GET

/// <summary>
/// Method to set the access token to HttpRequestMessage header
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public async Task AuthenticateRequestAsync(HttpRequestMessage request)
   //Azure App ID	
   string clientId = "";
   //Client secret key	
   string clientSecretKey = "";
   string authority = "<TenantID>";
   // AuthenticationContext – class used to retrieve authentication token from Azure AD and ADFS service
  AuthenticationContext authenticationContext = new AuthenticationContext(authority);
 //Client credential object – we are connecting Azure on be half of App
 ClientCredential clientCredential = new ClientCredential(clientId, clientSecretKey);
//Getting AccessToken
AuthenticationResult authResult = await authenticationContext.AcquireTokenAsync("", clientCredential);

//Setting the token in header of HttpRequestMessage object 	
request.Headers.Add("Authorization", "Bearer " + authResult.AccessToken);


Azure Active Directory access tokens

Authorize access to Azure Active Directory web applications using the OAuth 2.0 code grant flow

AuthenticationContext Class

AuthenticationResult Class

Thanks for reading 😊

Keep reading, share your thoughts, experiences. Feel free to contact us to discuss more.

If you have any suggestion / feedback / doubt, you are most welcome. Stay tuned on Knowledge-Junction, will come up with more such articles

Prasham Sabadra

LIFE IS VERY BEAUTIFUL :) ENJOY THE WHOLE JOURNEY :) Founder of Knowledge Junction and, Author, Learner, Passionate Techie, avid reader. Certified Professional Workshop Facilitator / Public Speaker. Scrum Foundation Professional certificated. Motivational, Behavioral , Technical speaker. Speaks in various events including SharePoint Saturdays, Boot camps, Collages / Schools, local chapter. Can reach me for Microsoft 365, Azure, DevOps, SharePoint, Teams, Power Platform, JavaScript.

You may also like...

2 Responses

  1. April 9, 2019

    […] Graph – Part 2 – Granting permission to Azure Apps to use Microsoft Graph APIs using CSOMOffice 365 – Microsoft Graph – Part 3 – Azure Access Token: to call Graph APIs from CSOMOffice 365 – Microsoft Graph – Part 4 – Fetching all Office 365 groups using CSOM- […]

  2. December 11, 2021

    […] For more details on Access Token please have a look once our article – Office 365 – Microsoft Graph – Part 3 – Azure Access Token: to call Graph APIs from CSOM […]

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: