module Rails::Auth

Modular resource-based authentication and authorization for Rails/Rack

Modular resource-based authentication and authorization for Rails/Rack

Pluggable authentication and authorization for Rack/Rails

Constants

AlreadyAuthorizedError

Internal errors involving authorizing things that are already authorized

Error

Base class of all Rails::Auth errors

NotAuthorizedError

Unauthorized!

ParseError

Error parsing e.g. an ACL

VERSION

Public Instance Methods

add_credential(rack_env, type, credential) click to toggle source

Add a credential to the Rack environment

@param [Hash] :rack_env Rack environment @param [String] :type credential type to add to the environment @param [Object] :credential object to add to the environment

# File lib/rails/auth/helpers.rb, line 60
def add_credential(rack_env, type, credential)
  Env.new(rack_env).tap do |env|
    env.credentials[type] = credential
  end.to_rack
end
allowed_by(rack_env) click to toggle source

Read what authorized the request

@param [Hash] :rack_env Rack environment

@return [String, nil] what authorized the request

# File lib/rails/auth/helpers.rb, line 42
def allowed_by(rack_env)
  Env.new(rack_env).allowed_by
end
authorized!(rack_env, allowed_by) click to toggle source

Mark a request as externally authorized. Causes ACL checks to be skipped.

@param [Hash] :rack_env Rack environment @param [String] :allowed_by what allowed the request

# File lib/rails/auth/helpers.rb, line 13
def authorized!(rack_env, allowed_by)
  Env.new(rack_env).tap do |env|
    env.authorize(allowed_by)
  end.to_rack
end
authorized?(rack_env) click to toggle source

Check whether a request has been authorized

@param [Hash] :rack_env Rack environment

# File lib/rails/auth/helpers.rb, line 23
def authorized?(rack_env)
  Env.new(rack_env).authorized?
end
credentials(rack_env) click to toggle source

Obtain credentials from a Rack environment

@param [Hash] :rack_env Rack environment

# File lib/rails/auth/helpers.rb, line 50
def credentials(rack_env)
  Credentials.from_rack_env(rack_env)
end
set_allowed_by(rack_env, allowed_by) click to toggle source

Mark what authorized the request in the Rack environment

@param [Hash] :rack_env Rack environment @param [String] :allowed_by what allowed this request

# File lib/rails/auth/helpers.rb, line 31
def set_allowed_by(rack_env, allowed_by)
  Env.new(rack_env).tap do |env|
    env.allowed_by = allowed_by
  end.to_rack
end