Loading...
「ツール」は右上に移動しました。
利用したサーバー: wtserver1
0いいね 20 views回再生

Resolving the AADSTS500011 Error: Access Token Issues with Azure Function Apps

Learn how to fix the `AADSTS500011` error when acquiring access tokens for Azure Function Apps using managed identities. Step-by-step guide included!
---
This video is based on the question https://stackoverflow.com/q/67399396/ asked by the user 'prakashrajansakthivel' ( https://stackoverflow.com/u/2689398/ ) and on the answer https://stackoverflow.com/a/67430000/ provided by the user 'prakashrajansakthivel' ( https://stackoverflow.com/u/2689398/ ) at 'Stack Overflow' website. Thanks to these great users and Stackexchange community for their contributions.

Visit these links for original content and any more details, such as alternate solutions, latest updates/developments on topic, comments, revision history etc. For example, the original title of the Question was: Unable to get access token. 'AADSTS500011: The resource principal named 'xxx' was not found in the tenant -tenantid

Also, Content (except music) licensed under CC BY-SA https://meta.stackexchange.com/help/l...
The original Question post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/... ) license, and the original Answer post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/... ) license.

If anything seems off to you, please feel free to write me at vlogize [AT] gmail [DOT] com.
---
How to Fix the AADSTS500011 Error When Fetching Access Tokens in Azure Function Apps

If you’re working with Azure Function Apps and you encounter the error message AADSTS500011: The resource principal named 'xxx' was not found in the tenant 'tenantid' while trying to obtain an access token, you're not alone. This issue can be particularly frustrating for developers leveraging Azure's Managed Identity feature. Fortunately, there's a straightforward solution. In this guide, we’ll walk through the problem and outline a step-by-step solution to help you fetch access tokens successfully.

Understanding the Problem

When you attempt to get an access token using the Azure.Identity NuGet package and receive the AADSTS500011 error, it indicates that the system cannot find the specified resource in your Azure Active Directory (AAD) tenant. Here's what happens in a typical scenario:

You have created an Azure Function App with a system-assigned managed identity.

You attempt to fetch an access token using the DefaultAzureCredential class from the Azure SDK.

Instead of receiving a valid token, you encounter an error indicating that the resource principal is missing.

This issue can arise for several reasons, including misconfiguration in Azure Active Directory or insufficient permissions granted to the application to fetch an access token.

Step-by-Step Solution

If you're facing this issue, follow these steps to resolve it:

1. Register an App in Azure Active Directory

To effectively use Managed Identity, your first step is to create an application registration within your Azure Active Directory.

Go to the Azure Portal and navigate to Azure Active Directory.

Click on App Registrations and then New Registration.

Provide a name and set the appropriate redirect URI. You can leave it blank for now if you're working with a function app.

After registration, note the Application (client) ID and the Directory (tenant) ID for future reference.

2. Expose the API of the Registered App

Once the app is registered, you need to expose its API to ensure that your Function App can request tokens correctly.

In the App registration page, navigate to Expose an API.

Click on Add a scope, and define a scope (e.g., access_as_user).

Once done, you can give necessary permissions to the application to access the API.

3. Assign Managed Identity to Your Function App

Ensure that the Function App has the system-assigned managed identity properly assigned:

In the Function App settings, look for Identity and toggle the System assigned status to On.

This provides the app with an identity in Azure AD so it can request tokens.

4. Handle Local Testing with Azure CLI

If you are testing locally and facing issues with requesting the token, check if your Azure CLI is authorized:

Run az login to ensure that you’re logged in to the correct subscription associated with your Azure account.

If Azure CLI is not consented, your application may not fetch tokens locally. This, however, won’t be an issue once deployed on Azure.

5. Deploy Everything and Test

Now that you've configured everything, it’s time to deploy your Function App:

Deploy the Function App to Azure.

Once deployed, test fetching the access token again using the same code snippet for DefaultAzureCredential.

Here’s a sample code to remind you how you would be requesting the token:

[[See Video to Reveal this Text or Code Snippet]]

6. Successful Access Token Retrieval

After following these steps, you should successfully receive the access token without encountering the AADSTS500011 error. Your Azure Function will now be able to interact with the resources it w

コメント