Skip to content

Commit

Permalink
Add project files.
Browse files Browse the repository at this point in the history
  • Loading branch information
pinkli committed May 9, 2016
1 parent 7563c8d commit 9bd5868
Show file tree
Hide file tree
Showing 50 changed files with 1,433 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
35 changes: 35 additions & 0 deletions Molaware.Nancy.Auth.JWT.sln
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 added Molaware.Nancy.Auth.JWT/.DS_Store
Binary file not shown.
13 changes: 13 additions & 0 deletions Molaware.Nancy.Auth.JWT/AuthOptions.cs
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; }
}
}

44 changes: 44 additions & 0 deletions Molaware.Nancy.Auth.JWT/Bootstrapper.cs
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

}
}
}

28 changes: 28 additions & 0 deletions Molaware.Nancy.Auth.JWT/CheckAuthOnStartup.cs
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
}
}

20 changes: 20 additions & 0 deletions Molaware.Nancy.Auth.JWT/DefaultSecurekeyProvider.cs
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


}
}

20 changes: 20 additions & 0 deletions Molaware.Nancy.Auth.JWT/DefaultTokenUserMapper.cs
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

}
}

14 changes: 14 additions & 0 deletions Molaware.Nancy.Auth.JWT/DefaultUserIdentity.cs
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; }
}
}

10 changes: 10 additions & 0 deletions Molaware.Nancy.Auth.JWT/IAuthOptionsProvider.cs
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();
}
}

11 changes: 11 additions & 0 deletions Molaware.Nancy.Auth.JWT/ISecurekeyProvider.cs
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();

}
}

11 changes: 11 additions & 0 deletions Molaware.Nancy.Auth.JWT/ITokenUserMapper.cs
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);
}
}

11 changes: 11 additions & 0 deletions Molaware.Nancy.Auth.JWT/ITokenValidator.cs
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);
}
}

21 changes: 21 additions & 0 deletions Molaware.Nancy.Auth.JWT/JwtAuthExtensions.cs
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;
}
}
}

16 changes: 16 additions & 0 deletions Molaware.Nancy.Auth.JWT/JwtToken.cs
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; }
}
}

21 changes: 21 additions & 0 deletions Molaware.Nancy.Auth.JWT/JwtTokenEncoder.cs
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);
}
}
}

65 changes: 65 additions & 0 deletions Molaware.Nancy.Auth.JWT/Molaware.Nancy.Auth.JWT.csproj
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>
12 changes: 12 additions & 0 deletions Molaware.Nancy.Auth.JWT/MyClass.cs
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()
{
}
}
}

Loading

0 comments on commit 9bd5868

Please sign in to comment.