Ocelot icon indicating copy to clipboard operation
Ocelot copied to clipboard

How to bypass authentication for anonymous API

Open tungphuong opened this issue 8 years ago • 13 comments

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 avatar Aug 16 '18 10:08 tungphuong

@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.

TomPallister avatar Aug 17 '18 06:08 TomPallister

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 avatar Aug 17 '18 06:08 tungphuong

@tungphuong unfortunately this is not possible. You need to have multiple ReRoutes. I hope that this is OK.

TomPallister avatar Aug 17 '18 07:08 TomPallister

Ok thanks @TomPallister but I suggest that we can configure some specific API to ignore. It will help to have a clear configuration.

tungphuong avatar Aug 17 '18 07:08 tungphuong

@tungphuong how do you think the model could be changed to represent this use case?

TomPallister avatar Aug 17 '18 07:08 TomPallister

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 avatar Aug 17 '18 12:08 margaale

@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 avatar Aug 17 '18 17:08 TomPallister

@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.

tungphuong avatar Aug 20 '18 02:08 tungphuong

@margaale what do you mean by anonymous1 ?

adnanjalloh avatar Sep 28 '20 12:09 adnanjalloh

A real bummer that this feature is missing.

davidivkovic avatar Apr 21 '21 01:04 davidivkovic

A real bummer that this feature is missing.

MicroHeartWangZheng avatar Mar 18 '22 06:03 MicroHeartWangZheng

Agree, this feature is handy.

developinua avatar Oct 20 '22 13:10 developinua

+1

bug0314 avatar May 11 '24 08:05 bug0314