question

CristianAlberch-9121 avatar image
0 Votes"
CristianAlberch-9121 asked MayankBargali-MSFT answered

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

I've followed the Microsoft Ingest-iot-hub-data tutorial: https://docs.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




azure-functionsmicrosoft-identity-managerazure-digital-twins
image.png (23.5 KiB)
image.png (10.4 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Adding a note that this thread relates with another issue opened in the doc: https://github.com/MicrosoftDocs/azure-docs/issues/92112

0 Votes 0 ·

1 Answer

MayankBargali-MSFT avatar image
1 Vote"
MayankBargali-MSFT answered

@CristianAlberch-9121 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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.