我有一个配置了 oidc 身份验证的 blazor wasm 应用程序,该应用程序运行正常。该网站有2个域,
- 运行 Identity Server 4 的 identity.example.com
- 为 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>