Skip to content

Commit f86c2cb

Browse files
authored
Fix typos and improve clarity in documentation
Edit review per CI 3171
1 parent 7055f08 commit f86c2cb

1 file changed

Lines changed: 46 additions & 42 deletions

File tree

support/entra/entra-id/app-integration/troubleshoot-error-idx10501-aspnet-b2c.md

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,73 @@
11
---
22
title: Troubleshoot IDX10501 Error in ASP.NET Core app with Azure B2C Custom Policy
3-
description: Provides guidance for troubleshooting IDX10501 Error in ASP.NET Core with Azure B2C.
3+
description: Provides guidance for troubleshooting the IDX10501 error in ASP.NET Core with Azure B2C.
44
ms.date: 01/06/2025
55
ms.author: markbukovich
66
ms.service: entra-id
77
ms.custom: sap:Microsoft Entra App Integration and Development
88
---
99

10-
# IDX10501 Error in ASP.NET Core app with Azure B2C Custom Policy
10+
# IDX10501 error in ASP.NET Core app with Azure B2C custom policy
1111

12-
This guide helps you understand the cause of the IDX10501 error and provide a step-by-step solution to resolve it.
12+
This guide discusses the cause of the "IDX10501" error, and provides a step-by-step solution to resolve it.
1313

1414
## Symptoms
15-
When you [implement a custom policy](/azure/active-directory-b2c/enable-authentication-web-application-options#pass-the-azure-ad-b2c-policy-id) in an ASP.NET Core application that integrates with Azure Active Directory B2C (Azure AD B2C), you may encounter the following IDX10501 error:
15+
When you [implement a custom policy](/azure/active-directory-b2c/enable-authentication-web-application-options#pass-the-azure-ad-b2c-policy-id) in an ASP.NET Core application that integrates with Azure Active Directory B2C (Azure AD B2C), you might encounter the following IDX10501 error:
1616

1717
> IDX10501: Signature validation failed. Unable to match key: kid: '[PII of type 'System.String' is hidden. For more details, see https://aka.ms/IdentityModel/PII.]'. Number of keys in TokenValidationParameters: '0'. Number of keys in Configuration: '1'. Exceptions caught: '[PII of type 'System.Text.StringBuilder' is hidden. For more details, see https://aka.ms/IdentityModel/PII.]'. token: '[PII of type 'System.IdentityModel.Tokens.Jwt.JwtSecurityToken' is hidden. For more details, see https://aka.ms/IdentityModel/PII.]'.
1818
19-
## Understanding the Error
19+
## Understanding the error
2020

21-
First, let’s understand why this error is being thrown when the custom policy redirects back to your app. In ASP.NET Core, whenever a user is authenticated and authorized, and there's a redirect back to the Web app that contains an ID Token. ASP.NET Core middleware will try to validate this ID Token to make sure that the redirect is genuine. To validate the ID Token, the Middleware needs the public key of the signing certificate which was used to sign the ID Token. The Middleware gets this public key by querying Azure Active Directory B2C. Specifically, there's a "metadata" endpoint in Azure Active Directory B2C used by the Middleware which provides authentication information including any public keys for signing certificates.
21+
Why is this error generated when the custom policy redirects to your app? In ASP.NET Core, whenever a user is authenticated and authorized, and a redirect page exists to the web app that contains an ID token, ASP.NET Core middleware tries to validate this ID token to make sure that the redirect is genuine. To validate the ID token, the middleware requires the public key of the signing certificate that was used to sign the ID token. The middleware gets this public key by querying Azure Active Directory B2C. Specifically, the middleware uses a "metadata" endpoint in Azure Active Directory B2C that provides authentication information, including any public keys for signing certificates.
2222

23-
When you created your custom policy, you were required to create or upload a signing certificate. This signing certificate is different from that used for built-in user flows in Azure Active Directory B2C. This means that the public keys accessible from the "metadata" endpoint for your Azure Active Directory B2C won't contain the public key for your custom policy. The custom policy actually has its own metadata endpoint.
23+
When you create a custom policy, you're required to create or upload a signing certificate. This signing certificate is different from that used for built-in user flows in Azure Active Directory B2C. This means that the public keys that are accessible from the "metadata" endpoint for your Azure Active Directory B2C won't contain the public key for your custom policy. The custom policy actually has its own metadata endpoint.
2424

25-
The endpoint which the Middleware uses is configured by Microsoft.Identity.Web and set at app startup. Since the metadata URL is already set, invoking a custom policy during runtime will result in a scenario where the Middleware is looking at the wrong metadata URL while validating the returning token.
25+
The endpoint that the middleware uses is configured by Microsoft.Identity.Web and is set at app startup. Because the metadata URL is already set, invoking a custom policy during runtime creates a scenario in which the middleware is looking at the wrong metadata URL while it validates the returning token.
2626

2727
## Solution
2828

29-
To resolve this issue, you must configure the correct metadata endpoint for the additional Custom Policy. To do this, create a second authentication scheme to handle the custom policy. With this additional authentication scheme, we can set the correct metadata endpoint at startup. Below is a brief overview of the steps involved:
29+
To resolve this issue, you must configure the correct metadata endpoint for the additional custom policy. To do this, create a second authentication scheme to handle the custom policy. By having this additional authentication scheme, you can set the correct metadata endpoint at startup. This process uses the following steps:
3030

31-
1. Add an additional redirect URI to your App Registration.
31+
1. Add an additional redirect URI to your app registration.
3232
2. Configure an additional B2C authentication scheme in your app.
3333
3. Add an action to the desired controller.
34-
4. Implement the created action in the Layout.
34+
4. Implement the created action in the layout.
3535

3636
Code sample: [ASP.NET Core Web App with Custom B2C Policy](https://github.com/mbukovich/ExtraB2CPolicyMVC).
3737

3838
### Prerequisites
3939

40-
Before continuing, Ensure you have:
40+
Before you continue this process, make sure that you have:
4141

4242
- An Azure B2C directory
4343
- An app registration for B2C authentication
44-
- [Standard user flows set up](/azure/active-directory-b2c/tutorial-create-user-flows?pivots=b2c-user-flow)
45-
- [A custom B2C policy added to your directory](/azure/active-directory-b2c/tutorial-create-user-flows?pivots=b2c-custom-policy)
46-
- An existing ASP.NET Core web app configured with Microsoft.Identity.Web for B2C authentication. For more information, see [Enable authentication in your own web app by using Azure AD B2C](/azure/active-directory-b2c/enable-authentication-web-application?tabs=visual-studio)
44+
- [Standard user flows that are set up](/azure/active-directory-b2c/tutorial-create-user-flows?pivots=b2c-user-flow)
45+
- [A custom B2C policy that's added to your directory](/azure/active-directory-b2c/tutorial-create-user-flows?pivots=b2c-custom-policy)
46+
- An existing ASP.NET Core web app that's configured by having Microsoft.Identity.Web for B2C authentication
4747

48-
### Step 1: Add an Additional Redirect URI
48+
For more information, see [Enable authentication in your own web app by using Azure AD B2C](/azure/active-directory-b2c/enable-authentication-web-application?tabs=visual-studio)
4949

50-
In the App Registration, you need to add another redirect URI for the custom policy. The reason you can't use the existing redirect URI in this case is that it could cause confusion for the Web App. We'll set up two different authentication schemes, but when the B2C policy redirects back to the Web App, the Middleware won't know which authentication scheme to use. Thus, we need a separate redirect URI to clearly distinguish redirects from the existing and new authentication schemes.
50+
### Step 1: Add an additional redirect URI
5151

52-
1. Navigate to your app registration in the [Azure Portal](https://portal.azure.com).
52+
In the app registration, you have to add another redirect URI for the custom policy. In this case, you can't use the existing redirect URI because it could cause confusion for the web app. You'll be setting up two different authentication schemes. However, when the B2C policy redirects to the web app, the middleware won't know which authentication scheme to use. Therefore, you need a separate redirect URI to clearly distinguish between redirects from the existing and new authentication schemes.
53+
54+
Follow these steps:
55+
56+
1. Navigate to your app registration in the [Azure portal](https://portal.azure.com).
5357
2. In the **Manage** section, select **Authentication**.
5458
3. In the **Redirect URIs** section, select **Add URI**.
55-
4. Add a new redirect URI. In this case, the new redirect URI is `https://localhost:44321/signin-oidc-editemail`.
59+
4. Add a redirect URI. In this case, the new redirect URI is `https://localhost:44321/signin-oidc-editemail`.
5660

5761
:::image type="content" source="media/troubleshoot-error-idx10501-aspnet-b2c/add-redirect-uri.png" alt-text="Screenshot of adding Redirect URIs." lightbox="media/troubleshoot-error-idx10501-aspnet-b2c/add-redirect-uri.png":::
5862

5963
> [!NOTE]
60-
> Each custom policy requires its own redirect URI. For example, if you're adding two custom policies, you will need to create two authentication scheme and two redirect URIs.
64+
> Each custom policy requires its own redirect URI. For example, if you're adding two custom policies, you have to create two authentication schemes and two redirect URIs.
6165
6266
### Step 2: Configure an Additional Authentication Scheme
6367

64-
This process involves adding an action to your controller that will issue a challenge to the user. Before creating this action, we need to configure the app with an additional authentication scheme. This requires updating both the appsettings.json file and the Startup.cs file.
68+
This process involves adding an action to your controller that issues a challenge to the user. Before you create this action, configure the app with an additional authentication scheme. This requires updating both the Appsettings.json file and the Startup.cs file.
6569

66-
#### Update `appsettings.json`
70+
#### Update `Appsettings.json`
6771

6872
Add the following configuration for your custom policy:
6973

@@ -78,7 +82,7 @@ Add the following configuration for your custom policy:
7882
},
7983
```
8084

81-
Example of the `appsettings.json`
85+
Example of `Appsettings.json`
8286

8387
```json
8488
{
@@ -110,15 +114,15 @@ Example of the `appsettings.json`
110114
"AllowedHosts": "*"
111115
}
112116
```
113-
**Important Considerations**
117+
**Important considerations**
114118

115-
- You can choose any name for the second B2C configuration. This configuration will be used for a single custom policy. If you need to add more custom policies, you'll have to include additional B2C configurations in the AppSettings.json file. For this reason, it's recommended to give the JSON object a name that reflects the associated custom policy.
116-
- The CallbackPath is the portion of the Redirect URI that follows the domain. For example, if your redirect URI is `https://localhost:44321/signin-oidc-editemail`, then the CallbackPath will be `/signin-oidc-editemail`.
117-
- You need to include the standard built-in sign-up/sign-in user flow in the authentication scheme to ensure that users are prompted to sign in if they try to access your custom policy without signed-in.
119+
- You can choose any name for the second B2C configuration. This configuration will be used for a single custom policy. If you have to add more custom policies, you must include additional B2C configurations in the AppSettings.json file. For this reason, we recommend that you give the JSON object a name that reflects the associated custom policy.
120+
- The CallbackPath value is the portion of the redirect URI that follows the domain. For example, if your redirect URI is `https://localhost:44321/signin-oidc-editemail`, then CallbackPath will be `/signin-oidc-editemail`.
121+
- You must include the standard built-in sign-up/sign-in user flow in the authentication scheme to make sure that users are prompted to sign in if they try to access your custom policy without being signed-in.
118122

119123
#### Update `Startup.cs`
120124

121-
Configure an additional authentication scheme in the startup.cs file. In the `ConfigureServices` function, add the following code:
125+
Configure an additional authentication scheme in the Startup.cs file. In the `ConfigureServices` function, add the following code:
122126

123127
```csharp
124128
// Create another authentication scheme to handle extra custom policy
@@ -131,30 +135,30 @@ services.Configure<OpenIdConnectOptions>("<Arbitrary-name-for-Auth-Scheme>", opt
131135
});
132136
```
133137

134-
- You will need to set custom names for both your authentication scheme and the associated cookie scheme. Microsoft.Identity.Web will create these schemes using the names you specify.
138+
- You have to set custom names for both your authentication scheme and the associated cookie scheme. Microsoft.Identity.Web will create these schemes by using the names that you specify.
135139

136-
- Additionally, replace `<name-of-json-configuration>` with the name of the JSON configuration from the previous step. In the example of this article, it should be `AzureADB2CEditEmail`.
140+
- Replace `<name-of-json-configuration>` with the name of the JSON configuration from the previous step. Per the example in this article, this should be `AzureADB2CEditEmail`.
137141

138-
- Replace `<Your-Custom-Metadata-URL>` with the OpenID Connect discovery endpoint URL found under your custom policy in Azure AD B2C.
142+
- Replace `<Your-Custom-Metadata-URL>` with the OpenID Connect discovery endpoint URL that's found under your custom policy in Azure AD B2C.
139143

140-
#### How to get the Metadata address for Custom Policy
144+
#### How to get the metadata address for custom policy
141145

142-
It's important to get the Metadata address. This will be used by the middleware to get the information necessary to validate ID Tokens returned by the Custom Policy.
146+
It's important to get the metadata address because this will be used by the middleware to get the required information to validate ID tokens that are returned by the custom policy.
143147

144148
To find the metadata address, follow these steps:
145149

146150
1. Log in to the Azure B2C portal.
147-
2. In **Policies** section, select **Identity Experience Framework**.
151+
1. In **Policies** section, select **Identity Experience Framework**.
148152

149153
:::image type="content" source="media/troubleshoot-error-idx10501-aspnet-b2c/find-identity-exp-fr.png" alt-text="Screenshot of the Identity Experience Framework button.":::
150-
1. Select Custom policies, and then select the custom policy that you are using. In this case, It's **B2C_1A_DEMO_CHANGESIGNINNAME**.
154+
1. Select Custom policies, and then select the custom policy that you're using. In this case, it's **B2C_1A_DEMO_CHANGESIGNINNAME**.
151155

152156
:::image type="content" source="media/troubleshoot-error-idx10501-aspnet-b2c/custom-policy.png" alt-text="Screenshot of checking custom-policy.":::
153-
1. The metadata address is the URL listed under **OpenId Connect Discovery Endpoint**. Copy this URL and paste it as the value for the `options.MetadataAddress` variable.
157+
1. The metadata address is the URL that's listed under **OpenId Connect Discovery Endpoint**. Copy this URL, and paste it as the value for the `options.MetadataAddress` variable.
154158

155-
### Step 3: Add Action to Controller
159+
### Step 3: Add an action to the controller
156160

157-
In your controller, implement an action to trigger the Custom B2C Policy challenge for the user. In code sample, the action is added to the Home Controller for the sake of simplicity. Add the following code to your controller and adjust the values and action name to meet your scenario. This code snippet can be found on line 40 of the `HomeController.cs` file in the `Controllers` folder in the Code sample:
161+
In your controller, implement an action to trigger the Custom B2C Policy challenge for the user. In code sample, the action is added to the Home Controller for simplicity. Add the following code to your controller, and adjust the values and action name to meet your scenario. This code snippet can be found on line 40 of the `HomeController.cs` file in the `Controllers` folder in the code sample:
158162

159163
```csharp
160164
[Authorize]
@@ -167,11 +171,11 @@ public IActionResult EditEmail()
167171
}
168172
```
169173

170-
Ensure `<Your-Custom-Policy>` matches your specific policy name and `<CustomAuthScheme>` is consistent with what you configured earlier.
174+
Make sure that `<Your-Custom-Policy>` matches your specific policy name and `<CustomAuthScheme>` is consistent with what you configured earlier.
171175

172-
### Step 4: Implement Action in Layout
176+
### Step 4: Implement action in layout
173177

174-
Implement the action in the layout, so that the user can actually invoke the custom policy. In code sample, the following snippet adds a button alongside existing B2C buttons based on the [tutorial](/azure/active-directory-b2c/enable-authentication-web-application). The snippet is added to line 13 of the `_LayoutPartial.cshtml` file in the `Views/Shared` folder. Note that the `asp-controller` property is set to `Home` to reference the Home Controller, and the `asp-action property` is set to `EditEmail` to reference the action created in the Home Controller. For more information, see [Add the UI elements](/azure/active-directory-b2c/enable-authentication-web-application?tabs=visual-studio#step-4-add-the-ui-elements).
178+
Implement the action in the layout so that the user can actually invoke the custom policy. In the code sample, the following snippet adds a button alongside the existing B2C buttons, based on the [tutorial](/azure/active-directory-b2c/enable-authentication-web-application). The snippet is added to line 13 of the `_LayoutPartial.cshtml` file in the `Views/Shared` folder. Note that the `asp-controller` property is set to `Home` to reference the Home Controller, and the `asp-action property` is set to `EditEmail` to reference the action that's created in the Home Controller. For more information, see [Add the UI elements](/azure/active-directory-b2c/enable-authentication-web-application?tabs=visual-studio#step-4-add-the-ui-elements).
175179

176180
```html
177181
<li class="navbar-btn">
@@ -181,7 +185,7 @@ Implement the action in the layout, so that the user can actually invoke the cus
181185
</li>
182186
```
183187

184-
If you have an existing app that doesn’t use the partial layout and just want a quick link to test the custom policy, you can use the following tag to create a basic link. Be sure to replace the indicated values and reference the correct controller if you didn’t add your action to the Home Controller:
188+
If you have an existing app that doesn’t use the partial layout, and you want only a quick link to test the custom policy, you can use the following tag to create a basic link. Make sure that you replace the indicated values and reference the correct controller if you didn’t add your action to the Home Controller.
185189

186190
```html
187191
<a asp-area="" asp-controller="Home" asp-action="replace-with-your-controller-action">Replace with text that describes the action</a>

0 commit comments

Comments
 (0)