我正在尝试获取运行多个托管 Blazor 应用的示例。
文档中描述的基本设置工作正常。
现在我想添加基于个人帐户的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 方,这会使事情变得更加复杂。但如果这是唯一或唯一干净的解决方案,我将不得不处理它。