How to authenticate Email Communication Service with service principal with secret?

Nicholas 25 Reputation points
2025-05-15T07:28:14.6933333+00:00

I have an email communication service that I'm trying to authenticate with

credential = DefaultAzureCredential()

It works in local development but not in production, throwing an error:

DefaultAzureCredential failed to retrieve a token from the included credentials.

I then define AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET and AZURE_AUTHORITY_HOST

I still get this error:

(Denied) Denied by the resource provider.

Code: Denied

Message: Denied by the resource provider.

Azure Communication Services

1 answer

Sort by: Most helpful
  1. Sampath 3,885 Reputation points Microsoft External Staff Moderator
    2025-05-16T03:42:09.9666667+00:00

    Hello @Nicholas ,

    Set the following environment variables in your production environment in App Service :

    
    AZURE_CLIENT_ID=<your-app-client-id>
    
    AZURE_TENANT_ID=<your-azure-ad-tenant-id>
    
    AZURE_CLIENT_SECRET=<your-app-client-secret>
    
    

    Make sure you enable Identity in the Azure Web App, enable System Assigned Managed Identity, and assign the appropriate roles such as 'Communication and Email Service Owner', or any other required roles?

    If you are having below problems

    image

    after enabling identity, follow the process below:

    After enabling identity, go to Communication Service and select Access Control. Then, select Communication and Email Service Owner, choose Managed Identity, search for the web app name with identity enabled, assign roles, and try again.

    Hope this helps!


    If this answers your query, do click Accept Answer and Yes for was this answer helpful, which may help members with similar questions.

    If you have any other questions or are still experiencing issues, feel free to ask in the "comments" section, and I'd be happy to help.

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.