rack-cerberus

Added by mig-hub at September 21, 2011 15:19 Star_smallStar_smallStar_smallStar_small_grayStar_small_gray
GitHub stats:
Magnifier watcher(s)
Arrow_branch fork(s)
Wrench

About

A Rack middleware for form-based authentication. Aim is a compromise between fonctionality, beauty and customization.

Usage

Cerberus

Cerberus is a Rack middleware for form-based authentication. Its purpose is only to offer a nicer (or more actual) replacement for Basic HTTP authentication.

Install with:

# sudo gem install rack-cerberus

You can use it almost the same way you use Rack::Auth::Basic:

require 'cerberus'
use Rack::Session::Cookie, :secret => 'change_me'
use Cerberus do |login, pass|
  pass=='secret'
end

Like in that example, make sure you have a session, because Cerberus use it for persistent login.

There is an optional hash you can add for customisation it. Options are:

  • :company_name
  • :fg_color (foreground color)
  • :bg_color (background color)
  • :text_color
  • :icon_url (for a company logo or any icon)
  • :css_location

Which is used that way:

use Cerberus, {:company_name => 'Nintendo'} do |login, pass|
  pass=='secret'
end

The purpose of Cerberus is to be basic, which is why there are enough options to have a page fairly customized with colors and logo (:icon_url). The logo can even replace the company name if you leave :company_name blank. But should you be fussy, this is possible to have more control using an external CSS file with the option :css_location.

Just like Rack::Auth::Basic, Cerberus yields login and pass, and delegate authentication to the block you send it which should return a boolean.

If you want to see a concrete example, go into the Cerberus directory and run:

# rackup example.ru

It's gonna start the example at http://localhost:9292

Logout

Any request to /logout on the path where the middleware is mounted will log you out. In other words, if you put the middleware at /admin, query /admin/logout to be logged out. Pretty simple.

blog comments powered by Disqus