Janus is an authentication engine for Ruby on Rails 3 and is an alternative to the Warden + Devise combo, without the Rack middleware. The whole project is inspired by the Warden and Devise API but shall eventually be quite different since everything happens within ActionDispatch and not at the Rack level.
The main difference for now is the cross domain authentication –which allows a user to single sign in and out across top level domains– which required a finer grained control over setting and unsetting a user than Warden provides. Janus uses login and logout to actually sign the user in and out, while set_user and unset_user will manually set the session, without dispatching the after_login and after_logout hooks.
Note: login through Janus::Manager#set_user won't track the user.
authentication system with strategies and hooks
scoped authentications with parallel authentication
database authentication with password encryption, validation and remember me strategy
remote authentication for cross domain sign in / sign out
controllers: sessions, registrations, confirmations, passwords and their routes
route generation for above controllers
rename RemoteAuthenticatable to something like CrossDomainAuthenticatable(?)
remember me on remote authenticated domains.
differenciate mailers per resource (automatically looking for a Users::Mailer < Janus::Mailer class?)
generators (janus:install, janus <resource>)
There is no automated way to install Janus yet, since generators are missing. Please remember that Janus is only compatible with Rails 3.
First add the gem to your Gemfile:
$ gem 'janus'
Configure your user models by including all or a selection of the Janus::Models modules:
class User < ActiveRecord::Base include Janus::Models::Base include Janus::Models::DatabaseAuthenticatable include Janus::Models::RemoteAuthenticatable include Janus::Models::Confirmable include Janus::Models::Rememberable include Janus::Models::Trackable end class Admin < ActiveRecord::Base include Janus::Models::Base include Janus::Models::DatabaseAuthenticatable include Janus::Models::RemoteAuthenticatable end
Configure your routes:
Name::Application.routes.map do janus :users, :session => true, :registration => true, :password => true, :confirmation => true janus :admins, :session => true root :to => "home#index" end
Create the required controllers:
class Users::SessionsController < Janus::SessionsController respond_to :html end class Users::RegistrationsController < Janus::RegistrationsController respond_to :html end class Users::PasswordsController < Janus::PasswordsController respond_to :html end class Users::ConfirmationsController < Janus::ConfirmationsController respond_to :html end class Admins::SessionsController < Janus::SessionsController respond_to :html end
Copy the views from test/rails_app to your application:
mkdir name/app/views/users/ cp -r janus/test/rails_app/app/views/users/sessions name/app/views/users/ cp -r janus/test/rails_app/app/views/users/registrations name/app/views/users/ cp -r janus/test/rails_app/app/views/users/confirmations name/app/views/users/ cp -r janus/test/rails_app/app/views/users/registrations name/app/views/users/ mkdir name/app/views/admins/ cp -r janus/test/rails_app/app/views/users/sessions name/app/views/users/
Have a look to the test app in test/rails_app for additional help:
app/controllers/application_controller.rb app/controller/users/confirmations_controller.rb app/controller/users/passwords_controller.rb app/controller/users/registrations_controller.rb app/controller/users/sessions_controller.rb app/mailers/janus_mailer.rb app/models/remote_token.rb app/models/user.rb app/views/janus_mailer/confirmation_instructions.html.erb app/views/janus_mailer/confirmation_instructions.text.erb app/views/janus_mailer/reset_password_instructions.html.erb app/views/janus_mailer/reset_password_instructions.text.erb app/views/users/confirmations/new.html.erb app/views/users/passwords/new.html.erb app/views/users/passwords/edit.html.erb app/views/users/registrations/new.html.erb app/views/users/registrations/edit.html.erb app/views/users/sessions/new.html.erb config/initializers/janus.rb config/locales/janus.en.yml config/routes.rb db/migrate/*.rb
Janus is distributed under the MIT-License.
Julien Portalier <email@example.com>