title: Graph API - Insufficient privileges to complete the operation
body: <p>When trying to access the Graph Service Client using  I am receiving the error :</p>
  
  <blockquote>
    <p>Code: Authorization_RequestDenied<br>
    Message: Insufficient privileges to complete the operation.</p>
  </blockquote>
  
  <p>After researching this error the most common solution was to set the permissions for the API. This had already been done and has permissions to read basic/full profiles. </p>
  
  <p>I've delete and re-added the APIs. </p>
  
  <p>Below is the code in my <code>AzureAuthenticationProvider</code> class which inherits from <code>IAuthenticationProvider</code>:    </p>
  
  <pre><code>public class AzureAuthenticationProvider : IAuthenticationProvider
  {
      private string _azureDomain = "myDevDom.onmicrosoft.com";
  
      public async Task AuthenticateRequestAsync(HttpRequestMessage request)
      {
          try
          {
              string clientId = "2b823c67-1b0d-4a10-a9e1-737142516f5q";
              string clientSecret = "xxxxxx";
  
              AuthenticationContext authContext = new AuthenticationContext("https://login.windows.net/" + _azureDomain + "/oauth2/token");
  
              ClientCredential credentials = new ClientCredential(clientId, clientSecret);
  
              AuthenticationResult authResult = await authContext.AcquireTokenAsync("https://graph.microsoft.com/", credentials);
  
              request.Headers.Add("Authorization", "Bearer " + authResult.AccessToken);
          }
          catch (Exception ex)
          {
          }
      }
  }
  </code></pre>
  
  <p>I've tried changing the client secret to an invalid Id and it threw an error, so the client key is correct. I've  also tried to verify that the access token is valid by altering the access token, this also returns a error. </p>
  
  <p>The above code seems to work fine. </p>
  
  <p>Below is the code where I'm trying to access Azure AD:</p>
  
  <pre><code>public async Task&lt;IGraphServiceUsersCollectionPage&gt; GetUsersByLastName(string lastname)  
  {
      GraphServiceClient graphClient = new GraphServiceClient(new AzureAuthenticationProvider());
      string filter = String.Format("startswith(surname, '{0}')", lastname);
      IGraphServiceUsersCollectionPage users = await graphClient.Users.Request().Filter(filter).GetAsync(); //Fails on this line
      return users;
  }
  </code></pre>
  
  <p>Any help is much appreciated, and thanks in advance for any help. <a href="https://i.stack.imgur.com/1KCiY.png" rel="noreferrer"><img src="https://i.stack.imgur.com/1KCiY.png" alt="azureADpermissionProperties"></a></p>