System-assigned managed identity to request an access token

Chunhui You 0 Reputation points Microsoft Employee

I have an Azure Function app, calls Azure text translate service restful API endpoint. Now I want to use the system assigned managed identity to request an access token and use that token to authenticate (bearer token in http header). However, I got an error below. Here is my code to request access token. Does anyone have clue?
var azureServiceTokenProvider = new DefaultAzureCredential(options);

            AccessToken accessToken = await azureServiceTokenProvider.GetTokenAsync(new TokenRequestContext(new[] { "" }));
Failed to translate. The exception is: Azure.Identity.AuthenticationFailedException: ManagedIdentityCredential authentication failed: Service request failed.
Status: 500 (Internal Server Error)

{"statusCode":500,"message":"An unexpected error occured while fetching the AAD Token.","correlationId":"3588c043-9b25-471f-b7b6-415905a000f0"}

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,520 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
20,228 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Luis Arias 5,601 Reputation points

    Hello Chunhui You,

    It looks like you are trying to use the system assigned identity to get the access token to use on the Azure AI service API call. Like this example:

    First I suggest to verify the endpoint url and the procedure itself, here an example using Service principal that also can help you to setup your call on function app:

    You can follow this documentation:

    Please take a look on the information shared and reach out again if you need more assistance.


    0 comments No comments