Example #1
0
        /// <summary>
        /// Builds a cookie for logging a user out
        /// </summary>
        /// <param name="configuration">
        /// Current configuration
        /// </param>
        /// <returns>
        /// Nancy cookie instance
        /// </returns>
        private INancyCookie BuildLogoutCookie(CDP4WebServiceAuthenticationConfiguration configuration)
        {
            var cookie = new NancyCookie(
                this.cdp4AuthenticationCookieName,
                string.Empty,
                true,
                this.currentConfiguration.RequiresSsl,
                DateTime.Now.AddDays(-1));

            if (!string.IsNullOrEmpty(configuration.Domain))
            {
                cookie.Domain = configuration.Domain;
            }

            if (!string.IsNullOrEmpty(configuration.Path))
            {
                cookie.Path = configuration.Path;
            }

            return(cookie);
        }
Example #2
0
        /// <summary>
        /// Enables basic authentication for the application
        /// </summary>
        /// <param name="pipelines">
        /// Pipelines to add handlers to (usually "this")
        /// </param>
        /// <param name="configuration">
        /// Forms authentication configuration
        /// </param>
        /// <param name="basicAuthenticationPaths">
        /// The basic Authentication Paths. Each supplied path shall be preceded by a '/' character.
        /// </param>
        public void Enable(
            IPipelines pipelines,
            CDP4WebServiceAuthenticationConfiguration configuration,
            IEnumerable <string> basicAuthenticationPaths)
        {
            if (pipelines == null)
            {
                throw new ArgumentNullException("pipelines");
            }

            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            this.currentConfiguration = configuration;
            this.cookieSessionManager = new CookieSessionManager();

            pipelines.BeforeRequest.AddItemToStartOfPipeline(this.GetCredentialRetrievalHook);
            pipelines.AfterRequest.AddItemToEndOfPipeline(
                context => this.GetAuthenticationPromptHook(context, basicAuthenticationPaths));
        }