public JwtSecurityToken GenerateToken(IUserRepository repository, User user) { var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(MyConfig.Get("jwt:SecretKey"))); var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256); var expires = DateTime.Now.AddDays(Convert.ToDouble(MyConfig.Get("jwt:ExpireDays"))); List <Role> roles = repository.GetRolesOfUser(user.Id).ToList(); // Create the JWT security token and encode it. var token = new JwtSecurityToken( issuer: MyConfig.Get("jwt:Issuer"), audience: MyConfig.Get("jwt:Audience"), claims: GetValidClaims(user, roles), expires: expires, signingCredentials: creds); return(token); }