dazinator / Dotnettency

Mutlitenancy for dotnet applications
MIT License
111 stars 23 forks source link

Question: Any thoughts why Authoriztion Attribute isn't working anymore? #41

Closed AndreSteenbergen closed 5 years ago

AndreSteenbergen commented 6 years ago

I have succesfully configured multitenant social login providers and local logins. When I add IdentityServer4, the Authorize attribute won't work anymore.

I guess somewhere in the pipeline something happens to cookies or schemes. I just can't seem to grasp the issue. Maybe someone can shed a light.

        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            var socialloginProvider = new SocialLoginProvider();
            services.ConfigurePOCO<List<TenantConfiguration>>(Configuration.GetSection("TenantConfigurations"));

            ConfigureUserStorageSystem(services);

            services.AddDefaultIdentity<ApplicationUser>(o =>
            {
                o.User.RequireUniqueEmail = true;
                o.SignIn.RequireConfirmedEmail = true;
            })
            .AddUserStore();
            ConfigureIdp(services);

            services.AddTransient<IEmailSender, AuthMessageSender>();
            services.AddTransient<ISmsSender, AuthMessageSender>();

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
            services.AddScoped<ITenantRequestContainerAccessor<Tenant>, TenantRequestContainerAccessor<Tenant>>();

            return services.AddAspNetCoreMultiTenancy<Tenant>((options) =>
            {
                options
                    .InitialiseTenant<TenantShellFactory>()
                    .ConfigureTenantContainers((containerBuilder) =>
                    {
                        containerBuilder.WithAutofac((tenant, tenantServices) =>
                        {
                            var authBuilder = tenantServices.AddAuthentication();
                            tenant.AddSocialLoginProviders(socialloginProvider, authBuilder);
                        })
                        .AddPerTenantMiddlewarePipelineServices();
                    })
                    .ConfigureTenantMiddleware((a) =>
                    {
                        a.OnInitialiseTenantPipeline((tenantContext, app) =>
                        {
                            app.UseAuthentication();
                        });
                    });
            });
        }
private static void ConfigureIdp(IServiceCollection services)
        {
            var cfg = new IdpConfiguration.Configuration();
            services.AddIdentityServer()
                .AddDeveloperSigningCredential()
                .AddInMemoryClients(cfg.Clients)
                .AddInMemoryIdentityResources(cfg.IdentityResources)
                .AddInMemoryApiResources(cfg.GetApiResources)
                .AddAspNetIdentity<ApplicationUser>();
        }
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseStaticFiles();

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

            app.UseIdentityServer();
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Manage}/{action=Index}/{id?}");
            });
        }
dazinator commented 5 years ago

Do you have a full sample repo you can share? What version of the dotnettency packages are you referencing?

dazinator commented 5 years ago

No action on this in over a year. Closing. Reopen if necessary.