0

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

  1. 运行 Identity Server 4 的 identity.example.com
  2. 为 blazor wasm 站点提供服务器的 example.com。

一切正常,当我添加

@attribute [Authorize]

用户(如果未经过身份验证)被重定向到https://identity.example.com/Account/Login?ReturnUrl..到剃刀组件。我想知道是否有办法在 mysite.com 域上实现自定义登录页面/组件,例如 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>
4

1 回答 1

1

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

如果您管理 IS4 服务器,则更容易自定义 IS4 的登录页面。

于 2020-07-10T13:05:00.183 回答