Multi-tenant authentication, IMustHaveTenant entity in ASP.NET Boilerplate Module Zero

asp.net-core-2.0 aspnetboilerplate c# entity-framework-core multi-tenant

Question

Multi-Tenant Authentication

I have created a new tenant from the swagger UI as an admin and I can check in the data the tenant created successfully together with admin account.

Now how do I login as the admin of the newly created tenant?

Cos I tried Token-authenticating via Postman, specifying tenancyName in the request body and it only seems to authenticate the admin from default tenant - even when I put in rubbish in the tenancyName field, it won't detect any error or exception.

I check the configuration value in the CoreModule.cs and MultiTenancyEnabled has been set to true

enter image description here

Entity Relation with Tenant

Also I would like to relate one of my entity with the tenant entity. So I based the class on IMustHaveTenant interface along side FullAuditedEntity like this:

public class Rule: FullAuditedEntity, IMustHaveTenant
{
    public string columnA { get; set; }
    public string columnB { get; set; }
    public string columnC { get; set; }
    public int TenantId { get; set; }
}

Is it enough or do I have to further put in any codes in the DbContext?

1
0
12/6/2017 10:50:04 AM

Accepted Answer

Now how do I login as the admin of the newly created tenant?

For Token Based Authentication, send the tenant id in the Abp.TenantId header.

In Postman, click on Headers, add the Key as Abp.TenantId and the Value as your tenant id. If you just created a new tenant, that would be 2 as there is a Default tenant with id 1.

Also I would like to relate one of my entity with the tenant entity. [...] Is it enough or do I have to further put in any codes in the DbContext?

You have to add a DbSet in your DbContext:

public class MyDbContext : AbpDbContext
{
    public DbSet<Product> Products { get; set; }

    public MyDbContext(DbContextOptions<MyDbContext> options)
        : base(options)
    {
    }
}
1
12/7/2017 2:42:22 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow