Пример #1
0
        private void OnRequestStart(IRequest request, IResponse response, object dto)
        {
            if (dto == null)
            {
                return;
            }

            var session = request.GetSession();

            if (!session.IsAuthenticated)
            {
                return;
            }

            var authenticateDto = dto as Authenticate;

            if (authenticateDto != null && !AuthProviderCatageries.LogoutAction.EqualsIgnoreCase(authenticateDto.Provider))
            {
                var copy = SessionFeature.DefaultSessionFactory().PopulateWith(session);

                request.Items[SessionCopyRequestItemKey] = copy;

                // clear details to allow credentials to be rechecked,
                // otherwise IsAuthorized will just return, bypassing the auth provider's Authenticate method
                // fields cleared LoginMatchesSession
                session.UserAuthName = null;
                session.Email        = null;
            }
        }
Пример #2
0
        public void Register(IAppHost appHost)
        {
            var s = SessionFeature.DefaultSessionFactory() as IWebSudoAuthSession;

            if (s == null)
            {
                throw new NotSupportedException("The IUserAuth session must also implement IWebSudoAuthSession");
            }

            appHost.GlobalRequestFilters.Add(OnRequestStart);
            appHost.GlobalResponseFilters.Add(OnRequestEnd);

            var authFeature = appHost.GetPlugin <AuthFeature>();

            authFeature.AuthEvents.Add(this);

            //appHost.GetPlugin<MetadataFeature>()
            //    ?.AddLink(MetadataFeature.AvailableFeatures, "http://docs.servicestack.net/swagger-api", nameof(WebSudoFeature));
        }