Ejemplo n.º 1
0
        public static Guid CreateAuthenticationControl(Guid userId, AuthOrigin origin)
        {
            var token = Guid.NewGuid();

            AuthenticationControlRepository.Get().InsertAuthControl(userId, token, origin, true);

            return(token);
        }
Ejemplo n.º 2
0
        public static void ValidateToken(AuthenticationInformationEntity authInfo)
        {
            if (authInfo != null && !String.IsNullOrEmpty(authInfo.AuthToken))
            {
                AuthenticationControlEntity authControl = AuthenticationControlRepository.Get().GetAuthControl(new Guid(authInfo.UserId), new Guid(authInfo.AuthToken));

                if (authControl == null)
                {
                    throw new ExceptionWithHttpStatus(System.Net.HttpStatusCode.Unauthorized, Messages.INVALID_AUTHORIZATION);
                }

                if (!authControl.KeepAlive && (DateTime.Now.Subtract(authControl.RegisterDate)).TotalHours > Settings.AuthenticationExpirationHours)
                {
                    AuthenticationControlRepository.Get().DeleteAuthControl(authControl.UserId, authControl.Token);
                    throw new ExceptionWithHttpStatus(System.Net.HttpStatusCode.Unauthorized, Messages.EXPIRED_AUTHORIZATION);
                }
            }
            else
            {
                throw new ExceptionWithHttpStatus(System.Net.HttpStatusCode.Unauthorized, Messages.INVALID_AUTHORIZATION);
            }
        }
Ejemplo n.º 3
0
 public static void DeleteAuthentication(string userId, string token)
 {
     AuthenticationControlRepository.Get().DeleteAuthControl(new Guid(userId), new Guid(token));
 }
Ejemplo n.º 4
0
 public static void Logout(string usuarioId)
 {
     AuthenticationControlRepository.Get().DeleteAllUserAuthControl(new Guid(usuarioId));
 }