Setp1: In startup.cs
public void ConfigureServices(IServiceCollection services)
{
#region Integrate with Identity Server 4
var authenticationProviderKey = "ID4";
services.AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme)
.AddIdentityServerAuthentication(authenticationProviderKey, options =>
{
options.RequireHttpsMetadata = false; //it is very important to have it in dev enviroment, otherwise will meet http 500 error
options.Authority = "http://localhost:5000";
options.ApiName = "socialnetwork";
});
#endregion
services.AddOcelot(Configuration)
.AddCacheManager(x => {
x.WithMicrosoftLogging(log =>
{
log.AddConsole(LogLevel.Debug);
})
.WithDictionaryHandle();
}); ;
}
Step2: In ocelot configuration.json
{
"DownstreamPathTemplate": "/api/values",
"DownstreamScheme": "http",
"DownstreamPort": 8802,
"DownstreamHost": "localhost",
"UpstreamPathTemplate": "/api/product",
"UpstreamHttpMethod": [ "Get" ],
"QoSOptions": {
"ExceptionsAllowedBeforeBreaking": 3,
"DurationOfBreak": 10,
"TimeoutValue": 5000
},
"AuthenticationOptions": {
"AuthenticationProviderKey": "ID4",
"AllowedScopes": []
}
}