将ASP.NET Core Identity设置为服务
问题描述:
我在MVC应用程序中很年轻将ASP.NET Core Identity设置为服务
我想创建一个为外部MVC应用程序提供标识的web服务。暴露ASP.NET核心身份作为服务的
优点:
实际的应用程序代码更简单,从它的身份脱钩涉及
支持建立的认证标准和模式简化了安全担忧和建立信任
身份证服务可以住在一个单独的过程
在多个应用
重用用户身份这可能吗?任何想法,我可以做到这一点?
答
这是可能的。
这就是我们的做法。
我们使用IdentityServer4为客户端生成JWT令牌。我们创建了一个简单的MVC项目,其中包含一个简单的启动文件,可以给你一个想法。
public void ConfigureServices(IServiceCollection services)
{
services.AddIdentityServer()
.AddSigningCredential(new X509Certificate2(Path.Combine(".", "cert", "token-cert.pfx"), "cert-password"))
.AddInMemoryApiResources(Config.GetApiResources())
.AddClientStore<CustomClientStore>();
string connectionString = Configuration.GetConnectionString("DefaultConnection");
// a data service to fetch user data from database
services.AddTransient<IUserDataMapper>(s => new UserDataMapper(connectionString));
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole();
loggerFactory.AddDebug();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseIdentityServer();
app.Run(async (context) =>
{
await context.Response.WriteAsync("ACME Auth Token API v1.0");
});
}
你可以找到IdentityServer4在https://identityserver4.readthedocs.io/en/release/quickstarts/1_client_credentials.html#defining-the-api
详细的解释,我认为你正在寻找https://identityserver.io/ – Veikedo