예제 #1
0
        public DisplayUserSecurity UserLog(string userId)
        {
            DisplayUserSecurity objUser = new DisplayUserSecurity();

            objUser._userInfo.user_id = userId;

            objUser.Display();

            return(objUser);
        }
예제 #2
0
        public string GenerateToken(string email)
        {
            string token           = string.Empty;
            DisplayUserSecurity Ds = new DisplayUserSecurity();

            Ds._userInfo.user_email = email;
            Ds.DisplayByEmail();

            #region "ROLES USER"
            DisplayUserSecurity _RolesUser = new DisplayUserSecurity();
            _RolesUser._userInfo.user_id = Ds._userInfo.user_id;

            List <RoleModel> collection = new List <RoleModel>((IEnumerable <RoleModel>)_RolesUser.DisplayRolesUser());

            var claims = new List <Claim>();

            foreach (var groupRoles in collection)
            {
                claims.Add(new Claim(ClaimTypes.Role, groupRoles.role_name));
            }
            claims.Add(new Claim(ClaimTypes.Name, email));
            claims.Add(new Claim("USERID", Ds._userInfo.user_id));
            claims.Add(new Claim("USEREMAIL", email));
            #endregion


            var key         = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(tokenManagement.Secret));
            var credentials = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);

            var jwtToken = new JwtSecurityToken(
                tokenManagement.Issuer,
                tokenManagement.Audience,
                claims,
                expires: DateTime.Now.AddMinutes(tokenManagement.AccessExpiration),
                signingCredentials: credentials
                );
            token = new JwtSecurityTokenHandler().WriteToken(jwtToken);
            return(token);
        }