An Azure service to easily conduct machine translation with a simple REST API call.
Hello Rishikesh S,
Welcome to the Microsoft Q&A and thank you for posting your questions here.
I understand that you're asking how you can connect Azure Translator text translation from an Azure Function using Managed Identity.
The 401 PermissionDenied error was caused by using the wrong authorization path for Azure Translator. Also, assigning Cognitive Services Contributor is not sufficient for Microsoft Entra ID / Managed Identity calls to Translator, because the supported role for Translator API access is Cognitive Services User. The request must also use the correct Microsoft Entra token audience and the correct Translator endpoint. - https://learn.microsoft.com/en-us/azure/ai-services/translator/how-to/microsoft-entra-id-auth, https://learn.microsoft.com/en-us/azure/ai-services/translator/text-translation/reference/authentication, https://learn.microsoft.com/en-us/dotnet/api/azure.provisioning.cognitiveservices.cognitiveservicesbuiltinrole.cognitiveservicescontributor?view=azure-dotnet
The best practice is to:
- Enable a system-assigned or user-assigned managed identity on the Azure Function App.
- Assign the Function App managed identity the Cognitive Services User role on the Azure Translator resource scope.
- Request the Microsoft Entra access token using this scope:
https://cognitiveservices.azure.com/.default. - Call Translator using the custom subdomain endpoint, for example:
https://<translator-resource-name>.cognitiveservices.azure.com/translator/text/v3.0/translate?api-version=3.0&to=fr. - Do not use Microsoft Entra / Managed Identity authentication if the Translator resource is configured with Selected Networks, Private Endpoints, or VNet endpoint mode; in that network-restricted mode, the supported path is key-based authentication against the Translator virtual network/custom endpoint, or the network restriction must be removed if Managed Identity is required.
After assigning Cognitive Services User, using the correct token scope, and calling the Translator custom subdomain endpoint, the Function App can authenticate to Azure Translator with Managed Identity successfully. If the resource is in private/network-restricted mode, switch to key-based authentication or redesign the network/authentication approach. - https://learn.microsoft.com/en-us/azure/ai-services/translator/how-to/use-firewalls
Use the below resource links for more reading and steps:
- Enable Microsoft Entra ID authentication for Azure Translator
- Azure Translator authentication and authorization
- Custom subdomains for Azure AI services
- Use managed identities for App Service and Azure Functions
- Azure Identity authentication best practices for .NET
- Translator virtual network / firewall behavior
I hope this is helpful! Do not hesitate to let me know if you have any other questions, steps or clarifications.
Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful.