Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Authentication engine for Ruby on Rails.
Ruby HTML

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
test
.gitignore
README.rdoc
Rakefile
janus.gemspec

README.rdoc

Janus

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.

Features

  • DatabaseAuthenticatable

  • RemoteAuthenticatable

  • Confirmable

  • Rememberable

  • Trackable

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

  • trackable hook

TODO

  • rename RemoteAuthenticatable to something like CrossDomainAuthenticatable(?)

  • remember me on remote authenticated domains.

  • confirmable resources

  • differenciate mailers per resource (automatically looking for a Users::Mailer < Janus::Mailer class?)

  • generators (janus:install, janus <resource>)

Install

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

License

Janus is distributed under the MIT-License.

Authors

Most of the API and some code like password encryption is copied from Devise: github.com/plataformatec/devise.git and Warden: github.com/hassox/warden

  • Julien Portalier <ysbaddaden@gmail.com>

Something went wrong with that request. Please try again.