新建两个WebAPI程序,假设这里取名为ApiService01(占用端口5010)和ApiService02(占用端口5020)。

为了方便快速启动,可以继续在launchSettings.json中删掉关于IISExpress的部分,由于是WebAPI,所以也不需要启动浏览器(将其设为false):
NuGet>Install-Package IdentityServer4.AccessTokenValidation
public void ConfigureServices(IServiceCollection services)
{
......
// IdentityServer
services.AddMvcCore().AddAuthorization().AddJsonFormatters();
services.AddAuthentication(Configuration["Identity:Scheme"])
.AddIdentityServerAuthentication(options =>
{
options.RequireHttpsMetadata = false; // for dev env
options.Authority = $"http://{Configuration["Identity:IP"]}:{Configuration["Identity:Port"]}";
options.ApiName = Configuration["Service:Name"]; // match with configuration in IdentityServer
});
// Swagger
......
}

{
"Service": {
"Name": "clientservice",
"Port": "5010",
"DocName": "clientservice",
"Version": "v1",
"Title": "CAS Client Service API",
"Description": "CAS Client Service API provide some API to help you get client information from CAS",
"Contact": {
"Name": "CAS 2.0 Team",
"Email": "EdisonZhou@manulife.com"
},
"XmlFile": "Manulife.DNC.MSAD.IdentityServer4Test.ApiService01.xml"
},
"Identity": {
"IP": "localhost",
"Port": "5000",
"Scheme": "Bearer"
}
}
此外,还需要在Configure方法中配置Authentication中间件:这里需要注意的就是需要放在UseMvc()之前调用。
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/tongxinshuyu/article-92987-1.html
都是纸老虎
蛆都变无氧呼吸的了