public async Task <string> GenerateTokenAsync(User user) { var identityUser = _mapper.Map <IdentityUser>(user); var userClaims = await GetUserClaimsAsync(identityUser); var tokenDescriptor = new SecurityTokenDescriptor { Issuer = JwtHelper.Issuer, Audience = JwtHelper.Audience, Subject = new ClaimsIdentity(userClaims), Expires = JwtHelper.TokenLifetTime, SigningCredentials = JwtHelper.CreateCredentials() }; var handler = new JwtSecurityTokenHandler(); var token = handler.CreateToken(tokenDescriptor); return(handler.WriteToken(token)); }