private void SetApplicationSession(CommonUserDetailsViewModel commonUser)
        {
            HttpContext.Session.SetInt32(AllSessionKeys.RoleId, commonUser.RoleId);
            HttpContext.Session.SetString(AllSessionKeys.UserId, Convert.ToString(commonUser.UserId));
            HttpContext.Session.SetString(AllSessionKeys.UserName, Convert.ToString(commonUser.UserName));
            HttpContext.Session.SetString(AllSessionKeys.RoleName, Convert.ToString(commonUser.RoleName));
            if (commonUser.FirstName != null)
            {
                HttpContext.Session.SetString(AllSessionKeys.FirstName, Convert.ToString(commonUser.FirstName));
            }

            HttpContext.Session.SetString(AllSessionKeys.EmailId, Convert.ToString(commonUser.EmailId));
            HttpContext.Session.SetString(AllSessionKeys.MobileNo, Convert.ToString(commonUser.MobileNo));
        }
Example #2
0
        private string GenerateJwtToken(CommonUserDetailsViewModel model)
        {
            var tokenHandler    = new JwtSecurityTokenHandler();
            var key             = Encoding.ASCII.GetBytes(_appSettings.SecretKey);
            var tokenDescriptor = new SecurityTokenDescriptor
            {
                Issuer   = _appSettings.Issuer,
                Audience = _appSettings.Audience,
                IssuedAt = DateTime.Now,
                Subject  = new ClaimsIdentity(new[]
                {
                    new Claim("uid", model.UserId.ToString()),
                    new Claim("roleId", model.RoleId.ToString()),
                    new Claim("role", model.RoleName),
                }),
                Expires            = DateTime.UtcNow.AddMinutes(Convert.ToInt32(_appSettings.Expires)),
                SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
            };
            var token = tokenHandler.CreateToken(tokenDescriptor);

            return(tokenHandler.WriteToken(token));
        }