mirror of https://github.com/abpframework/abp
parent
946bd7fb79
commit
f91fccc510
@ -1,24 +0,0 @@
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Volo.Abp.MultiTenancy;
|
||||
|
||||
namespace Volo.Abp.AspNetCore.MultiTenancy
|
||||
{
|
||||
public class ClaimsHttpTenantResolveContributer : HttpTenantResolveContributerBase
|
||||
{
|
||||
protected override void ResolveFromHttpContext(ITenantResolveContext context, HttpContext httpContext)
|
||||
{
|
||||
if (httpContext.User?.Identity?.IsAuthenticated == true)
|
||||
{
|
||||
base.ResolveFromHttpContext(context, httpContext);
|
||||
context.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected override string GetTenantIdOrNameFromHttpContextOrNull(ITenantResolveContext context, HttpContext httpContext)
|
||||
{
|
||||
var tenantKey = context.GetAspNetCoreMultiTenancyOptions().TenantKey;
|
||||
return httpContext.User.Claims.FirstOrDefault(c => c.Type == tenantKey)?.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
using System.Linq;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Volo.Abp.Security.Claims;
|
||||
|
||||
namespace Volo.Abp.MultiTenancy
|
||||
{
|
||||
public class CurrentClaimsPrincipalTenantResolveContributer : ITenantResolveContributer
|
||||
{
|
||||
public void Resolve(ITenantResolveContext context)
|
||||
{
|
||||
var principal = context.ServiceProvider.GetRequiredService<ICurrentPrincipalAccessor>().Principal;
|
||||
if (principal?.Identity?.IsAuthenticated != true)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
context.TenantIdOrName = principal.Claims.FirstOrDefault(c => c.Type == AbpClaimTypes.TenantId)?.Value;
|
||||
context.Handled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue