App throws error: ManagedIdentityCredential authentication failed: No Managed Identity found for specified ClientId/ResourceId/PrincipalId.Status: 400

Cristian Alberch 21 Reputation points
2022-04-27T18:00:57.9+00:00

I've followed the Microsoft Ingest-iot-hub-data tutorial: https://learn.microsoft.com/en-us/azure/digital-twins/how-to-ingest-iot-hub-data?tabs=cli

and made sure that the App deployed to ingest data from IoT hub to Digital Twin has the required Azure Digital Twin data-owner access. The code used was that shown in the tutorial: IoTHubtoTwins.cs, except that: public async void Run([EventGridTrigger] EventGridEvent eventGridEvent, ILogger log)
was changed to public async Task Run([EventGridTrigger] EventGridEvent eventGridEvent, ILogger log)

Tha App runs on a trigger event when getting data (I've tried the simulated data in the tutorials as well as actual data from Raspberry PI).

197010-image.png

I wasn't getting the Digital Twin to update, so monitored the App log stream and found that the function was throwing out an error related to Managed Identity.

I've checked everywhere for holes in role access, and it is all covered. It must be something else(?) I've been stuck for days on this. Thank you!

197121-image.png

Microsoft Identity Manager
Microsoft Identity Manager
A family of Microsoft products that manage a user's digital identity using identity synchronization, certificate management, and user provisioning.
620 questions
Azure Digital Twins
Azure Digital Twins
An Azure platform that is used to create digital representations of real-world things, places, business processes, and people.
220 questions
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,316 questions
{count} votes

Accepted answer
  1. MayankBargali-MSFT 68,656 Reputation points
    2022-04-29T04:05:01.013+00:00

    @Cristian Alberch Thanks for reaching out. The document has been updated to reflect the right code and it will be published soon.
    On step3 of sample code here please replace the old code with the new code for Authenticate with Digital Twins

    **Old Code: **

    var cred = new ManagedIdentityCredential("https://digitaltwins.azure.net");  
                    var client = new DigitalTwinsClient(  
                        new Uri(adtInstanceUrl),  
                        cred,  
                        new DigitalTwinsClientOptions { Transport = new HttpClientTransport(httpClient) });  
    

    **Update Code: **

    var cred = new DefaultAzureCredential();  
    var client = new DigitalTwinsClient(new Uri(adtInstanceUrl), cred);  
    

    Feel free to get back to me if you need any assistance.

    Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community looking for help on similar topics.

    3 people found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful