Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
A thin wrapper around the Rails `flash' object to assist in redirecting the user `back' after authentication.
Ruby
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
rails
test
LICENSE
README.rdoc
Rakefile
VERSION.yml
authentication-needed-san.gemspec

README.rdoc

AuthenticationNeededSan

A thin wrapper around the Rails ‘flash’ object, to assist in redirecting a user ‘back’ to the page she originally requested.

For more info see the AuthenticationNeededSan class documentation.

Example

Consider an application which uses the authorization-san plugin. The ApplicationController would look something like the following:

class ApplicationController < ActionController::Base
  # If nobody was logged in and this resource is not accessable by all,
  # request authentication. Otherwise reply that the resource is forbidden.
  def access_forbidden
    # If the user is logged in and still can't view the page, we have to tell
    # them access is forbidden.
    if !@authenticated.nil?
      send_response_document :forbidden
    else
      authentication_needed!
    end
  end

  def when_authentication_needed
    redirect_to new_session_url
  end
end

Then from your sessions controller redirect the user back to the page she requested or the default one:

class SessionsController < ApplicationController
  def create
    # login code...
    finish_authentication_needed! or redirect_to(root_url)
  end
end

The authorization-san plugin is available at: github.com/Fingertips/authorization-san

Something went wrong with that request. Please try again.