title: Access token validation failure Microsoft Graph API
body: <p>I am building a <code>console application</code> in C#.<br> I want to make some calls to <strong>Microsoft Graph API</strong> to access and edit some Excel files in my <em>SharePoint</em> so I can automate some processes in my Organization.</p>
  
  <p><br></p>
  
  <p>The logic of the app is simple. </p>
  
  <ol>
  <li>I call <code>Azure Active Directory</code> to <strong>authenticate</strong> this console application using the <strong>clients credential flow</strong> which means we will provide a clientsID and AppKey. I took the clientsID and AppKey from Azure <strong>Active Directory > App Registrations</strong>.
  <a href="https://i.stack.imgur.com/7CFDv.png" rel="noreferrer"><img src="https://i.stack.imgur.com/7CFDv.png" alt="enter image description here"></a></li>
  <li>Then I want to receive the access token and use this to make a GET Request to the <strong>Microsoft Graph API</strong>. 
  <br>E.g <code>https://graph.microsoft.com/v1.0/me/</code>
  <br><br>But then <strong>response</strong> I get is this:</li>
  </ol>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>{
    "error": {
      "code": "InvalidAuthenticationToken",
      "message": "Access token validation failure. Invalid audience.",
      "innerError": {
        "request-id": "0a3ec**************",
        "date": "2019-10-15T13:54:33"
      }
    }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p><strong>Below</strong> you will find the full code of my application with the two methods of getting the access token and calling the Graph API:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>using Microsoft.IdentityModel.Clients.ActiveDirectory;
  using System;
  using System.Collections.Generic;
  using System.Globalization;
  using System.IdentityModel.Tokens;
  using System.IO;
  using System.Linq;
  using System.Net;
  using System.Net.Http;
  using System.Net.Http.Headers;
  using System.Text;
  using System.Threading.Tasks;
  using AuthenticationContext = Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext;
  
  namespace Project_Budget
  {
      class Program
      {
          private const string clientId = "14f1****************";
          private const string aadInstance = "https://login.microsoftonline.com/{0}";
          private const string tenant = "******.onmicrosoft.com";
          private const string resource = "https://graph.windows.net";
          private const string appKey = "IKV***********";
          static string authority = String.Format(CultureInfo.InvariantCulture, aadInstance, tenant);
  
          private static HttpClient httpClient = new HttpClient();
          private static AuthenticationContext context = null;
          private static ClientCredential credential = null;
  
          static void Main(string[] args)
          {
              context = new AuthenticationContext(authority);
              credential = new ClientCredential(clientId,appKey);
  
              Task&lt;string&gt; token = GetToken();
              token.Wait();
              //Console.WriteLine(token.Result + "\n");
  
              Task&lt;string&gt; graphCall = GetExcelFile(token.Result);
              graphCall.Wait();
              Console.WriteLine(graphCall.Result + "\n");
              Console.ReadLine();
  
          }
  
          private static async Task&lt;string&gt; GetExcelFile(string result)
          {
              string apiJsonResult = null;
              
              var apiCallString = "https://graph.microsoft.com/v1.0/me/";
           
              httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", result);
              var getResult = await httpClient.GetAsync(apiCallString);
  
              if (getResult.Content != null)
              {
                  apiJsonResult = await getResult.Content.ReadAsStringAsync();
              }
  
              
              return apiJsonResult;
          }
  
          private static async Task&lt;string&gt; GetToken() 
          {
              AuthenticationResult result = null;
              string token = null;
              result = await context.AcquireTokenAsync(resource, credential); //authentication context object
              token = result.AccessToken;
              return token;
          }
  
          
      }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>I have given all the <strong>access</strong> required for the app to run. Also I run the query on <code>Graph Explorer</code> and runs properly.<br>
  <a href="https://i.stack.imgur.com/NFRa8.png" rel="noreferrer"><img src="https://i.stack.imgur.com/NFRa8.png" alt="enter image description here"></a>
  Why do I get this error on the console application?</p>