-
Notifications
You must be signed in to change notification settings - Fork 10k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a multitenant auth options sample #4126
Comments
hi @HaoK - I have scenario of multi-tenant auth, where I need to dynamically add OAuth2 Scheme based on tenant (each tenant has its own OAuth Options) and wire it with cookie scheme for my aspnet core web app (not implemented with any Javascript framework). Please suggest if this is possible with these auth samples. Thanks |
Try doing something like this sample aspnet/AuthSamples#44 |
@HaoK - Is it also possible to add Auth Handler dynamically, similar to adding/removing auth scheme from a controller? for example in a controller action method, can we do something like? .AddScheme<SimpleOptions, SimpleAuthHandler>("fromAction", o => o.DisplayMessage = "I am from controller action.") Also, even if this possible, how can this whole dynamic auth handler registration via action method be done for application running in a web farm. Actually I have a case where a tenant gets dynamically registered to the web application passing there OAuth Options on the fly. This is scenario of SMART on FHIR (HL7 Standard) |
Yes, you can just use the IAuthenticationSchemeProvider and call AddScheme, but you would probably have to have your implementation of this use some kind of shared data store backing the implementation to make them consistent across the web farm. |
@HaoK -- So I am trying to get PostConfigureOptions going my "SimpleOptions" by registering like this; public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication();
services.AddSingleton<IAuthenticationSchemeProvider, CustomAuthenticationSchemeProvider>();
services.TryAddEnumerable(ServiceDescriptor.Singleton<IPostConfigureOptions<SimpleOptions>, SimpleOptionsPostConfigureOptions<SimpleOptions, SimpleAuthHandler>());
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
} But the PostConfigure method in my SimpleOptionsPostConfigureOptions never hits ? here is my SimpleOptionsPostConfigureOptions class, Please suggest whats missing; public class SimpleOptionsPostConfigureOptions<SimpleOptions, SimpleAuthHandler> : IPostConfigureOptions<SimpleOptions>
where SimpleOptions : AuthenticationSchemeOptions, new()
where SimpleAuthHandler : AuthenticationHandler<SimpleOptions>
{
public void PostConfigure(string name, SimpleOptions options)
{
throw new NotImplementedException();
}
} |
@HaoK will this be in 2.2, or should we move this out? |
You can move it out, there's some weird build flakiness that this sample introduces, I will merge it into master once its consistently passing on CI |
Assuming we have some sort of middleware that sets the Do you see any problems doing this custom AuthenticationMiddleware that has Now we can easily have a "container" per tenant with Authentication schemes/options defined there. Example from:
|
See aspnet/Security#1718 for more context
The text was updated successfully, but these errors were encountered: