title: Microsoft Graph API: Authorization_IdentityNotFound
body: <p>I'm following the <a href="https://developer.microsoft.com/en-us/graph/docs/concepts/auth_v2_service" rel="nofollow noreferrer">Get access without a user</a> guide to write a Python script that will call Microsoft Graph.  </p>
  
  <p>This script will be scheduled from cron so it cannot get admin consent (therefore authorize using Client Credentials).  I am able to successfully obtain a token using this call:</p>
  
  <pre><code>request_url = "https://login.microsoftonline.com/mytenant.onmicrosoft.com/oauth2/v2.0/token"
  data = { 
     'Host' : 'login.microsoftonline.com',
     'Content-Type' : 'application/x-www-form-urlencoded',
     'client_id' : 'my-client-id-1234',
     'scope' : 'https://graph.microsoft.com/.default',
     'client_secret' : client_secret,
     'grant_type' : 'client_credentials'
  }
  response = requests.post(url = request_url, data = data)
  </code></pre>
  
  <p>I then try to get a user listing with this call, using the valid token:</p>
  
  <pre><code>request_url = "https://graph.microsoft.com/v1.0/users"
  headers = { 
     'Authorization' : 'Bearer ' + token,
     'Host' : 'graph.microsoft.com'
  }
  response = requests.get(url = request_url, headers = headers)
  </code></pre>
  
  <p>The problem is that I get an <code>Authorization_IdentityNotFound</code> error:</p>
  
  <pre><code>&lt;Response [401]&gt;
  {
     "error": {
        "code": "Authorization_IdentityNotFound",
        "message": "The identity of the calling application could not be established.",
        "innerError": {
           "request-id": "2257f532-abc4-4465-b19f-f33541787e76",
           "date": "2018-03-27T19:11:07"
        }
     }
  }
  </code></pre>
  
  <p>These are the permissions I've selected:</p>
  
  <p><a href="https://i.stack.imgur.com/DgMlV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DgMlV.png" alt="graphPermsScreenshot"></a></p>
  
  <p>Any idea how to fix this error?</p>