注册/登录无法在 ASP 中运行。 NET Core 应用程序:Azure B2C

问题描述 投票:0回答:1

我们使用 Google 作为身份提供商来配置用户流。按照 GitHub 上的 Azure-Sample 存储库使用 .NET 6 构建 ASP.NET Core Web 应用程序。

appsettings.json:

"AzureAdB2C": {
    "Instance": "https://b2ctenant.b2clogin.com",
    "ClientId": "3ae27e38-90a3-43c7-9bac-8d3bf33227f9",
    "Domain": "b2ctenant.b2clogin.com",
    "SignedOutCallbackPath": "/signout/B2C_1_susi",
    "SignUpSignInPolicyId": "b2c_1_susi",
    "ResetPasswordPolicyId": "b2c_1_reset",
    "EditProfilePolicyId": "b2c_1_edit_profile" // Optional profile editing policy
    //"CallbackPath": "/signin/B2C_1_sign_up_in"  // defaults to /signin-oidc

https://localhost:44316

enter image description here

当用户选择

Sign Up/In
选项时出现异常

IOException:IDX20807:无法从以下位置检索文档:“[‘System.String’类型的 PII 已隐藏。有关更多详细信息,请参阅 https://aka.ms/IdentityModel/PII.]'。 HttpResponseMessage: '[PII 的 类型“System.Net.Http.HttpResponseMessage”被隐藏。了解更多 详细信息,请参阅 https://aka.ms/IdentityModel/PII。]', HttpResponseMessage.Content:“[‘System.String’类型的 PII 已隐藏。 有关更多详细信息,请参阅 https://aka.ms/IdentityModel/PII。]'。
Microsoft.IdentityModel.Protocols.HttpDocumentRetriever.GetDocumentAsync(字符串 地址,CancellationToken 取消)
Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectConfigurationRetriever.GetAsync(字符串 地址、IDocumentRetriever 检索器、CancellationToken 取消)

Microsoft.IdentityModel.Protocols.ConfigurationManager.GetConfigurationAsync(CancellationToken 取消) nvalidOperationException:IDX20803:无法从以下位置获取配置:'[“System.String”类型的 PII 已隐藏。了解更多 详细信息,请参阅 https://aka.ms/IdentityModel/PII。]'。 Microsoft.IdentityModel.Protocols.ConfigurationManager.GetConfigurationAsync(CancellationToken 取消) Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectHandler.HandleChallengeAsyncInternal(AuthenticationProperties 特性) Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectHandler.HandleChallengeAsync(AuthenticationProperties 特性) Microsoft.AspNetCore.Authentication.AuthenticationHandler.ChallengeAsync(AuthenticationProperties 特性) Microsoft.AspNetCore.Authentication.AuthenticationService.ChallengeAsync(HttpContext 上下文、字符串方案、AuthenticationProperties 属性) Microsoft.AspNetCore.Mvc.ChallengeResult.ExecuteResultAsync(ActionContext 语境) Microsoft.AspNetCore.Mvc.Infrastruct.ResourceInvoker.g__Awaited|30_0(ResourceInvoker 调用程序,任务lastTask,状态下一个, 作用域范围,对象状态,bool isCompleted) Microsoft.AspNetCore.Mvc.Infrastruct.ResourceInvoker.Rethrow(ResultExecutedContextSealed 语境) Microsoft.AspNetCore.Mvc.Infrastruct.ResourceInvoker.ResultNext(ref 状态下一个,ref 范围范围,ref 对象状态,ref bool 已完成) Microsoft.AspNetCore.Mvc.Infrastruct.ResourceInvoker.g__Awaited|28_0(ResourceInvoker 调用者、任务上一个任务、下一个状态、作用域范围、对象状态、布尔值 完成了) Microsoft.AspNetCore.Mvc.Infrastruct.ResourceInvoker.g__Awaited|25_0(ResourceInvoker 调用者、任务上一个任务、下一个状态、作用域范围、对象状态、布尔值 完成了) Microsoft.AspNetCore.Mvc.Infrastruct.ResourceInvoker.Rethrow(ResourceExecutedContextSealed 语境) Microsoft.AspNetCore.Mvc.Infrastruct.ResourceInvoker.Next(参考状态 接下来,ref 范围范围,ref 对象状态,ref bool isCompleted) Microsoft.AspNetCore.Mvc.Infrastruct.ResourceInvoker.g__Awaited|20_0(ResourceInvoker 调用者、任务上一个任务、下一个状态、作用域范围、对象状态、布尔值 完成了) Microsoft.AspNetCore.Mvc.Infrastruct.ResourceInvoker.g__Logged|17_1(ResourceInvoker 调用者) Microsoft.AspNetCore.Mvc.Infrastruct.ResourceInvoker.g__Logged|17_1(ResourceInvoker 调用者) Microsoft.AspNetCore.Routing.EndpointMiddleware.g__AwaitRequestTask|6_0(端点 端点、任务 requestTask、ILogger 记录器) Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext 语境) Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext 语境) Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext 上下文)

asp.net-core google-oauth azure-ad-b2c azureportal azure-identity
1个回答
2
投票

我尝试在我的环境中重现相同的结果并得到以下结果:

我注册了一个应用程序并授予了API权限,如下所示:

enter image description here

我克隆了相同的 GitHub 示例并更新了

appsettings.json
文件,如下所示:

enter image description here

运行上面的示例并得到以下屏幕:

enter image description here

当我点击

Sign Up/In
按钮时,我得到了与下面相同的错误:

enter image description here

注意,您在 appsettings.json 文件中为 Domain 参数提供了

错误值
。您需要更改域参数的,可以在此处找到:

enter image description here

为了解决错误,我更改了我的中的域参数值
appsettings.json

 文件如下:

enter image description here

当我现在通过运行示例单击

Sign Up/In

 按钮时,我成功获得了 Google 的登录屏幕,如下所示:

enter image description here

参考: 使用 Azure Active Directory B2C 配置身份验证 |微软

© www.soinside.com 2019 - 2024. All rights reserved.