I want to request a token using the clientID of a user-assigned managed identity as the scope, so that the token I receive has the clientID as its audience.
To achieve this, I used the following code in C#:
var credential = new DefaultAzureCredential(new DefaultAzureCredentialOptions
{
ManagedIdentityClientId = clientID
});
var token = await credential.GetTokenAsync(new TokenRequestContext(new[]
{ $"{clientID}/.default" }) { });
This code is running in an Azure App Service that has the user-assigned managed identity assigned to it.
My problem is that this process already worked for me and I received the token in the way I need. Unfortunately this suddenly stopped working without me changing anything neither in the code nor in my Azure configuration. I now get the following error:
ManagedIdentityCredential authentication failed: Service request failed. Status: 500 (Internal Server Error) Content: {“statusCode”:500,”message”:”An unexpected error occured while fetching the AAD Token.”
I am still able to request a token when using a different scope. What could cause this issue? Thanks for your help.
Felikan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.