Thanks for posting your question in the Microsoft Q&A forum.
Enable managed identity for your web app in Azure. grant the managed identity access to your Azure Translator resource. use the appropriate SDK to retrieve an access token using the managed identity and use the token to authenticate your requests to the Translator service.
Here's an example of how you might retrieve and use the token in C#:
using Azure.Identity;
using Azure.Core;
using System.Net.Http;
using System.Text;
using System.Text.Json;
var credential = new ManagedIdentityCredential();
var scope = "https://cognitiveservices.azure.com/.default";
var accessToken = await credential.GetTokenAsync(new TokenRequestContext(new[] { scope }));
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {accessToken.Token}");
client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Region", "<your-region>");
var content = new StringContent("[{'Text':'Hello, world!'}]", Encoding.UTF8, "application/json");
var response = await client.PostAsync("https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&to=es", content);
var responseContent = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseContent);
}
Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful