コード例 #1
0
        private string GenerateToken(Common.DataObjects.Users user)
        {
            var tokenHandler    = new JwtSecurityTokenHandler();
            var secretKey       = Encoding.ASCII.GetBytes(_appSettings.SecretKey);
            var tokenDescriptor = new SecurityTokenDescriptor
            {
                Subject            = new ClaimsIdentity(new[] { new Claim("idUser", user.idUser.ToString()) }),
                Expires            = DateTime.UtcNow.AddMinutes(15),
                SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(secretKey), SecurityAlgorithms.HmacSha256Signature)
            };
            var token = tokenHandler.CreateToken(tokenDescriptor);

            return(tokenHandler.WriteToken(token));
        }
コード例 #2
0
 private LoginResponse setResponseValues(Common.DataObjects.Users user)
 {
     return(new LoginResponse(user, GenerateToken(user)));
 }