Can we authenticate Translator service with Microsoft Entra ID

lakshmi 551 Reputation points
2024-02-14T07:53:19.22+00:00

Hi Team,   Currently we are using translator text endpoint and key for accessing the azure translator service. We wanted to change this method to RBAC to increase the security.    We have referred the below document and in the steps it has mentioned creating the access token using the login Microsoft link and by providing the client id and secret.  We have implemented the same RBAC access for cosmos client and we were able to access the cosmos db tables by creating tokens using the Default azure credentials of Azure identity package.   Can we use same azure identity token to authenticate translator service

Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,771 questions
0 comments No comments
{count} votes

Accepted answer
  1. James Hamil 22,186 Reputation points Microsoft Employee
    2024-02-14T21:24:36.5833333+00:00

    Hi @lakshmi , yes, this should be possible! You can use the Azure Identity package to authenticate with the Translator service using RBAC. The Azure Identity package provides a set of credential types that can be used to authenticate with Azure services, including the Translator service.

    To authenticate with the Translator service using Azure Identity, you can use the DefaultAzureCredential class, which provides a default authentication flow for applications that will be deployed to Azure. The DefaultAzureCredential class tries several authentication methods in order, including managed identity, Visual Studio Code credential, Visual Studio credential, and Azure CLI credential.

    Here's an example of how to authenticate with the Translator service using DefaultAzureCredential:

    using Azure;
    using Azure.AI.Translator.DocumentTranslation;
    using Azure.Identity;
    
    // Create a new instance of DefaultAzureCredential
    var credential = new DefaultAzureCredential();
    
    // Create a new instance of DocumentTranslationClient using the credential
    var client = new DocumentTranslationClient(new Uri(endpoint), credential);
    
    // Use the client to call the Translator service
    var result = await client.TranslateDocumentAsync(sourceUri, targetUri, "fr");
    

    In this example, endpoint is the endpoint URL for the Translator service, sourceUri is the URI of the source document, targetUri is the URI of the target document, and "fr" is the target language.

    Please let me know if you have any questions and I can help you further.

    If this answer helps you please mark "Accept Answer" so other users can reference it.

    Thank you,

    James


0 additional answers

Sort by: Most helpful