|
|
|
@ -4,27 +4,34 @@ using System.Security.Claims; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Microsoft.AspNetCore.Identity; |
|
|
|
using Microsoft.Extensions.Options; |
|
|
|
using Volo.Abp.Data; |
|
|
|
using Volo.Abp.DependencyInjection; |
|
|
|
using Volo.Abp.MultiTenancy; |
|
|
|
using Volo.Abp.Security.Claims; |
|
|
|
using Volo.Abp.Uow; |
|
|
|
|
|
|
|
namespace Volo.Abp.Identity |
|
|
|
{ |
|
|
|
public class AbpUserClaimsPrincipalFactory : UserClaimsPrincipalFactory<IdentityUser, IdentityRole>, ITransientDependency |
|
|
|
public class AbpUserClaimsPrincipalFactory : UserClaimsPrincipalFactory<IdentityUser, IdentityRole>, |
|
|
|
ITransientDependency |
|
|
|
{ |
|
|
|
protected ITenantStore TenantStore { get; } |
|
|
|
|
|
|
|
public AbpUserClaimsPrincipalFactory( |
|
|
|
UserManager<IdentityUser> userManager, |
|
|
|
RoleManager<IdentityRole> roleManager, |
|
|
|
IOptions<IdentityOptions> options) |
|
|
|
IOptions<IdentityOptions> options, |
|
|
|
ITenantStore tenantStore) |
|
|
|
: base( |
|
|
|
userManager, |
|
|
|
roleManager, |
|
|
|
options) |
|
|
|
userManager, |
|
|
|
roleManager, |
|
|
|
options) |
|
|
|
{ |
|
|
|
TenantStore = tenantStore; |
|
|
|
} |
|
|
|
|
|
|
|
[UnitOfWork] |
|
|
|
public async override Task<ClaimsPrincipal> CreateAsync(IdentityUser user) |
|
|
|
public override async Task<ClaimsPrincipal> CreateAsync(IdentityUser user) |
|
|
|
{ |
|
|
|
var principal = await base.CreateAsync(user); |
|
|
|
var identity = principal.Identities.First(); |
|
|
|
@ -49,7 +56,8 @@ namespace Volo.Abp.Identity |
|
|
|
identity.AddIfNotContains(new Claim(AbpClaimTypes.PhoneNumber, user.PhoneNumber)); |
|
|
|
} |
|
|
|
|
|
|
|
identity.AddIfNotContains(new Claim(AbpClaimTypes.PhoneNumberVerified, user.PhoneNumberConfirmed.ToString())); |
|
|
|
identity.AddIfNotContains( |
|
|
|
new Claim(AbpClaimTypes.PhoneNumberVerified, user.PhoneNumberConfirmed.ToString())); |
|
|
|
|
|
|
|
if (!user.Email.IsNullOrWhiteSpace()) |
|
|
|
{ |
|
|
|
@ -58,6 +66,16 @@ namespace Volo.Abp.Identity |
|
|
|
|
|
|
|
identity.AddIfNotContains(new Claim(AbpClaimTypes.EmailVerified, user.EmailConfirmed.ToString())); |
|
|
|
|
|
|
|
if (user.TenantId.HasValue) |
|
|
|
{ |
|
|
|
var tenant = await TenantStore.FindAsync(user.TenantId.Value); |
|
|
|
var editionId = tenant?.GetProperty<Guid>(AbpClaimTypes.EditionId); |
|
|
|
if (editionId != default(Guid)) |
|
|
|
{ |
|
|
|
identity.AddIfNotContains(new Claim(AbpClaimTypes.EditionId, editionId.ToString())); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return principal; |
|
|
|
} |
|
|
|
} |
|
|
|
|