多租户身份验证,ASP.NET样板模块零中的IMustHaveTenant实体 [英] Multi-tenant authentication, IMustHaveTenant entity in ASP.NET Boilerplate Module Zero
问题描述
我已经从swagger UI中以管理员身份创建了一个新的租户,我可以检入数据与管理员帐户一起成功创建的租户.
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.
现在如何以新创建的租户的管理员身份登录?
我尝试通过Postman进行令牌身份验证,在请求正文中指定tenancyName
,即使我在 中放入垃圾,它似乎也只能从default
租户-身份验证管理员. c0>字段,它将不会检测到任何错误或异常.
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.
我检查CoreModule.cs
中的配置值,并且 MultiTenancyEnabled
已设置为true
I check the configuration value in the CoreModule.cs
and MultiTenancyEnabled
has been set to true
我也想将我的一个实体与tenant
实体相关联.因此,我将类基于IMustHaveTenant
界面沿FullAuditedEntity
放置,如下所示:
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; }
}
是否足够?还是必须在DbContext
中进一步输入任何代码?
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?
对于基于令牌的身份验证,请发送租户ID在 Abp.TenantId 标头中.
For Token Based Authentication, send the tenant id in the Abp.TenantId header.
在邮递员中,单击标题,将密钥添加为Abp.TenantId
,将值添加为您的租户ID.如果您刚刚创建了一个新的租户,则将为2
,因为存在一个ID为1的默认租户.
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.
我也想将我的一个实体与
tenant
实体相关联. [...]是否足够?还是必须在DbContext
中进一步输入任何代码?
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 theDbContext
?
您必须在 DbContext
:
public class MyDbContext : AbpDbContext
{
public DbSet<Product> Products { get; set; }
public MyDbContext(DbContextOptions<MyDbContext> options)
: base(options)
{
}
}
这篇关于多租户身份验证,ASP.NET样板模块零中的IMustHaveTenant实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!