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");
});
}
1 回答
这个有可能 .
这是我们的做法 .
我们使用IdentityServer4为客户端生成JWT令牌 . 我们创建了一个简单的MVC项目,该项目具有以下简单的启动文件,可以为您提供一个想法 .
您可以在https://identityserver4.readthedocs.io/en/release/quickstarts/1_client_credentials.html#defining-the-api找到IdentityServer4的详细说明 .