Sha256: 7ccfa6bba88ce34509ba10706cbfd573ff55252b430a7d5eef16667182082a5f

Contents?: true

Size: 1.75 KB

Versions: 7

Compression:

Stored size: 1.75 KB

Contents

module Rails
  # Modular resource-based authentication and authorization for Rails/Rack
  module Auth
    module_function

    # 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
    #
    def authorized!(rack_env, allowed_by)
      Env.new(rack_env).tap do |env|
        env.authorize(allowed_by)
      end.to_rack
    end

    # Check whether a request has been authorized
    #
    # @param [Hash] :rack_env Rack environment
    #
    def authorized?(rack_env)
      Env.new(rack_env).authorized?
    end

    # Mark what authorized the request in the Rack environment
    #
    # @param [Hash] :env Rack environment
    # @param [String] :allowed_by what allowed this request
    def set_allowed_by(rack_env, allowed_by)
      Env.new(rack_env).tap do |env|
        env.allowed_by = allowed_by
      end.to_rack
    end

    # Read what authorized the request
    #
    # @param [Hash] :rack_env Rack environment
    #
    # @return [String, nil] what authorized the request
    def allowed_by(rack_env)
      Env.new(rack_env).allowed_by
    end

    # Obtain credentials from a Rack environment
    #
    # @param [Hash] :rack_env Rack environment
    #
    def credentials(rack_env)
      Credentials.from_rack_env(rack_env)
    end

    # 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
    #
    def add_credential(rack_env, type, credential)
      Env.new(rack_env).tap do |env|
        env.credentials[type] = credential
      end.to_rack
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rails-auth-2.1.3 lib/rails/auth/helpers.rb
rails-auth-2.1.2 lib/rails/auth/helpers.rb
rails-auth-2.1.1 lib/rails/auth/helpers.rb
rails-auth-2.1.0 lib/rails/auth/helpers.rb
rails-auth-2.0.3 lib/rails/auth/helpers.rb
rails-auth-2.0.2 lib/rails/auth/helpers.rb
rails-auth-2.0.1 lib/rails/auth/helpers.rb