Skip to content

Commit

Permalink
Merge branch 'master' into NancyFx#1755-FormsAuthentication
Browse files Browse the repository at this point in the history
  • Loading branch information
Worthaboutapig committed Apr 30, 2015
2 parents a4b8796 + 9e8cf0b commit 3a656fc
Show file tree
Hide file tree
Showing 248 changed files with 2,149 additions and 1,133 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>
8 changes: 4 additions & 4 deletions src/Nancy.Authentication.Forms/FormsAuthentication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public static void Enable(INancyModule module, FormsAuthenticationConfiguration
currentConfiguration = configuration;

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

if (!configuration.DisableRedirect)
{
module.After.AddItemToEndOfPipeline(GetRedirectToLoginHook(configuration));
Expand Down Expand Up @@ -277,9 +277,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 +412,7 @@ private static string GetRedirectQuerystringKey(FormsAuthenticationConfiguration
{
redirectQuerystringKey = configuration.RedirectQuerystringKey;
}

if(string.IsNullOrWhiteSpace(redirectQuerystringKey))
{
redirectQuerystringKey = FormsAuthenticationConfiguration.DefaultRedirectQuerystringKey;
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
20 changes: 20 additions & 0 deletions src/Nancy.Authentication.Token.Tests/TokenAuthenticationFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,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(() => TokenAuthentication.Enable((IPipelines)null, null));

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

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

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

[Fact]
public void Pre_request_hook_should_not_set_auth_details_with_no_auth_headers()
{
Expand Down
1 change: 1 addition & 0 deletions src/Nancy.Authentication.Token.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="net45" />
<package id="xunit.extensions" version="1.9.1" targetFramework="net45" />
<package id="xunit.runner.visualstudio" version="2.0.0" targetFramework="net40" />
</packages>
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,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
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,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
1 change: 0 additions & 1 deletion src/Nancy.Demo.Authentication.Token/AuthModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public AuthModule(ITokenizer tokenizer)

Get["/admin"] = _ =>
{
this.RequiresAuthentication();
this.RequiresClaims(new[] { "admin" });
return "Yay! You are authorized!";
};
Expand Down
4 changes: 2 additions & 2 deletions src/Nancy.Demo.Caching/Views/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</head>
<body>
<h1>Nancy Caching Demo</h1>
<p><a href="/cached">Cached</a></p>
<p><a href="/uncached">Uncached</a></p>
<p><a href="/cached">Cached</a></p>
<p><a href="/uncached">Uncached</a></p>
</body>
</html>
Loading

0 comments on commit 3a656fc

Please sign in to comment.