Skip to content
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

Adding external identity provider #31

Closed
RolandGuijt opened this issue Jan 21, 2018 · 25 comments
Closed

Adding external identity provider #31

RolandGuijt opened this issue Jan 21, 2018 · 25 comments

Comments

@RolandGuijt
Copy link

I'm using 1.40 latest build.
I'm adding external identity providers to the tenant specific container (for example AddGoogle, AddOpenIdConnect).
When I (in a MVC controller) get the list of configured providers using an IAuthenticationSchemeProvider instance it seems nothing is configured.

Is there something special I should do?

@dazinator
Copy link
Owner

What asp.net core version are you using, 1, 1.1 or 2.0?

@RolandGuijt
Copy link
Author

RolandGuijt commented Jan 21, 2018 via email

@dazinator
Copy link
Owner

Are you adding Mvc in the tenant container also? (And usemvc in tenant middleware pipeline?)

@dazinator
Copy link
Owner

Failing that, if you have time to point me to a repro that would really help.

@RolandGuijt
Copy link
Author

RolandGuijt commented Jan 22, 2018

Adding MVC to the tenant container and then using it in the tenant's pipeline doesn't work for me. I'm probably missing something here. See the startup below (without auth). It gives an exception when adding MVC to the pipeline: required services not found.

public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            return services.AddMultiTenancy<Tenant>((multiTenancyOptions) =>
            {
                multiTenancyOptions
                    .DistinguishTenantsWith<AcrValuesTenantDistinguisherFactory>()
                    .InitialiseTenant<TenantShellFactory>()
                    .ConfigureTenantContainers((containerBuilder) =>
                    {
                        containerBuilder.WithStructureMap((organization, tenantServices) =>
                        {
                            tenantServices.AddMvc();
                        });
                    }).ConfigureTenantMiddleware((tenantsMiddlewareBuilder) =>
                    {
                        tenantsMiddlewareBuilder.OnInitialiseTenantPipeline((context, appBuilder) =>
                        {
                            appBuilder.UseMvc(routes =>
                            {
                                routes.MapRoute(
                                    name: "default",
                                    template: "{controller=Home}/{action=Index}/{id?}");
                            });
                        });
                    });
            });
        }

        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {

            app.UseStaticFiles();

            app.UseMultitenancy<Tenant>((options) =>
            {
                options.UsePerTenantContainers();
                options.UsePerTenantMiddlewarePipeline();
            });
        }
    }

@dazinator
Copy link
Owner

Hmm cant see anything obvious. I'll try and get a better sample up and running with mvc, cookie auth and asp.net core 2.0 but it may not be for a few days or so!

@RolandGuijt
Copy link
Author

RolandGuijt commented Jan 23, 2018 via email

@RolandGuijt
Copy link
Author

RolandGuijt commented Jan 30, 2018 via email

@dazinator
Copy link
Owner

Sorry, I was making progress and then nuget.org crapped up the other night and halted me. Have been super busy since but I will get back on this hopefully this week/end

@durmisi
Copy link

durmisi commented Mar 10, 2018

Is there any progress being made on this?

@dazinator
Copy link
Owner

dazinator commented Mar 10, 2018

It's next on my agenda.. Have been spread a bit thin working on other projects with a higher priority.

@durmisi
Copy link

durmisi commented Mar 10, 2018

Thanks

@amalabey
Copy link

amalabey commented Apr 2, 2018

This issue is blocking us from using dotnettency in our project. Can you give us some tips on where to look at?

@dazinator
Copy link
Owner

dazinator commented Apr 2, 2018

@amalabey A lot of stuff changed in asp.net core 2.0 to do with authentication and identity.
Can you give me some specifics about what you are wanting to accomplish? If I could point you at a sample to help you with your use case, what would the sample show?

I have some very basic samples for asp.net core 2.0 here which may help: https://github.com/dazinator/Dotnettency.Samples/tree/aspnetcore20/src

However if you are wanting to use this for an asp.net core 2.0 project right now, then I am afraid it might be a little premature - I am hoping to find some more time to work on the project but it hasn't happened yet!

@amalabey
Copy link

amalabey commented Apr 3, 2018

Thanks for your quick response! I am trying to develop a multi-tenant app that supports multiple logical tenants identified by the subdomain in the url. Each tenant has its own database. The application should support yammer (and other providers too) but the yammer options (clientid, secret) are different for each tenant. So, need to be able to specify different yammer app settings for each tenant. Below is what I tried (with version 1.3.2).

  1. Register yammer auth in tenant container config, I get "No authentication handler is configured to handle the scheme" error.

  2. If I move AddMvc to tenant container config and UseMvc to tenant pipeline config, then I get "The constructor should not be static\r\nParameter name: constructor\r\n" error.

Btw, you've done a great job. I am still getting myself familiarize with your work. Happy to contribute in the future.

@amalabey
Copy link

amalabey commented Apr 3, 2018

Here's a sample with the issue reproduced. Note that I am using 1.3.2 with ASP.NET Core 2 here.

@durmisi
Copy link

durmisi commented Apr 13, 2018

Is there any progress being made on this? This issue is blocking me from using dotnettency in my project. Can you give some tips on where to look at?

@dazinator
Copy link
Owner

dazinator commented Apr 29, 2018

Just about to look at this now using the sample that @amalabey provided.

Like most of us, I don't get much time to spare these days, so If you are having an issue what really helps is if you can provide a repro / sample showing the problem and a quick explaination and I'll do my best to turn it around as quick as possible.

By the way I have just added a couple more asp.net core 2.0 - EF Core samples showing two approaches to multitenancy and efcore:

  • MultitenantDB (i.e one database containing records for all tenants that have some TenantID)
  • PerTenantDB (each tenant has a seperate database)

You can find those samples here: https://github.com/dazinator/Dotnettency.Samples/tree/aspnetcore20/src
You can basically just run those projects and hit them on localhost:5000-5004 on /Blogs and /AddBlog to see what happens.

@durmisi
Copy link

durmisi commented May 10, 2018

@dazinator thanks for your answer. Could you please take a look on this repo https://github.com/amalabey/Dotnettency.Sample.Core2Auth/tree/master/src/Sample.Core2Auth
where this issue is reproduced. The problem is that MVC doesn`t work when we use TenantContainers and register it per Tenant.

@dazinator
Copy link
Owner

I will begin looking at MVC per tenant container issue this evening.
Can't promise a quick turnaround im afraid though!

@dazinator
Copy link
Owner

dazinator commented May 21, 2018

So for some reason, when AddMvc() is called on the tenant container, and then that container is used to resolve a type like MvcRouteHandler - structuremap's AspNetConstructorSelector says it can't find an appropriate constructor - because it thinks services required by the constructor are not registered.

When working at the root container level, AspNetConstructorSelector sees everything fine.

I am not an expert with structure map and it looks complicated. I don't expect this to be turned round very quickly i'm afraid, unless someone can lend a hand.

It's perhaps something I am doing wrong with sturcture map, or perhaps its a bug in AspNetConstructorSelector which is only seen in child containers.

My next plan of attack is to create a replication test with structure map - basically to proof if there is an issue with AspNetConstructorSelector. If there is I will raise an issue over there. Otherwise hopefully this will help narrow down the problem.

@dazinator
Copy link
Owner

dazinator commented Aug 28, 2018

An update on this.
I have a new sample showing how Authentication can be configured for different tenants (I'm using cookie authentication)

https://github.com/dazinator/Dotnettency.Samples/tree/aspnetcore20/src/Sample.Authentication

This took a while because whilst putting it together I had to get to the bottom of a few issues and find workarounds.

  1. I raised an issue with StructureMap which is still currently unresolved: Microsoft.Extensions.Options and child container - failing test case structuremap/StructureMap.Microsoft.DependencyInjection#43

  2. I have published Dotnettency.Container.Autofac package. The sample above uses this instead of structuremap, because I was able to get Autofac working.

Please can you you let me know if this helps address your scenarios now - if not, what would you like to see. Thanks!

@RolandGuijt
Copy link
Author

RolandGuijt commented Aug 28, 2018 via email

@dazinator
Copy link
Owner

dazinator commented Aug 28, 2018

@RolandGuijt - thank you.
Also, I have a per tenant RazorPages example, where AddMvc() and UseMvc() are at the per tenant level: https://github.com/dazinator/Dotnettency.Samples/tree/aspnetcore20/src/Sample.RazorPages

It's a very basic sample, not using many MVC features or anything but still.. I haven't actually tried configuring MVC or Razor differently per tenant, they all have the same configuration in the sample. But I am assuming you could do stuff like.. Configure one tenant to pick up Razor pages from one additional folder, or include additional compilation references, tag helpers, application parts etc. I am hoping this might enable a few more interesting mvc configuration scenarios.

@dazinator
Copy link
Owner

I will close this for now, we can reopen new issue if there is any feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants