I have multiple authentication in my .NET Core API using add multiple Jwt bearer, assume I have Schema1
, Schema2
and Schema3
.
I'm also using Ocelot to manage requests. In Ocelot config for each route I could declare one and only one authentication type (schema name). However in some scenarios I need to have multiple authentication support for each route. (I need to authenticate request with either of Schema1
, Schema2
or Schema3
).
But as Ocelot just let me add one schema name, I have to merge these 3 schemas to 1 schema.
So the basic question is: How could I define one authentication schema (SchemaX
) which authenticate by Schema1
or Schema2
or Schema3
? Any idea?
You can try to create custom AuthorizeFilter to allow multiple authentication schema like here or write a custom middleware that check url route from http context and manually calls
AuthenticateAsync()
and creates aClaimsPrincipal
containing all the identities you need like :Of course you can also move the authentication logic from three schemes into one scheme .