title: How to authenticate with Azure Resource Manager using managed identity in C#
body: <p>I am trying to use the managedIdentity to get a token that I can then use to list resources in the resource group. I am getting an error when attempting to get the token. The GetToken() api seems to be adding other strings (offline_access openid) internally to the scope I provided and fails that the scope is not a valid url. From the error, it appears that I am not using the api correctly. But I am also following the documentation. Could some one please help track down what the issue is in my code.</p>
  <p>Code:</p>
  <pre><code>var managedIdentityCredential = new DefaultAzureCredential(new DefaultAzureCredentialOptions { ManagedIdentityClientId = managedIdentityId });
  var azureServiceTokenProvider = new AzureServiceTokenProvider(&quot;RunAs=App&quot;);
  AccessToken accessToken = managedIdentityCredential.GetToken(new TokenRequestContext(new string[] { &quot;https://management.azure.com/&quot; }));
  </code></pre>
  <p>Error:
  Azure.Identity.AuthenticationFailedException: SharedTokenCacheCredential authentication failed. ---&gt; Microsoft.Identity.Client.MsalServiceException: AADSTS70011: The provided request must include a 'scope' input parameter. The provided value for the input parameter 'scope' is not valid. The scope <a href="https://management.azure.com/" rel="nofollow noreferrer">https://management.azure.com/</a> offline_access openid profile is not valid. The scope format is invalid. Scope must be in a valid URI form <a href="https://example/scope" rel="nofollow noreferrer">https://example/scope</a> or a valid Guid &lt;guid/scope&gt;.</p>