Ejemplo n.º 1
0
        public void IdentitySignin(UserCredential user, string providerKey = null, bool isPersistent = false)
        {
            var claims = new List <Claim>();

            // create required claims
            claims.Add(new Claim(ClaimTypes.NameIdentifier, user.UserID.ToString()));
            claims.Add(new Claim(ClaimTypes.Name, user.Email));

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

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

            AuthenticationManager.SignIn(new AuthenticationProperties()
            {
                AllowRefresh = true,
                IsPersistent = isPersistent,
                ExpiresUtc   = DateTime.UtcNow.AddDays(7)
            }, identity);
        }