I'm quite frustrated about the fact that an authentication scheme appears to be mandatory in Asp.Net Core. My objective is to build an API and I don't want to know anything about the client. I've built custom authentication and authorization, which works fine. I'm not using identity or cookies. However, I can't return a 403 Forbid result without a valid authentication scheme, otherwise I get the following exception...
System.InvalidOperationException: No authentication handler is configured to handle the scheme: Automatic
My question is, can I configure MVC to not use an authentication scheme or create an authentication scheme without the reliance on a login path or any path for that matter?
After poring over the Asp.net Core security source code, I've managed to create a custom authentication handler. To do this you need to implement 3 classes.
The first class implements an abstract AuthenticationOptions.
The second class implements an abstract AuthenticationHandler.
The third class implements an abstract AuthenticationMiddleware.
Finally, you use the middleware component in the Startup.cs Configure method.
Now you can build your own Authentication Schemes.