Skip to content

Rack Usage

Tony Arcieri edited this page Jul 16, 2016 · 13 revisions

Rails::Auth, despite the name, includes a Rack-only mode which is not dependent on Rails:

require "rails/auth/rack"

To use Rails::Auth you will need to configure the relevant AuthN and AuthZ middleware for your app.

Rails::Auth ships with the following middleware:

  • AuthN: Rails::Auth::X509::Middleware: support for authenticating clients by their SSL/TLS client certificates. Please see X.509 for more information.
  • AuthZ: Rails::Auth::ACL::Middleware: support for authorizing requests using Access Control Lists (ACLs).

ACL Middleware

Once you've defined an Access Control List, you'll need to create a corresponding ACL object in Ruby and a middleware to authorize requests using that ACL. Add the following code anywhere you can modify the middleware chain (e.g. config.ru):

app = MyRackApp.new

acl = Rails::Auth::ACL.from_yaml(
  File.read("/path/to/my/acl.yaml"),
  matchers: { allow_claims: MyClaimsMatcher }
)

acl_auth = Rails::Auth::ACL::Middleware.new(app, acl: acl)

run acl_auth

You'll need to pass in a hash of predicate matchers that correspond to the keys in the ACL.

Clone this wiki locally