【发布时间】:2021-06-02 21:24:45
【问题描述】:
我正在尝试获取多个正在运行的托管 Blazor 应用的示例。
我的出发点是 Microsoft 提供的文档: https://docs.microsoft.com/en-us/aspnet/core/blazor/host-and-deploy/webassembly?view=aspnetcore-6.0#hosted-deployment-with-multiple-blazor-webassembly-apps
文档中描述的基本设置工作正常。
现在我想添加基于 blazor webassembly 模板身份验证的个人帐户身份验证。
我让它的一部分运行,但其他部分不工作,我什至不确定关于它的一般架构的正确方法是什么。
假设多个应用使用一个用户群。 我是按如下方式使用我的主机作为身份服务器,还是为所有应用使用第 3 方主机?
app.MapWhen(ctx => ctx.Request.Host.Port == 5001 ||
ctx.Request.Host.Equals("firstapp.com"), first =>
{
first.Use((ctx, nxt) =>
{
ctx.Request.Path = "/FirstApp" + ctx.Request.Path;
return nxt();
});
first.UseBlazorFrameworkFiles("/FirstApp");
first.UseStaticFiles();
first.UseStaticFiles("/FirstApp");
first.UseRouting();
first.UseIdentityServer();
first.UseAuthentication();
first.UseAuthorization();
first.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
endpoints.MapControllers();
endpoints.MapFallbackToFile("/FirstApp/{*path:nonfile}",
"FirstApp/index.html");
});
});
app.MapWhen(ctx => ctx.Request.Host.Port == 5002 ||
ctx.Request.Host.Equals("secondapp.com"), second =>
{
...
由于调用 openid 配置 (https://localhost:5001/.well-known/openid-configuration) 失败,因此无法按预期工作, 以及对身份服务器页面的任何调用,例如https://localhost:5001/Identity/Account/Register
这似乎是一个路由/映射问题,虽然我不确定我必须在哪里进行更改。有什么想法或提示吗?
我发现的另一个可能的选项是使用第三个端口通过在 mapWhen 语句之后添加以下内容来将其与客户端分开运行
app.UseStaticFiles();
app.UseRouting();
app.UseIdentityServer();
app.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
endpoints.MapControllers();
});
这将要求客户端不要使用自己的主机进行身份验证,而是使用第 3 方,这会使事情变得更加复杂。但如果这是唯一或唯一干净的解决方案,我将不得不处理它。
【问题讨论】:
标签: authentication blazor blazor-webassembly