/// <summary> /// Logs the user out and returns either an empty 200 response for ajax requests, or a redirect response for non-ajax. <seealso cref="M:Nancy.Extensions.RequestExtensions.IsAjaxRequest(Nancy.Request)" /> /// </summary> /// <param name="module">Nancy module</param> /// <param name="redirectUrl">URL to redirect to</param> /// <returns>Nancy response with redirect if request was not ajax, otherwise with OK.</returns> public static Response Logout(this INancyModule module, string redirectUrl) { if (!module.Context.Request.IsAjaxRequest()) { return(CustomAuthenticationProvider.LogOutAndRedirectResponse(module.Context, redirectUrl)); } return(CustomAuthenticationProvider.LogOutResponse()); }
/// <summary>Enables forms authentication for the application</summary> /// <param name="pipelines">Pipelines to add handlers to (usually "this")</param> /// <param name="configuration">Forms authentication configuration</param> public static void Enable(IPipelines pipelines, CustomAuthenticationConfiguration configuration) { if (pipelines == null) { throw new ArgumentNullException("pipelines"); } if (configuration == null) { throw new ArgumentNullException("configuration"); } if (!configuration.IsValid) { throw new ArgumentException("Configuration is invalid", "configuration"); } CustomAuthenticationProvider.currentConfiguration = configuration; pipelines.BeforeRequest.AddItemToStartOfPipeline(CustomAuthenticationProvider.GetLoadAuthenticationHook(configuration)); if (configuration.DisableRedirect) { return; } pipelines.AfterRequest.AddItemToEndOfPipeline(CustomAuthenticationProvider.GetRedirectToLoginHook(configuration)); }
/// <summary>Enables forms authentication for a module</summary> /// <param name="module">Module to add handlers to (usually "this")</param> /// <param name="configuration">Forms authentication configuration</param> public static void Enable(INancyModule module, CustomAuthenticationConfiguration configuration) { if (module == null) { throw new ArgumentNullException("module"); } if (configuration == null) { throw new ArgumentNullException("configuration"); } if (!configuration.IsValid) { throw new ArgumentException("Configuration is invalid", "configuration"); } module.RequiresAuthentication(); CustomAuthenticationProvider.currentConfiguration = configuration; module.Before.AddItemToStartOfPipeline(CustomAuthenticationProvider.GetLoadAuthenticationHook(configuration)); if (configuration.DisableRedirect) { return; } module.After.AddItemToEndOfPipeline(CustomAuthenticationProvider.GetRedirectToLoginHook(configuration)); }
/// <summary>Logs the user out and redirects</summary> /// <param name="module">Nancy module</param> /// <param name="redirectUrl">URL to redirect to</param> /// <returns>Nancy response instance</returns> public static Response LogoutAndRedirect(this INancyModule module, string redirectUrl) { return(CustomAuthenticationProvider.LogOutAndRedirectResponse(module.Context, redirectUrl)); }
/// <summary> /// Logs the user in with the given user guid and returns ok response. /// </summary> /// <param name="module">Nancy module</param> /// <param name="userIdentifier">User identifier guid</param> /// <param name="cookieExpiry">Optional expiry date for the cookie (for 'Remember me')</param> /// <returns>Nancy response instance</returns> public static Response LoginWithoutRedirect(this INancyModule module, Guid userIdentifier, DateTime?cookieExpiry = null) { return(CustomAuthenticationProvider.UserLoggedInResponse(userIdentifier, cookieExpiry)); }
/// <summary> /// Logs the user in with the given user guid and redirects. /// </summary> /// <param name="module">Nancy module</param> /// <param name="userIdentifier">User identifier guid</param> /// <param name="cookieExpiry">Optional expiry date for the cookie (for 'Remember me')</param> /// <param name="fallbackRedirectUrl">Url to redirect to if none in the querystring</param> /// <returns>Nancy response instance</returns> public static Response LoginAndRedirect(this INancyModule module, Guid userIdentifier, DateTime?cookieExpiry = null, string fallbackRedirectUrl = "/") { return(CustomAuthenticationProvider.UserLoggedInRedirectResponse(module.Context, userIdentifier, cookieExpiry, fallbackRedirectUrl)); }
/// <summary>Logs the user out without a redirect</summary> /// <param name="module">Nancy module</param> /// <returns>Nancy response instance</returns> public static Response LogoutWithoutRedirect(this INancyModule module) { return(CustomAuthenticationProvider.LogOutResponse()); }