【发布时间】:2020-04-12 09:40:47
【问题描述】:
我有一个使用 Identity Server 4、OpenIDConnect 的隐式代码流和带有 MongoDbStore 的 AspNetCore Identity 的现有系统。用户当前使用用户名和密码注册/登录。我正在尝试允许用户使用将针对单独的 Mongo 集合进行验证的 ID 和 PINS 登录。我需要帮助确定此功能的最佳方法。这本质上是使用配置文件服务的多租户吗?我要配置新客户端吗?我可以有条件地覆盖验证吗?
这是我Startup.cs中的ConfigureServices方法:
public void ConfigureServices(IServiceCollection services)
{
services.AddIdentity<ApplicationUser, ApplicationRole>(config => { config.SignIn.RequireConfirmedEmail = true; })
.AddMongoDbStores<ApplicationUser, ApplicationRole, Guid>
(
Configuration.GetSection("MongoDb:ConnectionString").Value,
Configuration.GetSection("MongoDb:Database").Value
)
.AddDefaultTokenProviders();
services.AddServices();
services.AddSettings(Configuration);
services.Configure<IdentityConfig>(Configuration.GetSection("IdentityConfig"));
services.AddScoped<IdentityConfig>(sp => sp.GetService<IOptionsSnapshot<IdentityConfig>>().Value);
services.AddMvc();
services.AddSession();
IdentityConfig identityConfig = Configuration.GetSection("IdentityConfig").Get<IdentityConfig>();
services.AddIdentityServer(options =>
{
if (!string.IsNullOrEmpty(identityConfig.PublicOrigin))
{
options.PublicOrigin = identityConfig.PublicOrigin;
}
if (!string.IsNullOrEmpty(identityConfig.IssuerUri))
{
options.IssuerUri = identityConfig.IssuerUri;
}
})
.AddDeveloperSigningCredential()
.AddInMemoryPersistedGrants()
.AddInMemoryIdentityResources(GetIdentityResource(identityConfig.IdentityResources))
.AddInMemoryApiResources(GetAPIResources(identityConfig.ApiResources))
.AddInMemoryClients(GetClients(identityConfig.Clients))
.AddAspNetIdentity<ApplicationUser>();
}
【问题讨论】:
标签: asp.net-identity identityserver4 openid-connect