In theses past weeks, I’ve been playing around with NancyFx – a simple web framework a la Ruby Sinatra. So far it has been a joy to use. While I still love ASP.NET MVC, I find myself a bit more appreciative each day of the simplicity of Nancy.
One of the thing that I had set out to do was to build a simple registration module using Forms Authentication for a sample app, and to verify that the authentication worked by trying to access a secured module.
The code is quite simple. First off, I had to implement a Bootstrapper to inject my service clients and to enable Forms Authentication.
With the dependencies injected, I could build my Authentication module to handle login in and out of the system.
Now, to verify that it did indeed work, I wrote an extension class as well as a SecureModule class that validates that the user was set to the NancyContext prior to each requests .
All that is left is to implement a module that would inherit from my SecureModule, et voila!