Basic Authentication for Camping
This week I wrote a small web tool in Camping but when I wanted to secure it a little bit I noticed that there was no default way to do HTTP basic authentication. So I wrote some code to do just that. Actually I wrote a lot of documentation and a little bit of code.
With just some downloading and three simple steps you can add basic authentication to you application.
Download the basic_authentication.rb file.
require 'basic_authentication'- Mixin the BasicAuth module:
module Blog include Camping::BasicAuth end - Define how you want to authenticate users:
module Blog def authenticate(u, p) [u,p] == ['admin','secret'] end module_function :authenticate end
And you’re ready to start not letting people into you application. If anyone has a better idea on how and where to define the authenticate method, please drop me a line.
You can use this code under the same restrictions as the Camping framework. Now let’s just hope Why doesn’t sue me for using the Camping module (:
Update: Thijs found a bug in the header handling. The link above has been updated. I will try to give this code a home somewhere and some proper version information when I have some time.
At Fingertips we design and develop Web, iPhone, iPad and Mac OS X apps.
Find out how to hire us…




Subscribe to our mailing list — Follow us on Twitter — Grab our feed — Fork our code on GitHub