Enables integration with Microsoft's OWIN security middeware from the Katana project. This package will allow you to easily access the IAuthenticationManager. .NET 4.5 only.
Installing the nuget package:
install-package Nancy.MSOwinSecurity
Getting the authentication manager and current user from the context:
public class MyModule : NancyModule
{
public MyModule()
{
Get["/"] = _ =>
{
IAuthenticationManager authenticationManager = Context.GetAuthenticationManager();
//ClaimsPrincipal user = authenticationManager.User;
//authenticationManager.SignIn(..);
//authenticationManager.SignOut(..);
//authenticationManager.AuthenticateAsync(..);
//authenticationManager.Challenge(..);
};
}
}
Securing a module:
public class MyModule : NancyModule
{
public MyModule()
{
this.RequiresMSOwinAuthentication();
Get["/"] = _ => {...}
}
}
Securing a route:
public class MyModule : NancyModule
{
public MyModule()
{
Get["/"] = _ =>
{
this.RequiresMSOwinAuthentication();
....
}
}
}
Getting the current user (just a helper extension around IAuthenticationManager.User):
public class MyModule : NancyModule
{
public MyModule()
{
Get["/"] = _ =>
{
ClaimsPrincipal = Context.GetMSOwinUser();
....
}
}
}
Authorizing the user at module level:
public class MyModule : NancyModule
{
public MyModule()
{
this.RequiresSecurityClaims(claims => claims.Any(
claim.ClaimType = ClaimTypes.Country &&
claim.Value.Equals("IE", StringComparision.Ordinal)));
Get["/"] = _ =>
{
....
}
}
}
Authorizing the user at route level:
public class MyModule : NancyModule
{
public MyModule()
{
Get["/"] = _ =>
{
this.RequiresSecurityClaims(claims => claims.Any(
claim.ClaimType = ClaimTypes.Country &&
claim.Value.Equals("IE", StringComparision.Ordinal)));
...
}
}
}
Personal note: this nancy extension package would integrate much better if we had extenstion properties in c# :(
MIT
Please report issues on github. Questions, criticisms, compliments or otherwise, @randompunter, or pop by the Nancy Jabbr room.