How communicate between Azure Communication Service and function using Managed identity

Debashis Jena 76 Reputation points
2023-05-23T07:39:38.25+00:00

We have a requirement to send SMS using Azure Communication Service from Azure Function.

How to send SMS using Azure Communication Service from Azure Function app using Managed identity authentication?

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,930 questions
Azure Communication Services
Azure Communication Services
An Azure communication platform for deploying applications across devices and platforms.
1,240 questions
{count} votes

2 answers

Sort by: Most helpful
  1. VenkateshDodda-MSFT 25,111 Reputation points Microsoft Employee Moderator
    2023-05-24T07:51:25.16+00:00

    @Debashis Jena Thanks for your patience on this.

    By enabling the Managed identity on the Azure functions and by granting Contributor role to that identity on the ACS resource you will be able to authenticate and send the SMS to specific users.

    You can refer to the GitHub sample example on how to authenticate and generate access token to ACS resource using Managed identity.
    Feel free to reach back to me if you have any further questions on this.

    0 comments No comments

  2. Lohith Goudagere Nagaraj 0 Reputation points Microsoft Employee
    2023-05-24T13:45:13.6933333+00:00

    Hi,

    Steps:

    • When you create the Function resource in Azure, enable managed identity
    • On the Az Communication Service, add the function managed identity as a contributor
    • In the function when you instantiate the SmsClient, use the below code:
    string endpoint = "<endpoint_url>"; 
    TokenCredential tokenCredential = new DefaultAzureCredential(); 
    SmsClient client = new SmsClient(new Uri(endpoint), tokenCredential);
    
    

    Hope this helps.

    Note: If my notes solved your issue/problem, do mark this as Accepted Answer. Thanks

    0 comments No comments

Your answer

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