asp.net-core - 连接到本地 Identity Server 4 的新 Blazor 项目
问题描述
当我创建新的 Blazor 项目时,可以选择通过Individual User Accounts
,使用身份验证Connect to an existing user store in the cloud
。我安装并配置了本地 Identity Server 4。我可以使用它进行身份验证吗?在这种情况下,我应该为 、 和 选项指定Sign-up or Sign-ii policy
哪些Reset Password Policy
参数Edit Profile Policy
?
解决方案
不,该选项用于连接 Azure AD B2C 应用程序,这是 Microsoft 的云身份服务之一。
如果要连接本地 Identity Server 4,可以先安装包IdentityServer4
,然后在 blazor 应用中添加认证,使用 OIDC 中间件连接 IDS4:
services.AddAuthentication(options =>
{
options.DefaultScheme = "Cookies";
options.DefaultChallengeScheme = "oidc";
})
.AddCookie("Cookies")
.AddOpenIdConnect("oidc", options =>
{
options.Authority = "http://localhost:5000";
options.RequireHttpsMetadata = false;
options.ClientId = "mvcBlazor";
options.SaveTokens = true;
options.Scope.Add("openid");
options.Scope.Add("profile");
});
services.AddMvcCore(options =>
{
var policy = new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
.Build();
options.Filters.Add(new AuthorizeFilter(policy));
});
和
app.UseAuthentication();
您可以参考以下文章的代码示例和解释:
推荐阅读
- java - 如何将非标题元素添加到 asciidoctor 的目录
- asp.net - .NET 程序集的错误版本被复制到 Web 窗体 bin 目录
- reactjs - 将绝对路径添加到由“Create React App”创建的应用程序
- haskell - Haskell:如何获取具有多个参数的数据类型的类型(如`Path ab = ..`
- python - pyspark 将某种数据类型的所有列转换为另一个
- typescript - TypeScript 导入的常量未定义
- python - 在 Python 中组合两个字节
- c - 管道:错误的文件描述符
- angular - 如何在角度6中选择和取消选择行
- python - Numpy 聚合平均值