IdentityServer / IdentityServer4

OpenID Connect and OAuth 2.0 Framework for ASP.NET Core
https://identityserver.io
Apache License 2.0
9.21k stars 4k forks source link

ASP.NET Core CORS policy cannot be mixed with IdentityServer4 CORS #5474

Closed Perustaja closed 1 year ago

Perustaja commented 1 year ago

Issue #3780 never got resolved and is valid.

If you try to mix the ASP.NET Core default CORS policy control with IdentityServer4's, IdentityServer4 seems to step over it when used as described in the documentation.

As an example here is my IDP. It has the usual endpoints and then an api for user data. Here is the Startup.cs file as the documentation says to set it up: Code_9IfU77Pr5b

The default policy is defined here. The localhost origin is where my Angular client is located. Code_K2BFKarjtN

Upon trying to access the api on my IDP this debug message displays: Code_PtcyJY2HTC

Which doesn't seem to make sense. I have debugged a manual service implementation and checked the source code.

It seems like the IdentityServer4 CorsPolicyProvider steps over every other piece of CORS middleware and blocks requests that aren't to the authentication paths. There have been numerous issues surrounding this but I can't seem to get an api request to go through from my client in any way. Based on other issues I've tried:

Neither seem to work.

Perustaja commented 1 year ago

Fixed by reading https://docs.identityserver.io/en/latest/topics/add_apis.html

github-actions[bot] commented 1 year ago

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.