How to bypass authentication for anonymous API
Hello,
After we configure "Authentication" for one service, it will check token or apply "authentication" for all API of that service. However, in many case, there is anonymous API in this service. So, how can configure to ignore or allow "anonymous" for specific API.
Thanks,
@tungphuong please read the docs https://ocelot.readthedocs.io/en/latest/features/authentication.html you can choose which reroutes you want to apply the authentication to.
Thanks @TomPallister I know it, but my situation that in one controller, almost API need to be authorize, just some APIs allow anonymous. So, if we follow doc, we need to configure "reroute" for those APIs without authentication? It means that there is many reroute on one service.
Can we have any way to add APIs into reroute to skip authentication?
@tungphuong unfortunately this is not possible. You need to have multiple ReRoutes. I hope that this is OK.
Ok thanks @TomPallister but I suggest that we can configure some specific API to ignore. It will help to have a clear configuration.
@tungphuong how do you think the model could be changed to represent this use case?
Sorry to step in in the conversation. I was asked yesterday if ocelot was able to handle this. I know it can with priorities but i think it would be useful to have something like: "DownstreamPathTemplate": "/actions/{all}", "AuthenticationOptions": { "AuthenticationProviderKey": "Bearer", "AllowedScopes": [], "ExcludedActions": ["anonymous1", "anonymous2"] } where all actions that are not included in "ExcludedActions" are validated
@margaale no worries jump in, I wouldn't add an exclusion list like that, I'm really not a fan of exclusion style designs. I prefer to just model what I want..the cognitive load to go back and see what has been excluded doesnt make sense to me!
@TomPallister I know your point but for this situation, I also prefer approach of @margaale. Because from API gateway side, we dont know which downstream API is anonymous. Besides, just few anonymous API need to configure for one "authorize" controller.
In case, there are many anonymous API in one controller, I suggest that we move them to one separated controller and set up "reroute" for it.
@margaale what do you mean by anonymous1 ?
A real bummer that this feature is missing.
A real bummer that this feature is missing.
Agree, this feature is handy.
+1