【发布时间】:2021-03-08 02:12:44
【问题描述】:
很抱歉提出新问题。
我真的需要了解这个新模板的解决方法是什么。
重现错误:
Visual Studio,全新的 Blazor 应用,名为“Demo3”
.NET 5.0,Blazor WebAssembly 应用程序,模板“CLI v5.0.100”
ASP.NET Core 托管,https
身份验证、单域、读取目录数据
运行创建
我已经在以前的模板上这样做了数百次。但是这个“新”模板会立即产生一个我无法弄清楚的错误。
详情:
正常登录
点击“获取数据”(天气预报)
我收到此错误消息。
关键字:401 和未经授权。
我猜 Unauthorized 是重要的信息。
info: System.Net.Http.HttpClient.Demo3.ServerAPI.ClientHandler[100]
Sending HTTP request GET https://localhost:44345/WeatherForecast
WeatherForecast:1 Failed to load resource: the server responded with a status of 401 ()
blazor.webassembly.js:1 info: System.Net.Http.HttpClient.Demo3.ServerAPI.ClientHandler[101]
Received HTTP response after 1272.7899ms - Unauthorized
blazor.webassembly.js:1 info: System.Net.Http.HttpClient.Demo3.ServerAPI.LogicalHandler[101]
End processing HTTP request after 1340.08ms - Unauthorized
blazor.webassembly.js:1 crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: Response status code does not indicate success: 401 (Unauthorized).
System.Net.Http.HttpRequestException: Response status code does not indicate success: 401 (Unauthorized).
at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode () <0x337bf70 + 0x00052> in <filename unknown>:0
at System.Net.Http.Json.HttpClientJsonExtensions.GetFromJsonAsyncCore[T] (System.Threading.Tasks.Task`1[TResult] taskResponse, System.Text.Json.JsonSerializerOptions options, System.Threading.CancellationToken cancellationToken) <0x32c6740 + 0x000f4> in <filename unknown>:0
at Demo3.Client.Pages.FetchData.OnInitializedAsync () [0x0003c] in D:\repos\nameofrepo\src\Demo3\Demo3\Client\Pages\FetchData.razor:48
at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync () <0x2c764b0 + 0x0013a> in <filename unknown>:0
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask (System.Threading.Tasks.Task taskToHandle) <0x2f401a8 + 0x000b6> in <filename unknown>:0
如错误所示,存在授权错误。
我的问题是:
有人找到此错误的“官方 MS 链接”吗?
或者,谁能解释一下出了什么问题。
跟进
只是为了澄清,我没有更改或添加任何代码。模板完成后直接进行测试运行。当然,我尝试调试错误并查看 AzureAD 中的设置,但没有成功。
第二次跟进
调查了一个提示,评论中的 AADSTS7000218 详细信息。
所以我建立了一个项目。以下是详细信息:
我改成了红隼。
我将 Azure 应用设置更改为 SPA,重定向地址相同。
为自己授予两个应用的所有者权限。
将服务器添加到客户端应用程序的 api 权限。 "api://BlazorApp1_Server/user_impersonation"
测试:同样的错误。 细节,我仍然注意到观众的细节。
Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: Response status code does not indicate success: 401 (Unauthorized).
System.Net.Http.HttpRequestException: Response status code does not indicate success: 401 (Unauthorized).
在响应头中:
www-authenticate: Bearer error="invalid_token", error_description="The audience 'api://blazorapp1_server' is invalid"
但没有关于 AADSTS7000218 或缺少客户端密码的信息。
仍然不放弃...我会回来...
【问题讨论】:
-
您是否通知了 AzAD 您的应用程序?
-
是的,模板注册了两者。 Demo3(Blazor Web 程序集)和 Demo3_Server(Rest Api)。尝试了各种更改,没有运气。还授予服务器应用程序的 wasm 应用程序权限...在以前的应用程序中,我遇到了 v1 和 v2 身份验证点的问题,这是我现在最好的问题。
-
为了它的价值,我可以复制这个。不是我的区域,但响应包含:AADSTS7000218:请求正文必须包含以下参数:“client_assertion”或“client_secret”。这似乎是一个熟悉的错误。
-
我新建一个项目,找不到AADSTS7000218错误。