Ejemplo n.º 1
0
        private async Task SignInAsync(ApplicationUser user, bool isPersistent)
        {
            //Comentado devido ao uso do SignalR
            //var sessionKey = ApplicationSignInManager.getSessionKey(user,Request);
            //await userManager.AddSessionAsync(user, sessionKey);

            AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie, DefaultAuthenticationTypes.TwoFactorCookie);
            AuthenticationManager.SignIn(new AuthenticationProperties { IsPersistent = isPersistent }, await user.GenerateUserIdentityAsync(userManager));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Authenticar o usuario e registra a sessao do mesmo
        /// </summary>
        /// <param name="user">O usuario a ser logado.</param>
        /// <param name="isPersistent"></param>
        /// <returns></returns>
        private async Task SignInAsync(ApplicationUser user, bool isPersistent)
        {
            //Comentado devido ao uso do SignalR
            //var sessionKey = ApplicationSignInManager.getSessionKey(user, Request);
            //await userManager.AddSessionAsync(user, sessionKey);

            // Zerando contador de logins errados.
            await userManager.ResetAccessFailedCountAsync(user.Id);

            // Coletando Claims externos (se houver)
            ClaimsIdentity ext = await AuthenticationManager.GetExternalIdentityAsync(DefaultAuthenticationTypes.ExternalCookie);

            AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie, DefaultAuthenticationTypes.TwoFactorCookie, DefaultAuthenticationTypes.ApplicationCookie);
            AuthenticationManager.SignIn(
                    new AuthenticationProperties { IsPersistent = isPersistent },
                // Criação da instancia do Identity e atribuição dos Claims
                    await user.GenerateUserIdentityAsync(userManager, ext)
                );
        }