title: MSGraph Authenticating to dynamics with correct token gives 401
body: <p>Using the following code I can connect to MSGraph (different resource url) and fetch the data that I need, but I'm struggling to realise how to do the same for Microsoft Dynamics (CRM)</p>
  
  <pre><code>public static async Task&lt;string&gt; GetTokenForApplication(string resourceUrl)
  {
      AuthenticationContext authenticationContext = 
           new AuthenticationContext(AppModeConstants.AuthString, false);
  
      ClientCredential clientCred = new ClientCredential(AppModeConstants.ClientId, AppModeConstants.ClientSecret);
      AuthenticationResult authenticationResult = await authenticationContext
             AcquireTokenAsync("resourceUrl", clientCred);
  
      TokenForApplication = authenticationResult.AccessToken;
  }
  
  public static async Task CrmTest()
  {
          var token = await AuthenticationHelper.GetTokenForApplication(@"https://myapp.crm4.dynamics.com/");
  
          HttpClient client = new HttpClient();
  
          client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
          client.DefaultRequestHeaders.Accept.Clear();
          client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
  
          var response = await client.GetAsync(@"https://myapp.crm4.dynamics.com/api/data/v8.2/accounts");
  }
  </code></pre>
  
  <p>Although I fetch the right token I'll still get a 401: Unauthorized:</p>
  
  <pre><code>{StatusCode: 401, ReasonPhrase: 'Unauthorized', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
  {
    REQ_ID: 790b38b0-c8c0-4878-a318-e490ee7db57a
    Strict-Transport-Security: max-age=31536000; includeSubDomains
    Date: Thu, 11 May 2017 15:33:41 GMT
    Set-Cookie: crmf5cookie=!UXdAbawdawdal8sNiJ9xy74dAiawdawdDnDsomethingAolDYjkR7innjWIYQ1pV+DcZ9A=;secure; path=/
    Server: Microsoft-IIS/8.5
    WWW-Authenticate: Bearer authorization_uri=https://login.windows.net/b8faag21-awda-awda-90s4-f8652ss86ddb/oauth2/authorize, resource_id=https://myapp.crm4.dynamics.com/
    X-Powered-By: ASP.NET
    Content-Length: 49
    Content-Type: text/html
  }}
  </code></pre>
  
  <p>A 403 I would understand, but a 401 means that I'm simply using the wrong authentication. Any input on this would be appreciated.</p>
  
  <p><strong>Edit: Is it even possible to access CRM data as an application? There are only delegated permissions available in the azure portal, no application permissions.</strong></p>