简体   繁体   中英

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

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

在此处输入图片说明

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 ?

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)
    {
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM