Hi @Gnetchejo, Patrick Juvet Greetings! Welcome to Microsoft Q&A forum. Thank you for posting the question here.
The sample code from the tutorial Coding with the Azure Digital Twins SDK uses DefaultAzureCredential (part of the Azure.Identity
library) to authenticate users with the Azure Digital Twins instance. With DefaultAzureCredential
, the sample will search for credentials in your local environment, like an Azure sign-in in a local Azure CLI or in Visual Studio or Visual Studio Code.
The error message implies that the authentication failed. Did you sign in into the Visual Studio code using the same Azure credentials that you want to use to access your Azure Digital Twins instance? If you do not want to sing in into Visual Studio Code, you can install Azure CLI on your machine and authenticate locally using the az login
command from the Command prompt. After you authenticate using this command, you should be able to execute the code without any issues.
Kindly note that there is known issue with Azure.Identity library that causes the DefaultAzureCredential method to throw the following error Azure.Identity.AuthenticationFailedException: SharedTokenCacheCredential authentication failed
. If you face this issue, you can resolve it by adding an optional parameter as follows new DefaultAzureCredential(new DefaultAzureCredentialOptions { ExcludeSharedTokenCacheCredential = true })
when instantiating the DefaultAzureCredential
Hope this helps. Please let us know if you need further assistance or have any follow up questions.
If the response helped, please do click Accept Answer and Yes. Doing so would help other community members with similar issue identify the solution. I highly appreciate your contribution to the community.