Provide a way to prevent AuthenticationSchemeProvider from picking a specific scheme handler #1287
Description
When there's only one authentication handler registered, AuthenticationSchemeProvider
uses it as the default scheme handler for basically everything (authentication, challenge, forbidden, sign-in and sign-out).
Sadly, this logic makes no sense for handlers like ASOS, that throws an InvalidOperationException
if you try to call one of the IAuthenticationService
methods outside an OpenID Connect request (for obvious security reasons).
Yet, AuthenticationMiddleware
uses GetDefaultAuthenticateSchemeAsync()
and automatically calls [ASOS].AuthenticateAsync()
for each request, which is detected as an invalid operation and causes an exception when ASOS is the only handler registered in the DI container.
Please consider adding a flag to disable this extremely annoying behavior, either at the global level, or per-handler.
/cc @HaoK