Skip to content

Commit

Permalink
Merge branch 'SaveTrees' into NancyFx#1755-FormsAuthentication
Browse files Browse the repository at this point in the history
  • Loading branch information
Worthaboutapig committed Aug 11, 2015
2 parents e21534e + 38196a4 commit 9e9af52
Show file tree
Hide file tree
Showing 282 changed files with 2,847 additions and 1,377 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ _[Rr]e[Ss]harper.*/
src/_NCrunch_Nancy/
Thumbs.db
.idea
*.GhostDoc.xml

2 changes: 1 addition & 1 deletion favicon.license.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
The Nancy logo is copyright ©2011 by Andreas Håkansson and Steven Robbings. Please consult the usage guidelines in the Nancy.Portfolio repository (https://github.com/NancyFx/Nancy.Portfolio) for information on how it may be used.
The Nancy logo is copyright ©2011 by Andreas Håkansson and Steven Robbins. Please consult the usage guidelines in the Nancy.Portfolio repository (https://github.com/NancyFx/Nancy.Portfolio) for information on how it may be used.
20 changes: 20 additions & 0 deletions src/Nancy.Authentication.Basic.Tests/BasicAuthenticationFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,26 @@ public void Should_throw_with_null_config_passed_to_enable_with_module()
result.ShouldBeOfType(typeof(ArgumentNullException));
}

[Fact]
public void Should_throw_with_null_pipeline_passed_to_enable_with_config()
{
// Given, When
var result = Record.Exception(() => BasicAuthentication.Enable((IPipelines)null, this.config));

// Then
result.ShouldBeOfType(typeof(ArgumentNullException));
}

[Fact]
public void Should_throw_with_null_module_passed_to_enable_with_config()
{
// Given, When
var result = Record.Exception(() => BasicAuthentication.Enable((INancyModule)null, this.config));

// Then
result.ShouldBeOfType(typeof(ArgumentNullException));
}

[Fact]
public void Pre_request_hook_should_not_set_auth_details_with_no_auth_headers()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\xunit.runner.visualstudio.2.0.0\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\packages\xunit.runner.visualstudio.2.0.0\build\net20\xunit.runner.visualstudio.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand Down Expand Up @@ -150,6 +151,9 @@
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
1 change: 1 addition & 0 deletions src/Nancy.Authentication.Basic.Tests/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
<package id="FakeItEasy" version="1.19.0" targetFramework="net40" />
<package id="xunit" version="1.9.1" targetFramework="net40" />
<package id="xunit.extensions" version="1.9.1" targetFramework="net40" />
<package id="xunit.runner.visualstudio" version="2.0.0" targetFramework="net40" />
</packages>
56 changes: 28 additions & 28 deletions src/Nancy.Authentication.Basic/BasicAuthenticationConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
namespace Nancy.Authentication.Basic
{
using System;

/// <summary>
/// Configuration options for forms authentication
/// </summary>
public class BasicAuthenticationConfiguration
{
/// <summary>
/// Initializes a new instance of the <see cref="BasicAuthenticationConfiguration"/> class.
/// Configuration options for forms authentication
/// </summary>
public class BasicAuthenticationConfiguration
{
/// <summary>
/// Initializes a new instance of the <see cref="BasicAuthenticationConfiguration"/> class.
/// </summary>
/// <param name="userValidator">A valid instance of <see cref="IUserValidator"/> class</param>
/// <param name="realm">Basic authentication realm</param>
/// <param name="userValidator">A valid instance of <see cref="IUserValidator"/> class</param>
/// <param name="realm">Basic authentication realm</param>
/// <param name="userPromptBehaviour">Control when the browser should be instructed to prompt for credentials</param>
public BasicAuthenticationConfiguration(IUserValidator userValidator, string realm, UserPromptBehaviour userPromptBehaviour = Basic.UserPromptBehaviour.NonAjax)
{
if (userValidator == null)
{
throw new ArgumentNullException("userValidator");
}
if (userValidator == null)
{
throw new ArgumentNullException("userValidator");
}

if (string.IsNullOrEmpty(realm))
{
throw new ArgumentException("realm");
}
if (string.IsNullOrEmpty(realm))
{
throw new ArgumentException("realm");
}

this.UserValidator = userValidator;
this.Realm = realm;
this.UserValidator = userValidator;
this.Realm = realm;
this.UserPromptBehaviour = userPromptBehaviour;
}

/// <summary>
/// Gets the user validator
/// </summary>
public IUserValidator UserValidator { get; private set; }
/// <summary>
/// Gets the user validator
/// </summary>
public IUserValidator UserValidator { get; private set; }

/// <summary>
/// Gets the basic authentication realm
/// </summary>
public string Realm { get; private set; }

/// <summary>
/// Gets the basic authentication realm
/// </summary>
public string Realm { get; private set; }

/// <summary>
/// Determines when the browser should prompt the user for credentials
/// </summary>
Expand Down
48 changes: 24 additions & 24 deletions src/Nancy.Authentication.Basic/BasicHttpExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
namespace Nancy.Authentication.Basic
{
using Nancy.Bootstrapper;

/// <summary>
/// Some simple helpers give some nice authentication syntax in the modules.
/// </summary>
public static class BasicHttpExtensions
{
/// <summary>
/// Module requires basic authentication
/// </summary>
/// <param name="module">Module to enable</param>
/// <param name="configuration">Basic authentication configuration</param>
public static void EnableBasicAuthentication(this INancyModule module, BasicAuthenticationConfiguration configuration)
{
BasicAuthentication.Enable(module, configuration);
}
/// Some simple helpers give some nice authentication syntax in the modules.
/// </summary>
public static class BasicHttpExtensions
{
/// <summary>
/// Module requires basic authentication
/// </summary>
/// <param name="module">Module to enable</param>
/// <param name="configuration">Basic authentication configuration</param>
public static void EnableBasicAuthentication(this INancyModule module, BasicAuthenticationConfiguration configuration)
{
BasicAuthentication.Enable(module, configuration);
}

/// <summary>
/// Module requires basic authentication
/// </summary>
/// <param name="pipeline">Bootstrapper to enable</param>
/// <param name="configuration">Basic authentication configuration</param>
public static void EnableBasicAuthentication(this IPipelines pipeline, BasicAuthenticationConfiguration configuration)
{
BasicAuthentication.Enable(pipeline, configuration);
}
}
/// <summary>
/// Module requires basic authentication
/// </summary>
/// <param name="pipeline">Bootstrapper to enable</param>
/// <param name="configuration">Basic authentication configuration</param>
public static void EnableBasicAuthentication(this IPipelines pipeline, BasicAuthenticationConfiguration configuration)
{
BasicAuthentication.Enable(pipeline, configuration);
}
}
}
26 changes: 13 additions & 13 deletions src/Nancy.Authentication.Basic/IUserValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ namespace Nancy.Authentication.Basic
{
using Nancy.Security;

/// <summary>
/// Provides a way to validate the username and password
/// </summary>
public interface IUserValidator
{
/// <summary>
/// Validates the username and password
/// </summary>
/// <param name="username">Username</param>
/// <param name="password">Password</param>
/// <returns>A value representing the authenticated user, null if the user was not authenticated.</returns>
IUserIdentity Validate(string username, string password);
}
/// <summary>
/// Provides a way to validate the username and password
/// </summary>
public interface IUserValidator
{
/// <summary>
/// Validates the username and password
/// </summary>
/// <param name="username">Username</param>
/// <param name="password">Password</param>
/// <returns>A value representing the authenticated user, null if the user was not authenticated.</returns>
IUserIdentity Validate(string username, string password);
}
}
2 changes: 1 addition & 1 deletion src/Nancy.Authentication.Basic/UserPromptBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public enum UserPromptBehaviour
/// Never present user with login prompt
/// </summary>
Never,

/// <summary>
/// Always present user with login prompt
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\xunit.runner.visualstudio.2.0.0\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\packages\xunit.runner.visualstudio.2.0.0\build\net20\xunit.runner.visualstudio.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand Down Expand Up @@ -206,6 +207,9 @@
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
1 change: 1 addition & 0 deletions src/Nancy.Authentication.Forms.Tests/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
<package id="FakeItEasy" version="1.19.0" targetFramework="net40" />
<package id="xunit" version="1.9.1" targetFramework="net40" />
<package id="xunit.extensions" version="1.9.1" targetFramework="net40" />
<package id="xunit.runner.visualstudio" version="2.0.0" targetFramework="net40" />
</packages>
15 changes: 8 additions & 7 deletions src/Nancy.Authentication.Forms/FormsAuthentication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ namespace Nancy.Authentication.Forms
using Helpers;
using Nancy.Extensions;
using Nancy.Security;
using Responses;

/// <summary>
/// <summary>
/// Nancy forms authentication implementation
/// </summary>
public static class FormsAuthentication
Expand Down Expand Up @@ -100,7 +101,7 @@ public static void Enable(INancyModule module, FormsAuthenticationConfiguration
currentConfiguration = configuration;

module.Before.AddItemToStartOfPipeline(GetLoadAuthenticationHook(configuration));

if (!configuration.DisableRedirect)
{
module.After.AddItemToEndOfPipeline(GetRedirectToLoginHook(configuration));
Expand All @@ -116,7 +117,7 @@ public static void Enable(INancyModule module, FormsAuthenticationConfiguration
/// <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 with redirect.</returns>
public static Response UserLoggedInRedirectResponse(NancyContext context, Guid userIdentifier, DateTime? cookieExpiry = null, string fallbackRedirectUrl = null)
public static RedirectResponse UserLoggedInRedirectResponse(NancyContext context, Guid userIdentifier, DateTime? cookieExpiry = null, string fallbackRedirectUrl = null)
{
if (currentConfiguration == null)
{
Expand Down Expand Up @@ -182,7 +183,7 @@ public static Response UserLoggedInResponse(Guid userIdentifier, DateTime? cooki
/// <param name="context">Current context</param>
/// <param name="redirectUrl">URL to redirect to</param>
/// <returns>Nancy response</returns>
public static Response LogOutAndRedirectResponse(NancyContext context, string redirectUrl)
public static RedirectResponse LogOutAndRedirectResponse(NancyContext context, string redirectUrl)
{
if (currentConfiguration == null)
{
Expand Down Expand Up @@ -277,9 +278,9 @@ private static Guid GetAuthenticatedUserFromCookie(NancyContext context, FormsAu
{
return Guid.Empty;
}

var cookieValueEncrypted = context.Request.Cookies[formsAuthenticationCookieName];

if (string.IsNullOrEmpty(cookieValueEncrypted))
{
return Guid.Empty;
Expand Down Expand Up @@ -412,7 +413,7 @@ private static string GetRedirectQuerystringKey(FormsAuthenticationConfiguration
{
redirectQuerystringKey = configuration.RedirectQuerystringKey;
}

if(string.IsNullOrWhiteSpace(redirectQuerystringKey))
{
redirectQuerystringKey = FormsAuthenticationConfiguration.DefaultRedirectQuerystringKey;
Expand Down
7 changes: 4 additions & 3 deletions src/Nancy.Authentication.Forms/ModuleExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ namespace Nancy.Authentication.Forms
{
using System;
using Extensions;
using Responses;

/// <summary>
/// <summary>
/// Module extensions for login/logout of forms auth
/// </summary>
public static class ModuleExtensions
Expand Down Expand Up @@ -31,7 +32,7 @@ public static Response Login(this INancyModule module, Guid userIdentifier, Date
/// <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 = "/")
public static RedirectResponse LoginAndRedirect(this INancyModule module, Guid userIdentifier, DateTime? cookieExpiry = null, string fallbackRedirectUrl = "/")
{
return FormsAuthentication.UserLoggedInRedirectResponse(module.Context, userIdentifier, cookieExpiry, fallbackRedirectUrl);
}
Expand Down Expand Up @@ -67,7 +68,7 @@ public static Response Logout(this INancyModule module, string redirectUrl)
/// <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)
public static RedirectResponse LogoutAndRedirect(this INancyModule module, string redirectUrl)
{
return FormsAuthentication.LogOutAndRedirectResponse(module.Context, redirectUrl);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@
<Compile Include="ModuleExtensions.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Nancy.Cryptography\Nancy.Cryptography.csproj">
<Project>{E90334A6-BDD0-403A-B734-A93457D0E8F8}</Project>
<Name>Nancy.Cryptography</Name>
</ProjectReference>
<ProjectReference Include="..\Nancy\Nancy.csproj">
<Project>{34576216-0DCA-4B0F-A0DC-9075E75A676F}</Project>
<Name>Nancy</Name>
Expand Down
4 changes: 2 additions & 2 deletions src/Nancy.Authentication.Stateless/StatelessAuthentication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Nancy.Authentication.Stateless
/// </summary>
public static class StatelessAuthentication
{
/// <summary>
/// <summary>
/// Enables stateless authentication for the application
/// </summary>
/// <param name="pipelines">Pipelines to add handlers to (usually "this")</param>
Expand All @@ -33,7 +33,7 @@ public static void Enable(IPipelines pipelines, StatelessAuthenticationConfigura
pipelines.BeforeRequest.AddItemToStartOfPipeline(GetLoadAuthenticationHook(configuration));
}

/// <summary>
/// <summary>
/// Enables stateless authentication for a module
/// </summary>
/// <param name="module">Module to add handlers to (usually "this")</param>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\xunit.runner.visualstudio.2.0.0\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\packages\xunit.runner.visualstudio.2.0.0\build\net20\xunit.runner.visualstudio.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand Down Expand Up @@ -101,6 +102,9 @@
<Name>Nancy</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
Loading

0 comments on commit 9e9af52

Please sign in to comment.