private ApplicationUserWithToken SignIn(ApplicationUser account, Guid countryId) { string roleId = _userRoleCountryService.GetAll(countryId).Where(x => x.ApplicationUserId == account.Id).First().RoleId; var role = _roleManager.FindByIdAsync(roleId).GetAwaiter().GetResult(); var symmetricKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_configuration["SecretKey:Value"])); var signingCredentials = new SigningCredentials(symmetricKey, SecurityAlgorithms.HmacSha256); var claims = new List <Claim> { new Claim(ClaimTypes.Name, account.UserName), new Claim(ClaimTypes.Role, role.Name) }; var tokenOptions = new JwtSecurityToken( issuer: _configuration.GetValue <string>("EnvironmentUrl:Value"), audience: _configuration.GetValue <string>("EnvironmentUrl:Value"), claims: claims, expires: DateTime.Now.AddDays(7), signingCredentials: signingCredentials ); return(new ApplicationUserWithToken() { Email = account.Email, Id = account.Id, UserName = account.UserName, Role = role.Name, PhoneNumber = account.PhoneNumber, Token = new JwtSecurityTokenHandler().WriteToken(tokenOptions), }); }