public bool SignIn(User authenticationRequest)
 {
     if (Authenticate(authenticationRequest.Email, authenticationRequest.Password))
     {
         var identity = new ClaimsIdentity(new[] { new Claim(ClaimTypes.Email, authenticationRequest.Email) }, "CoblogaCookie");
         httpRequest.GetOwinContext().Authentication.SignIn(identity);
         return(true);
     }
     return(false);
 }
        protected static int GetCurrentUserId(HttpRequestBase request)
        {
            var owinContext = request.GetOwinContext();
            var userId      = owinContext.Get <int>("userId");

            return(userId);
        }
Example #3
0
        /// <summary>
        /// Método responsável por realizar o logout no sistema
        /// </summary>
        /// <param name="request">Request Base</param>
        public static void LogOut(HttpRequestBase request)
        {
            var ctx         = request.GetOwinContext();
            var authManager = ctx.Authentication;

            authManager.SignOut("ApplicationCookie");
        }
Example #4
0
        public bool UpdateClaim(HttpRequestBase request, Dictionary <string, string> claimValues)
        {
            try
            {
                var AuthenticationManager = request.GetOwinContext().Authentication;
                var Identity = new ClaimsIdentity(((ClaimsPrincipal)request.RequestContext.HttpContext.User).Identity);

                foreach (var kValuePair in claimValues)
                {
                    //remove the claim
                    Identity.RemoveClaim(Identity.FindFirst(kValuePair.Key));
                    //add back with new value
                    Identity.AddClaim(new Claim(kValuePair.Key, kValuePair.Value));
                }
                AuthenticationManager.AuthenticationResponseGrant = new Microsoft.Owin.Security.AuthenticationResponseGrant(new ClaimsPrincipal(Identity), new Microsoft.Owin.Security.AuthenticationProperties {
                    IsPersistent = true
                });
                //logout and log back in quickly
                AuthenticationManager.SignOut(Identity.AuthenticationType);
                AuthenticationManager.SignIn(new Microsoft.Owin.Security.AuthenticationProperties()
                {
                    IsPersistent = true
                }, Identity);
                return(true);
            }
            catch (Exception ex)
            {
                string err = ex.Message;
                //eat any exceptions.
                return(false);
            }
        }
Example #5
0
        private static IAuthenticationManager GetAuthManager(HttpRequestBase requestBase)
        {
            var ctx         = requestBase.GetOwinContext();
            var authManager = ctx.Authentication;

            return(authManager);
        }
        public static string GetProfile(this HttpRequestBase request)
        {
            var owinContext  = request.GetOwinContext();
            var identity     = owinContext.Request.User.Identity as ClaimsIdentity;
            var profileClaim = identity.Claims.FirstOrDefault(c => c.Type == SignInService.PROFILE_TYPE_CLAIMS_KEY);

            return(profileClaim.Value);
        }
Example #7
0
        public void createOwinIdentity(UserAccount user, HttpRequestBase request)
        {
            var identity = new ClaimsIdentity(new[] {
                new Claim(ClaimTypes.Name, user.Username),
            },
                                              "ApplicationCookie");

            var ctx         = request.GetOwinContext();
            var authManager = ctx.Authentication;

            authManager.SignIn(identity);
        }
        private static void UpdateUserUiCulture(HttpRequestBase request, string uiCulture, IIdentity userIdentity)
        {
            //Andriy: Difficult to test this method, not fully clear how to correct inject database access in this code
            string aspNetUserId = userIdentity.GetUserId();
            //Update user Ui Culture in database
            var        db   = request.GetOwinContext().Get <HellolingoEntities>();
            AspNetUser user = db.AspNetUsers.Find(aspNetUserId);

            if (user == null)
            {
                Log.Warn(LogTag.CultureAwareActivator_UserNotFound, request, new { AspNetUserId = aspNetUserId });
                return;
            }
            user.UiCulture = uiCulture;
            db.SaveChanges();
            //Update user claims with new Ui Culture.
            var signInManager = request.GetOwinContext().Get <ApplicationSignInManager>();

            signInManager.AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
            var            applicationUserManager = request.GetOwinContext().GetUserManager <ApplicationUserManager>();
            ClaimsIdentity newUserIdentity        = user.GenerateUserIdentity(applicationUserManager);

            signInManager.AuthenticationManager.SignIn(newUserIdentity);
        }
Example #9
0
        public static void Autenticar(string nome, string email, long usuarioId, HttpRequestBase request)
        {
            var identity = new ClaimsIdentity(new[]
            {
                new Claim(ClaimTypes.Name, nome),
                new Claim(ClaimTypes.Email, email),
                new Claim("Id", usuarioId.ToString())
            }, "ApplicationCookie");

            var ctx = request.GetOwinContext();

            var authManager = ctx.Authentication;

            authManager.SignIn(identity);
        }
Example #10
0
        public static void Login(LogInModel loginModel, HttpRequestBase request, List <string> sistemas)
        {
            try
            {
                //var searchResult = AutenticateActiveDirectory(loginModel);

                //List<string> listaGrupos = GetGruposActiveDirectory(searchResult);

                //if (listaGrupos == null || listaGrupos.Count <= 0)
                //{
                //    throw new Exception("Usuario não possui acesso ao sistema");
                //}

                var identity = new ClaimsIdentity("ApplicationCookie");
                //identity.AddClaim(new Claim(ClaimTypes.Name, GetNomeCompletoUsuario(searchResult)));
                //identity.AddClaim(new Claim(ClaimTypes.Sid, loginModel.UserName));
                identity.AddClaim(new Claim(ClaimTypes.Name, loginModel.UserName.ToUpper()));
                identity.AddClaim(new Claim(ClaimTypes.Sid, loginModel.UserName.ToUpper()));
                //foreach (string grupo in listaGrupos)
                //{
                //    identity.AddClaim(new Claim(ClaimTypes.Role, grupo));
                //}

                var ctx         = request.GetOwinContext();
                var authManager = ctx.Authentication;

                //indica que o o cookie expira junto com a sessão
                authManager.SignIn(new AuthenticationProperties()
                {
                    IsPersistent = loginModel.RememberMe
                }, identity);
            }
            catch (Exception ex)
            {
                throw new Exception("Não foi possível realizar o login. " + ex.Message, ex);
            }
        }
Example #11
0
 public UserObject(HttpRequestBase request)
 {
     var owin        = request.GetOwinContext();
     var authManager = owin.Authentication;
 }
Example #12
0
 /// <summary>
 /// Tests whether the current user is an Administrator
 /// </summary>
 /// <param name="request">The request base that this extension is applied to</param>
 /// <returns>true if the user is an Administrator, else false</returns>
 public static bool IsAdmin(this HttpRequestBase request)
 {
     return(request.GetOwinContext().Authentication.User.IsInRole(Sentinel.Views.User.AccessLevel.Administrator.ToString()));
 }
Example #13
0
 public void SignIn(HttpRequestBase request, params ClaimsIdentity[] claims)
 {
     request.GetOwinContext().Authentication.SignIn(claims);
 }
Example #14
0
 public static ApplicationSignInManager GetSignInManager(this HttpRequestBase request)
 {
     return(request.GetOwinContext().GetSignInManager());
 }
Example #15
0
 public static ApplicationRoleManager GetRolesManager(this HttpRequestBase request)
 {
     return(request.GetOwinContext().GetRolesManager());
 }
Example #16
0
        public static RouteNames GetRouteNames(this HttpRequestBase request)
        {
            IOwinContext context = request.GetOwinContext();

            return(context.Environment.ContainsKey("RouteNames") ? context.Get <RouteNames>("RouteNames") : new RouteNames());
        }
Example #17
0
        public IAuthenticationManager GetAuthManager(HttpRequestBase request)
        {
            var context = request.GetOwinContext();

            return(context.Authentication);
        }
Example #18
0
 public void SignOut(HttpRequestBase request, params string[] authenticationTypes)
 {
     request.GetOwinContext().Authentication.SignOut(authenticationTypes);
 }