I am creating a .Net 8 WebAPI which needs to support multiple OIDC providers. For each OIDC provider, I have a JwtBearer registration and a OAuth2Introspection registration, which happens in loop (based on configuration) and scheme name is unique to every provider is registered. For ex: if Abc is the provider name, then I have auth scheme as AbcBearer and 2nd one as AbcIntrospection registered. I have also defined a dummy default scheme and corresponding ForwardDefaultSelector defined which will determine the auth scheme to be used for the incoming token validation.
When a request comes in, its going through the ForwardDefaultSelector logic and goes into corresponding auth scheme’s token validation. I can also see AuthenticationScheme Validated message being written to log from the JwtBearerHandler class.
But the authentication does not stop there. Even after the token is validated by auth scheme determined by the ForwardDefaultSelector, its going to subsequent validation again against other auth schemes as well and I can see the logs showing that the token validated was not successful for those other auth schemes.
The incoming request itself does not fail and get a 200 ok response. But how do I prevent the token undergoing unnecessary authentication multiple times, even after successful authentication by the correct auth scheme?
Thanks!