3

ASP.NET Web API 2 comes with five filter interfaces:

  • IActionFilter
  • IAuthenticationFilter
  • IAuthorizationFilter
  • IExceptionFilter
  • IOverrideFilter

All of those interfaces have built-in implementations (e.g. ActionFilterAttribute, AuthorizationFilterAttribute), except for IAuthenticationFilter. Is there a reason for that or have Web API devs simply forgot to provide an implementation for that particular interface?

UPDATE

After reading Yishai Galatzer's answer I ended up implementing the "missing" attribute and uploaded it to Nuget.org: https://www.nuget.org/packages/WebApi.AuthenticationFilter

4
  • I assume there's no AuthenticationFilterAttribute because you can fulfill the use-case by using the AuthorizationFilterAttribute (assuming the use-case is you only "authorize" people who have authenticated) Commented May 8, 2014 at 23:52
  • To elaborate further, authorization is the process of granting access, authentication can then be used to determine authorization. Commented May 8, 2014 at 23:55
  • @Matthew The IAuthenticationFilter interface was introduced in v2 so you don't have to use an authorization filter to perform both authentication and authorization, which is indeed a good thing. What I don't quite understand is why they haven't provided an implementation for that new interface so that I can subclass it and implement my custom authentication the same way as I do for custom authorization. Commented May 9, 2014 at 0:10
  • @Matthew I certainly can implement IAuthenticationFilter myself and it will work just fine. But for me it would be more consistent to subclass a FilterAttribute class as it's usually done with all other filters. Commented May 9, 2014 at 0:18

1 Answer 1

1

Because we don't expect the common user to use an AuthenticationFilter. This is a way of not putting it front and center.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.