Provide Options to JwtBearerAuthenticationScheme dynamically per request #26558
-
I have a multi-tenant web application. Each tenant has a unique hostname. ex. tenant1.mycompany.com, tenant2.mycompany.com. We have IdentityServer4 based app to issue oAuth 2 tokens. This token issuer app also works in a multi-tenant model i.e. same instance of the application can be reached as https://tenant1.mycompany.com/tokenissuer etc. We have other services in our application, which hosts APIs supporting different functional areas. All these services are multi-tenant applications and accessible as http://tenant1.mycompany.com/service1/api/... For the other services (developed using ASP.Net Core 3.1) to accept and validate access tokens issues by the token issuer, I am trying to use JwtBearerAuthenticationScheme. However, the configurations (i.e. issues, authority, IssuerSigningKey, etc - JwtBearerOptions) for this scheme need to be provided at the time of configuring services. We will not have these details at the time of application startup, as the configuration values are different for each tenant. Is there a way to provide these options per request? We have another middleware, which identifies a tenant and builds all necessary configuration at the beginning of the request pipeline. I am currently using the following code snippet in my ConfigureServices method, to test using a hardcoded tenant.
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
No, multi-tenant auth is not currently supported. The closest you can get today is to add a JwtBearer instance per tenant at startup and then invoke them by auth scheme name. |
Beta Was this translation helpful? Give feedback.
No, multi-tenant auth is not currently supported. The closest you can get today is to add a JwtBearer instance per tenant at startup and then invoke them by auth scheme name.