Example #1
0
        public string Generate(int userId, string email, Common.User.UserRole role)
        {
            var tokenDescriptor = new SecurityTokenDescriptor
            {
                Subject = new ClaimsIdentity(new Claim[]
                {
                    new Claim(ClaimTypeNameUserId, userId.ToString()),
                    new Claim(ClaimTypes.Email, email),
                    new Claim(ClaimTypes.Role, role.ToString())
                }),
                Expires            = DateTime.UtcNow.AddHours(1),
                NotBefore          = DateTime.UtcNow,
                SigningCredentials = new SigningCredentials(
                    authenticationManager.GetSymmetricSecurityKey(), SecurityAlgorithms.HmacSha256)
            };
            var tokenHandler = new JwtSecurityTokenHandler();

            return(tokenHandler.WriteToken(tokenHandler.CreateToken(tokenDescriptor)));
        }