Project

bona_fide

0.0
No commit activity in last 3 years
No release in over 3 years
Low level Rack authentication enforcement
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 1.0
 Project Readme

BonaFide

Build Status

Low level Rack authentication enforcement.

Features

BonaFide was built to bring advanced middleware functionality to all Rails apps. By providing the key functions to setup user state, limit access, and redirect others, BonaFide is a simple solution to a complex problem.

Essentially, BonaFide injects it's middleware just before Rails and it's routing are called, allowing it to read the current request's cookies, and call your designated model with the requested user state cookie. By setting user state before routing is called, BonaFide allows for more inteligent routing, as well as reduce request initialization code.

Installation

Install BonaFide gem

gem install bona_fide

Configure BonaFide settings

Create initializer in config/initializers/bona_fide.rb:

BonaFide.configure do |config|
  config.base_class = User
  config.setter = :authenticate
  config.cookie_name = "user_cookie"
end

Usage

BonaFide provides a helper for routing via BonaFide::Constraint which allows for calling methods on the configured base class. For example:

ExampleApp::Application.routes.draw do

  # routes where User.admin? is true
  constraints(BonaFide::Constraint.new(:admin?)) do
    root to: "index#admin"
  end

  # routes where User.user? is true
  constraints(BonaFide::Constraint.new(:user?)) do
    root to: "index#user"
  end

  # fallback route
  root to: "index#visitor"
end

License

BonaFide is released under the MIT License