feat: 后端完成双token刷新功能

This commit is contained in:
陈淳
2024-01-24 11:26:44 +08:00
parent c18334002c
commit c9e01e0782
7 changed files with 51 additions and 12 deletions

View File

@@ -41,7 +41,7 @@ namespace Yi.Framework.Rbac.Domain.Managers
, IOptions<JwtOptions> jwtOptions
, ILocalEventBus localEventBus
, UserManager userManager
,IOptions<RefreshJwtOptions> refreshJwtOptions
, IOptions<RefreshJwtOptions> refreshJwtOptions
, ISqlSugarRepository<RoleEntity> roleRepository)
{
_repository = repository;
@@ -50,7 +50,7 @@ namespace Yi.Framework.Rbac.Domain.Managers
_localEventBus = localEventBus;
_userManager = userManager;
_roleRepository = roleRepository;
_refreshJwtOptions= refreshJwtOptions.Value;
_refreshJwtOptions = refreshJwtOptions.Value;
}
/// <summary>
@@ -112,11 +112,15 @@ namespace Yi.Framework.Rbac.Domain.Managers
return returnToken;
}
private string CreateRefreshToken()
public string CreateRefreshToken(Guid userId)
{
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_refreshJwtOptions.SecurityKey));
var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
var claims =new List<Claim> { new Claim("Refresh", "true") } ;
//添加用户id及刷新token的标识
var claims = new List<Claim> {
new Claim(AbpClaimTypes.UserId,userId.ToString()),
new Claim(TokenTypeConst.Refresh, "true")
};
var token = new JwtSecurityToken(
issuer: _refreshJwtOptions.Issuer,
audience: _refreshJwtOptions.Audience,

View File

@@ -10,6 +10,7 @@ namespace Yi.Framework.Rbac.Domain.Managers
{
public interface IAccountManager : IDomainService
{
string CreateRefreshToken(Guid userId);
Task<string> GetTokenByUserIdAsync(Guid userId);
Task LoginValidationAsync(string userName, string password, Action<UserEntity> userAction = null);
Task RegisterAsync(string userName, string password, long phone);