public async Task <TokenDto> CreateTokenAsync(UserEntity user) { List <Claim> claims = new List <Claim>() { new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()), new Claim(ClaimTypes.Email, user.Email ?? ""), new Claim(ClaimTypes.GivenName, user.Nickname ?? ""), new Claim(ClaimTypes.Name, user.Username ?? ""), }; user.Roles?.ForEach(r => { claims.Add(new Claim(ClaimTypes.Role, r.Name)); claims.Add(new Claim(CoreClaimTypes.Roles, r.Id.ToString())); }); string token = _jsonWebTokenService.Encode(claims); string refreshToken = GenerateToken(); user.ChangeLoginStatus(refreshToken); await _userRepo.UpdateAsync(user); return(new TokenDto(token, refreshToken)); }