Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Multi-Tenant #541

Closed
learntecno opened this issue Dec 5, 2016 · 2 comments
Closed

Multi-Tenant #541

learntecno opened this issue Dec 5, 2016 · 2 comments
Labels

Comments

@learntecno
Copy link

I am using Identity Server4 , I want to save the IdentityResources and APIResource I am using IdentityServer4.EntityFrameworkCore and I want to save this by Tenant and I am using SASSKit for multi tenant , So I have create custom PersistedGrantDbContext as shown below.

public class SqlServerPersistedGrantDbContext : DbContext, IPersistedGrantDbContext

{
public SqlServerPersistedGrantDbContext(DbContextOptions options, AppTenant tenant) : base(options)
{
this.tenant = tenant;
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(tenant.ConnectionString);
base.OnConfiguring(optionsBuilder);
}
protected override void OnModelCreating(ModelBuilder builder)
{
//builder.ConfigurePersistedGrantContext(storeOptions);
base.OnModelCreating(builder);
}
}

and In the Start up I have added as below , but the issue is calling UseIdentityServer middleware is called first , then UseMultitenancy is called second , so because of this I could not able to get the Tenant object in the above class SqlServerPersistedGrantDbContext . Please let me know how to solve this issue. or how to store IdentityResources and APIResource in multi tenant environment.

        app.UseMultitenancy<AppTenant>();
        app.UsePerTenant<AppTenant>((ctx, builder) =>
        {

            builder.UseCookieAuthentication(new CookieAuthenticationOptions()
            {
                AuthenticationScheme = $"{ctx.Tenant.Id}Cookies",
                //LoginPath = new PathString("/account/login"),
                //AccessDeniedPath = new PathString("/account/forbidden"),
                AutomaticAuthenticate = false,
                AutomaticChallenge = false,
                CookieName = $"{ctx.Tenant.Id}.AspNet.Cookies"
            });
            builder.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
            {
                Authority = ctx.Tenant.Authority,
                AllowedScopes = { "api1" },
                RequireHttpsMetadata = false
            });

        });
        app.UseIdentity();
        app.UseIdentityServer();  
@brockallen
Copy link
Member

brockallen commented Dec 24, 2016

I'm going to close this one as a dup of #442 -- Feel free to get involved over there. Thanks.

@lock
Copy link

lock bot commented Jan 15, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants