title: Azure managed identity error - Could not find identity for access token
body: <p>I am trying to get managed identity object of Azure data factory programmatically (using Python).</p>
  <p>To do so, I am following the below steps:</p>
  <ol>
  <li>Register an App in Azure Active Directory to get client ID, add client secret, tenant id, scope.</li>
  <li>Followed the steps in below link to get an access token for the registered app in #1:
  <a href="https://github.com/AzureAD/microsoft-authentication-library-for-python/blob/dev/sample/confidential_client_secret_sample.py" rel="nofollow noreferrer">https://github.com/AzureAD/microsoft-authentication-library-for-python/blob/dev/sample/confidential_client_secret_sample.py</a></li>
  <li>Add the registered app to the data factory subscription with role as 'Owner'</li>
  <li>Use the below code:</li>
  </ol>
  <pre><code>head = {&quot;Authorization&quot;: &quot;Bearer {}&quot;.format(request_token)} 
  #request_token is the access token from #2   
  requests.get('https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}?api-version=2018-06-01', headers = head)
  </code></pre>
  <p>as provided in link :
  <a href="https://docs.microsoft.com/en-us/azure/data-factory/data-factory-service-identity" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/azure/data-factory/data-factory-service-identity</a></p>
  <p>After following these steps, the response from #5 is
  error=&quot;invalid_token&quot;, error_description=&quot;Could not find identity for access token.&quot;</p>
  <p>The app registration does not have an identity section to check for managed identity.</p>
  <p>Am I missing any step here?</p>
  <p>Please find below the code. Thanks for your time!</p>
  <pre><code>import sys  
  import json
  import logging
  
  import requests
  import msal
  
  
  
  input_client_id = &lt;client_id&gt;
  input_authority = &quot;https://login.microsoftonline.com/&lt;tenant_id&gt;&quot;
  input_secret = &lt;client_Secret&gt;
  input_scope = [&quot;https://graph.microsoft.com/.default&quot;]
  input_endpoint = &quot;https://graph.microsoft.com/v1.0/applications&quot;
  
  app = msal.ConfidentialClientApplication(
      input_client_id, authority=input_authority,
      client_credential=input_secret,
      # token_cache=...  # Default cache is in memory only.
                         # You can learn how to use SerializableTokenCache from
                         # https://msal-python.rtfd.io/en/latest/#msal.SerializableTokenCache
      )
  
  
  result = app.acquire_token_for_client(scopes=input_scope)
  
  print('Access Token', result['access_token'])
  request_token = result['access_token']
  head = {&quot;Authorization&quot;: &quot;Bearer {}&quot;.format(request_token)}
  response = requests.get('{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}?api-version=2018-06-01', headers=head)
  </code></pre>
  <p>Part of the error response:</p>
  <pre><code>{'Cache-Control': 'no-cache', 'Pragma': 'no-cache', 'Content-Type': 'application/json; charset=utf-8', 'Expires': '-1', 'WWW-Authenticate': 'Bearer authorization_uri=&quot;https://login.windows.net/&lt;tenant_id&gt;&quot;, error=&quot;invalid_token&quot;, error_description=&quot;Could not find identity for access token.&quot;'
  </code></pre>