-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
50 changed files
with
1,433 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 2012 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TryNancyNginx", "TryNancyNginx\TryNancyNginx.csproj", "{F83D14AC-808C-4D0D-A6CE-45AB8DC88631}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TryOwinSelfHost", "TryOwinSelfHost\TryOwinSelfHost.csproj", "{F7E68CBE-ADE2-44E4-BDBB-ED226016C813}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Molaware.Nancy.Auth.JWT", "Molaware.Nancy.Auth.JWT\Molaware.Nancy.Auth.JWT.csproj", "{78E10B42-9DF5-4534-82E2-02D9983FAB03}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestSelfhostJwt", "TestSelfhostJwt\TestSelfhostJwt.csproj", "{C6FA3DBF-B406-4AD4-B3CE-394A5FC52DD0}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|x86 = Debug|x86 | ||
Release|x86 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{78E10B42-9DF5-4534-82E2-02D9983FAB03}.Debug|x86.ActiveCfg = Debug|Any CPU | ||
{78E10B42-9DF5-4534-82E2-02D9983FAB03}.Debug|x86.Build.0 = Debug|Any CPU | ||
{78E10B42-9DF5-4534-82E2-02D9983FAB03}.Release|x86.ActiveCfg = Release|Any CPU | ||
{78E10B42-9DF5-4534-82E2-02D9983FAB03}.Release|x86.Build.0 = Release|Any CPU | ||
{C6FA3DBF-B406-4AD4-B3CE-394A5FC52DD0}.Debug|x86.ActiveCfg = Debug|x86 | ||
{C6FA3DBF-B406-4AD4-B3CE-394A5FC52DD0}.Debug|x86.Build.0 = Debug|x86 | ||
{C6FA3DBF-B406-4AD4-B3CE-394A5FC52DD0}.Release|x86.ActiveCfg = Release|x86 | ||
{C6FA3DBF-B406-4AD4-B3CE-394A5FC52DD0}.Release|x86.Build.0 = Release|x86 | ||
{F7E68CBE-ADE2-44E4-BDBB-ED226016C813}.Debug|x86.ActiveCfg = Debug|x86 | ||
{F7E68CBE-ADE2-44E4-BDBB-ED226016C813}.Debug|x86.Build.0 = Debug|x86 | ||
{F7E68CBE-ADE2-44E4-BDBB-ED226016C813}.Release|x86.ActiveCfg = Release|x86 | ||
{F7E68CBE-ADE2-44E4-BDBB-ED226016C813}.Release|x86.Build.0 = Release|x86 | ||
{F83D14AC-808C-4D0D-A6CE-45AB8DC88631}.Debug|x86.ActiveCfg = Debug|x86 | ||
{F83D14AC-808C-4D0D-A6CE-45AB8DC88631}.Debug|x86.Build.0 = Debug|x86 | ||
{F83D14AC-808C-4D0D-A6CE-45AB8DC88631}.Release|x86.ActiveCfg = Release|x86 | ||
{F83D14AC-808C-4D0D-A6CE-45AB8DC88631}.Release|x86.Build.0 = Release|x86 | ||
EndGlobalSection | ||
EndGlobal |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Molaware.Nancy.Auth.JWT | ||
{ | ||
public class AuthOptions | ||
{ | ||
public IEnumerable<string> IgnorePaths { get; set; } | ||
public string WWWAuthenticationChallenge { get; set; } | ||
public bool PassThruUnAuthorizedRequests { get; set; } | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System; | ||
using System.Linq; | ||
using Nancy; | ||
using Nancy.Bootstrapper; | ||
using Nancy.TinyIoc; | ||
|
||
namespace Molaware.Nancy.Auth.JWT | ||
{ | ||
public class Bootstrapper : DefaultNancyBootstrapper | ||
{ | ||
|
||
protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines) | ||
{ | ||
base.ApplicationStartup(container, pipelines); | ||
|
||
|
||
if (!container.CanResolve<IAuthOptionsProvider>()) | ||
return; // if no implementation detected, no actions will be made | ||
|
||
this.RegisterDependencies(container); | ||
|
||
|
||
|
||
var auth = container.Resolve<StatelessAuth>(); | ||
|
||
auth.Enable(pipelines); | ||
} | ||
|
||
private void RegisterDependencies(TinyIoCContainer container) | ||
{ | ||
|
||
#if DEBUG | ||
var securekeyProvider = container.Resolve<ISecurekeyProvider>(); | ||
Console.WriteLine("application: " + securekeyProvider.GetType().FullName); | ||
#endif | ||
|
||
|
||
|
||
container.Register<ITokenValidator, MyJwtTokenValidor>(); // always use this one | ||
|
||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System; | ||
using Nancy; | ||
using Nancy.Bootstrapper; | ||
using Nancy.TinyIoc; | ||
|
||
namespace Molaware.Nancy.Auth.JWT | ||
{ | ||
public class CheckAuthOnStartup : IApplicationStartup | ||
{ | ||
private readonly StatelessAuth auth; | ||
|
||
public CheckAuthOnStartup(AuthOptions options) | ||
{ | ||
var validator = TinyIoCContainer.Current.Resolve<ITokenValidator>(); | ||
this.auth = new StatelessAuth(validator, options); | ||
} | ||
|
||
#region IApplicationStartup implementation | ||
|
||
public void Initialize(IPipelines pipelines) | ||
{ | ||
this.auth.Enable(pipelines); | ||
} | ||
|
||
#endregion | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
|
||
namespace Molaware.Nancy.Auth.JWT | ||
{ | ||
class DefaultSecurekeyProvider : ISecurekeyProvider | ||
{ | ||
#region ISecurekeyProvider implementation | ||
|
||
public string GetSecurekey() | ||
{ | ||
return System.Configuration.ConfigurationManager.AppSettings["securekey"] ?? "Molaware0x10"; | ||
} | ||
|
||
|
||
#endregion | ||
|
||
|
||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
using Nancy.Security; | ||
|
||
namespace Molaware.Nancy.Auth.JWT | ||
{ | ||
class DefaultTokenUserMapper : ITokenUserMapper | ||
{ | ||
#region ITokenUserMapper implementation | ||
public IUserIdentity Convert(JwtToken token) | ||
{ | ||
return new DefaultUserIdentity { | ||
UserName = token.UserName, | ||
Claims = token.Claims | ||
}; | ||
} | ||
#endregion | ||
|
||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Nancy.Security; | ||
|
||
namespace Molaware.Nancy.Auth.JWT | ||
{ | ||
public class DefaultUserIdentity : IUserIdentity | ||
{ | ||
public string UserName { get; set; } | ||
|
||
public IEnumerable<string> Claims { get; set; } | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System; | ||
|
||
namespace Molaware.Nancy.Auth.JWT | ||
{ | ||
public interface IAuthOptionsProvider | ||
{ | ||
AuthOptions Configure(); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System; | ||
|
||
namespace Molaware.Nancy.Auth.JWT | ||
{ | ||
public interface ISecurekeyProvider | ||
{ | ||
string GetSecurekey(); | ||
|
||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System; | ||
using Nancy.Security; | ||
|
||
namespace Molaware.Nancy.Auth.JWT | ||
{ | ||
public interface ITokenUserMapper | ||
{ | ||
IUserIdentity Convert(JwtToken token); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System; | ||
using Nancy.Security; | ||
|
||
namespace Molaware.Nancy.Auth.JWT | ||
{ | ||
interface ITokenValidator | ||
{ | ||
IUserIdentity ValidateUser(string token); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
using Nancy; | ||
using Nancy.TinyIoc; | ||
|
||
namespace Molaware.Nancy.Auth.JWT | ||
{ | ||
public static class JwtAuthExtensions | ||
{ | ||
public static string JwtToken(this NancyModule module, JwtToken token, ISecurekeyProvider keyProvider) | ||
{ | ||
#if DEBUG | ||
Console.WriteLine("request: " + keyProvider.GetType().FullName); | ||
#endif | ||
|
||
var encoder = new JwtTokenEncoder(keyProvider); | ||
string encoded = encoder.Encode(token); | ||
return encoded; | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Molaware.Nancy.Auth.JWT | ||
{ | ||
public class JwtToken | ||
{ | ||
public string UserName { get; set; } | ||
|
||
public DateTime Expire { get; set; } | ||
|
||
public IEnumerable<string> Claims { get; set; } | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
using JWT; | ||
|
||
namespace Molaware.Nancy.Auth.JWT | ||
{ | ||
class JwtTokenEncoder | ||
{ | ||
private readonly ISecurekeyProvider key; | ||
|
||
public JwtTokenEncoder(ISecurekeyProvider key) | ||
{ | ||
this.key = key; | ||
} | ||
|
||
public string Encode(JwtToken token) | ||
{ | ||
return JsonWebToken.Encode(token, this.key.GetSecurekey(), JwtHashAlgorithm.HS256); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{78E10B42-9DF5-4534-82E2-02D9983FAB03}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<RootNamespace>Molaware.Nancy.Auth.JWT</RootNamespace> | ||
<AssemblyName>Molaware.Nancy.Auth.JWT</AssemblyName> | ||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug</OutputPath> | ||
<DefineConstants>DEBUG;</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<ConsolePause>false</ConsolePause> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>full</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release</OutputPath> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<ConsolePause>false</ConsolePause> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="Nancy"> | ||
<HintPath>..\packages\Nancy.1.4.3\lib\net40\Nancy.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Minimatch"> | ||
<HintPath>..\packages\Minimatch.1.1.0.0\lib\portable-net40+sl50+win+wp80\Minimatch.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.Configuration" /> | ||
<Reference Include="JWT"> | ||
<HintPath>..\packages\JWT.1.3.4\lib\3.5\JWT.dll</HintPath> | ||
</Reference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
<Compile Include="AuthOptions.cs" /> | ||
<Compile Include="ITokenValidator.cs" /> | ||
<Compile Include="StatelessAuth.cs" /> | ||
<Compile Include="Bootstrapper.cs" /> | ||
<Compile Include="IAuthOptionsProvider.cs" /> | ||
<Compile Include="ISecurekeyProvider.cs" /> | ||
<Compile Include="DefaultSecurekeyProvider.cs" /> | ||
<Compile Include="ITokenUserMapper.cs" /> | ||
<Compile Include="JwtToken.cs" /> | ||
<Compile Include="DefaultUserIdentity.cs" /> | ||
<Compile Include="DefaultTokenUserMapper.cs" /> | ||
<Compile Include="MyJwtTokenValidor.cs" /> | ||
<Compile Include="JwtTokenEncoder.cs" /> | ||
<Compile Include="JwtAuthExtensions.cs" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> | ||
<ItemGroup> | ||
<None Include="packages.config" /> | ||
<None Include="readme.md" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
|
||
namespace Molaware.Nancy.Auth.JWT | ||
{ | ||
public class MyClass | ||
{ | ||
public MyClass() | ||
{ | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.