예제 #1
0
        public void IdentitySignin(AppUserState appUserState, string providerKey = null, bool isPersistent = false)
        {
            var claims = new List <Claim>();

            // create *required* claims
            claims.Add(new Claim(ClaimTypes.NameIdentifier, appUserState.UserId));
            claims.Add(new Claim(ClaimTypes.Name, appUserState.UserName));

            // serialized AppUserState object
            claims.Add(new Claim("userState", appUserState.ToString()));
            claims.Add(new Claim("LoginUserId", appUserState.UserId));
            claims.Add(new Claim("EmployeeId", appUserState.EmployeeId.ToString()));
            claims.Add(new Claim("LoginRoleId", appUserState.RoleId.ToString()));
            claims.Add(new Claim("LoginRoleName", appUserState.RoleName.ToString()));

            var identity = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie);

            // add to user here!
            AuthenticationManager.SignIn(new AuthenticationProperties()
            {
                AllowRefresh = true,
                IsPersistent = isPersistent,
                ExpiresUtc   = DateTime.UtcNow.AddMinutes(30)
            }, identity);
        }
예제 #2
0
        //End
        //End


        public void IdentitySignin(AppUserState appUserState, string providerKey = null, bool isPersistent = false)
        {
            var claims = new List <Claim>();

            // create required claims
            claims.Add(new Claim(ClaimTypes.NameIdentifier, appUserState.UserId.ToString()));
            claims.Add(new Claim(ClaimTypes.Name, appUserState.Name));
            //claims.Add(new Claim(ClaimTypes.Role, appUserState.RoleId));


            // custom – my serialized AppUserState object
            claims.Add(new Claim("userState", appUserState.ToString()));

            var identity = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie);

            AuthenticationManager.SignIn(new AuthenticationProperties()
            {
                AllowRefresh = true,
                IsPersistent = isPersistent,
                ExpiresUtc   = DateTime.UtcNow.AddDays(7)
            }, identity);
        }
예제 #3
0
        /// <summary>
        ///     Helper method that adds the Identity cookie to the request output
        ///     headers. Assigns the userState to the claims for holding user
        ///     data without having to reload the data from disk on each request.
        ///     AppUserState is read in as part of the baseController class.
        /// </summary>
        /// <param name="appUserState"></param>
        /// <param name="providerKey"></param>
        /// <param name="isPersistent"></param>
        public void IdentitySignin(AppUserState appUserState, string providerKey = null, bool isPersistent = false)
        {
            var claims = new List <Claim>();

            // create *required* claims
            claims.Add(new Claim(ClaimTypes.NameIdentifier, appUserState.UserId.ToString()));
            claims.Add(new Claim(ClaimTypes.Name, appUserState.Name));

            // serialized AppUserState object
            claims.Add(new Claim("userState", appUserState.ToString()));
            var identity = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie);

            // add to user here!
            AuthenticationManager.SignIn(new AuthenticationProperties
            {
                AllowRefresh = true,
                IsPersistent = isPersistent,
                ExpiresUtc   = DateTime.UtcNow.AddDays(7)
            }, identity);

            //var token = Helpers.GenerateToken(appUserState.Name.ToLower(), appUserState.Wgs, appUserState.Ds, "inreachweb");
            //ViewData["access_token"] = Helpers.WriteToken(token);
            //ViewData["access_token_ttl"] = token.ValidTo.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds;
        }
        /// <summary>
        /// Helper method that adds the Identity cookie to the request output
        /// headers. Assigns the userState to the claims for holding user
        /// data without having to reload the data from disk on each request.
        /// 
        /// AppUserState is read in as part of the baseController class.
        /// </summary>
        /// <param name="appUserState"></param>
        /// <param name="providerKey"></param>
        /// <param name="isPersistent"></param>
        public void IdentitySignin(AppUserState appUserState, string providerKey = null, bool isPersistent = false)
        {
            var claims = new List<Claim>();

            // create *required* claims
            claims.Add(new Claim(ClaimTypes.NameIdentifier, appUserState.UserId));
            claims.Add(new Claim(ClaimTypes.Name, appUserState.Name));

            // serialized AppUserState object
            claims.Add(new Claim("userState", appUserState.ToString()));

            var identity = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie);

            // add to user here!
            AuthenticationManager.SignIn(new AuthenticationProperties()
            {
                AllowRefresh = true,
                IsPersistent = isPersistent,
                ExpiresUtc = DateTime.UtcNow.AddDays(7)
            }, identity);
        }