搭建DemoApi_III 过程和第一篇中的DemoApi_I 一致json
惟一不一样在于 appsettings.json 内的 ServiceName 改成demoAPi3 而后 Port 改成 100三、api
configuration.json 内的 ReRoutes添加节点app
// API:demo3 { "UseServiceDiscovery": true, "DownstreamPathTemplate": "/api/{url}", "DownstreamScheme": "http", "ServiceName": "demoAPi3", "LoadBalancerOptions": { "Type": "LeastConnection" }, "UpstreamPathTemplate": "/demo3/{url}", "UpstreamHttpMethod": [ "Get", "Post" ], "ReRoutesCaseSensitive": false, // non case sensitive //添加身份验证 "AuthenticationOptions": { "AuthenticationProviderKey": "OcelotKey3", "AllowedScopes": [ "demoAPi3" ] } }
修改 Startup.cs ide
//添加第二个身份验证 .AddIdentityServerAuthentication("OcelotKey3", options => { options.Authority = Configuration.GetSection("Setting")["AuthUrl"]; options.ApiName = "demoAPi3"; options.SupportedTokens = SupportedTokens.Both; options.RequireHttpsMetadata = false; })
如图所示:测试
此处 未考虑优化配置 demo级别优化
注意 :ui
1.apiName内的内容区分大小写 必须和身份验证服务内定义的ApiResources的APIName 名称一致url
2.例子中第二个身份验证中的ocelotkey3 必须和第一个不一样 即 这个值必须与以前定义的不一样spa
且须要和configuration.json 中 此处的key值相同3d
完成后便可