是否可以使用自定义登录配置 Blazor WebAssembly oidc component/page

Is it possible to configure Blazor WebAssembly oidc with a custom login component/page

我有一个配置了 oidc 身份验证的 blazor wasm 应用程序,它运行正常。该站点有 2 个域,

  1. identity.example.com 运行 身份服务器 4
  2. example.com blazor wasm 站点的服务器。

一切正常,当我添加

@attribute [Authorize]

将用户(如果未通过身份验证)重定向到剃刀组件 https://identity.example.com/Account/Login?ReturnUrl..。 我想知道是否有一种方法可以在 mysite.com 域上实现自定义登录 page/component,例如 mysite.com/Login 这样用户将被重定向到该域并且该表单将提交到到身份域 AccountController 并且仍然让框架处理 jwt 令牌和...?

我首先有几个其他原因,我希望网站上的所有内容都经过身份验证。现在我已经将@attribute [Authorize] 添加到每个页面,但这仍然会导致网站加载,并且只有在用户可以看到该网站后,他们才会被重定向到 identity.example.com 上的登录页面。它看起来有点奇怪,接下来 identity.example.com 上的登录页面看起来与站点的其余部分完全不同 我想尝试使登录页面的“主题”看起来像站点的其余部分

我目前是这样配置Oidc的

nuget package Microsoft.AspNetCore.Components.WebAssembly.Authentication

在appsetting.json

{
  "oidc": {
    "Authority": "https://identity.example.com/",
    "ClientId": "abcd",
    "DefaultScopes": [
      "openid",
      "profile",
      "email"
    ],
    "PostLogoutRedirectUri": "https://example.com",
    "ResponseType": "code"
  }
} 

然后在我的 Program.cs 我有

builder.Services.AddOidcAuthentication(options => {
  builder.Configuration.Bind("oidc", options.ProviderOptions);                  
});

在我的 wwwroot/index.html

<script src="_content/Microsoft.AspNetCore.Components.WebAssembly.Authentication/AuthenticationService.js"></script>

出于安全考虑,这不是一个好主意。
但是,如果您在表单数据中提供良好的防伪标记并请求 header,则可以在您想要的地方实现一个登录页面。这意味着您需要来自 IS4 服务器的登录页面。解析页面以找到包含反 XSRF 伪造令牌的隐藏表单字段。将 cookie 和 header 发送回 IS4 服务器。
祝你好运。

如果您管理 IS4 服务器,则可以更轻松地自定义 IS4 的登录页面。