This is not a bug per se, more of a documentation issue. My apologies if I should have categorized it differently.
I previously submitted this change as a pull request (https://github.com/IdentityServer/IdentityServer4/pull/4404/files). Again my apologies, I don't think that was the best way to communicate what I believe to be a documentation issue.
docs/topics/cors.rst indicates that you define Allowed Origins like this:
var cors = new DefaultCorsPolicyService(_loggerFactory.CreateLogger
{
AllowedOrigins = { "https://foo", "https://bar" }
};
services.AddSingleton
However, this was not working for me. What I did eventually get working is:
services.AddSingleton
var logger = container.GetRequiredService
return new DefaultCorsPolicyService(logger) {
AllowedOrigins = { "https://foo", "https://bar" }
};
});
I believe the reason that the former approach did not work is that an instance of _loggerFactory is no longer available in Startup.cs->ConfigureServices(). I believe this is due to a change Microsoft made in the approach to configuring logging in .NET Core 3.1.
I am facing the same issue. the original code no longer works.
But the code suggested by @abarker11101 also does not work. it keeps saying that the ILogger provided by Microsoft is not compatible with the ILogger need by DefaultCorsPolicyService.
I think this code may work better:
services.AddSingleton<ICorsPolicyService>((container) => {
var logger = container.GetRequiredService<ILogger<DefaultCorsPolicyService>>();
return new DefaultCorsPolicyService(logger) {
AllowedOrigins = { "https://foo", "https://bar" }
};
});
@abarker11101 that worked.
Yes, you're absolutely right -- I made the change on my docs PR. Thank you!
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.