|
@@ -2,6 +2,7 @@
|
|
|
using Hotline.Identity.Accounts;
|
|
|
using Hotline.Share.Dtos.Identity;
|
|
|
using Hotline.Share.Enums.Identity;
|
|
|
+using Hotline.Users;
|
|
|
using IdentityModel;
|
|
|
using Microsoft.AspNetCore.Identity;
|
|
|
using Microsoft.Extensions.Options;
|
|
@@ -17,17 +18,20 @@ public class IdentityAppService : IIdentityAppService, IScopeDependency
|
|
|
{
|
|
|
private readonly IAccountRepository _accountRepository;
|
|
|
private readonly IAccountDomainService _accountDomainService;
|
|
|
+ private readonly IUserRepository _userRepository;
|
|
|
private readonly IJwtSecurity _jwtSecurity;
|
|
|
private readonly IOptionsSnapshot<IdentityConfiguration> _identityOptionsAccessor;
|
|
|
|
|
|
public IdentityAppService(
|
|
|
IAccountRepository accountRepository,
|
|
|
IAccountDomainService accountDomainService,
|
|
|
+ IUserRepository userRepository,
|
|
|
IJwtSecurity jwtSecurity,
|
|
|
IOptionsSnapshot<IdentityConfiguration> identityOptionsAccessor)
|
|
|
{
|
|
|
_accountRepository = accountRepository;
|
|
|
_accountDomainService = accountDomainService;
|
|
|
+ _userRepository = userRepository;
|
|
|
_jwtSecurity = jwtSecurity;
|
|
|
_identityOptionsAccessor = identityOptionsAccessor;
|
|
|
}
|
|
@@ -61,6 +65,12 @@ public class IdentityAppService : IIdentityAppService, IScopeDependency
|
|
|
account.AccessFailedCount = 0;
|
|
|
await _accountRepository.UpdateAsync(account, cancellationToken);
|
|
|
|
|
|
+ var user = await _userRepository.Queryable()
|
|
|
+ .Includes(d => d.Organization)
|
|
|
+ .FirstAsync(d => d.Id == account.Id);
|
|
|
+ if (user == null)
|
|
|
+ throw UserFriendlyException.SameMessage("未查询到用户数据");
|
|
|
+
|
|
|
var jwtOptions = _identityOptionsAccessor.Value.Jwt;
|
|
|
var claims = new List<Claim>
|
|
|
{
|
|
@@ -70,6 +80,9 @@ public class IdentityAppService : IIdentityAppService, IScopeDependency
|
|
|
new(AppClaimTypes.UserDisplayName, account.Name),
|
|
|
new(JwtClaimTypes.Scope,jwtOptions.Scope),
|
|
|
new(AppClaimTypes.UserPasswordChanged, account.PasswordChanged.ToString()),
|
|
|
+ new(AppClaimTypes.DepartmentId, user.OrgId??string.Empty),
|
|
|
+ new(AppClaimTypes.DepartmentCode, user.OrgCode??string.Empty),
|
|
|
+ new(AppClaimTypes.DepartmentName, user.Organization?.OrgName??string.Empty),
|
|
|
};
|
|
|
claims.AddRange(account.Roles.Select(d => new Claim(JwtClaimTypes.Role, d.Name)));
|
|
|
var token = _jwtSecurity.EncodeJwtToken(claims);
|