/// <summary>
        /// Saves the Auth Tokens for this request. Called in OnAuthenticated(). 
        /// Overrideable, the default behaviour is to call IUserAuthRepository.CreateOrMergeAuthSession().
        /// </summary>
        protected virtual void SaveUserAuth(IServiceBase authService, IAuthSession session, IUserAuthRepository authRepo, IOAuthTokens tokens)
        {
            if (authRepo == null) return;
            if (tokens != null)
            {
                session.UserAuthId = authRepo.CreateOrMergeAuthSession(session, tokens);
            }

            authRepo.LoadUserAuth(session, tokens);

            foreach (var oAuthToken in session.ProviderOAuthAccess)
            {
                var authProvider = AuthService.GetAuthProvider(oAuthToken.Provider);
                if (authProvider == null) continue;
                var userAuthProvider = authProvider as OAuthProvider;
                if (userAuthProvider != null)
                {
                    userAuthProvider.LoadUserOAuthProvider(session, oAuthToken);
                }
            }

            authRepo.SaveUserAuth(session);

            var httpRes = authService.RequestContext.Get<IHttpResponse>();
            if (httpRes != null)
            {
                httpRes.Cookies.AddPermanentCookie(HttpHeaders.XUserAuthId, session.UserAuthId);
            }
            OnSaveUserAuth(authService, session);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Saves the Auth Tokens for this request. Called in OnAuthenticated().
        /// Overrideable, the default behaviour is to call IUserAuthRepository.CreateOrMergeAuthSession().
        /// </summary>
        protected virtual void SaveUserAuth(IServiceBase authService, IAuthSession session, IUserAuthRepository authRepo, IOAuthTokens tokens)
        {
            if (authRepo == null)
            {
                return;
            }
            if (tokens != null)
            {
                session.UserAuthId = authRepo.CreateOrMergeAuthSession(session, tokens);
            }

            authRepo.LoadUserAuth(session, tokens);

            foreach (var oAuthToken in session.ProviderOAuthAccess)
            {
                var authProvider = AuthService.GetAuthProvider(oAuthToken.Provider);
                if (authProvider == null)
                {
                    continue;
                }
            }

            authRepo.SaveUserAuth(session);

            var httpRes = authService.RequestContext.Get <IHttpResponse>();

            if (httpRes != null)
            {
                httpRes.Cookies.AddPermanentCookie(HttpHeaders.XUserAuthId, session.UserAuthId);
            }
            OnSaveUserAuth(authService, session);
        }
Ejemplo n.º 3
0
        public static void RecordSuccessfulLogin(this IUserAuthRepository repo, IUserAuth userAuth)
        {
            var feature = HostContext.GetPlugin <AuthFeature>();

            if (feature == null || feature.MaxLoginAttempts == null)
            {
                return;
            }

            userAuth.InvalidLoginAttempts = 0;
            userAuth.LastLoginAttempt     = userAuth.ModifiedDate = DateTime.UtcNow;
            repo.SaveUserAuth(userAuth);
        }
Ejemplo n.º 4
0
        public static void RecordInvalidLoginAttempt(this IUserAuthRepository repo, IUserAuth userAuth)
        {
            var feature = HostContext.GetPlugin <AuthFeature>();

            if (feature == null || feature.MaxLoginAttempts == null)
            {
                return;
            }

            userAuth.InvalidLoginAttempts += 1;
            userAuth.LastLoginAttempt      = userAuth.ModifiedDate = DateTime.UtcNow;
            if (userAuth.InvalidLoginAttempts >= feature.MaxLoginAttempts.Value)
            {
                userAuth.LockedDate = userAuth.LastLoginAttempt;
            }
            repo.SaveUserAuth(userAuth);
        }
Ejemplo n.º 5
0
        public static void RecordSuccessfulLogin(this IUserAuthRepository repo, IUserAuth userAuth, bool rehashPassword, string password)
        {
            var feature = HostContext.GetPlugin <AuthFeature>();

            if (feature?.MaxLoginAttempts == null)
            {
                return;
            }

            userAuth.InvalidLoginAttempts = 0;
            userAuth.LastLoginAttempt     = userAuth.ModifiedDate = DateTime.UtcNow;

            if (rehashPassword)
            {
                userAuth.PopulatePasswordHashes(password);
            }

            repo.SaveUserAuth(userAuth);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Saves the Auth Tokens for this request. Called in OnAuthenticated(). 
        /// Overrideable, the default behaviour is to call IUserAuthRepository.CreateOrMergeAuthSession().
        /// </summary>
        protected virtual void SaveUserAuth(IServiceBase authService, IAuthSession session, IUserAuthRepository authRepo, IOAuthTokens tokens)
        {
            if (authRepo == null) return;
            if (tokens != null)
            {
                session.UserAuthId = authRepo.CreateOrMergeAuthSession(session, tokens);
            }

            authRepo.LoadUserAuth(session, tokens);

            foreach (var oAuthToken in session.ProviderOAuthAccess)
            {
                var authProvider = AuthService.GetAuthProvider(oAuthToken.Provider);
                if (authProvider == null) continue;
                authProvider.LoadUserOAuthProvider(session, oAuthToken);
            }

            authRepo.SaveUserAuth(session);
        }