Module: Roy::BasicAuth

Defined in:
lib/roy/basic_auth.rb

Overview

This module provides helpers for using the HTTP basic authentication system.

Configuration:

roy.conf.auth [:realm]

The authentication realm to use.

roy.conf.auth [:logic]

A proc that checks if an user is authorized. See #authorized? in InstanceMethods.

Examples:

Simple auth example


class AuthApp
  include Roy
  roy use: [:basic_auth],
      auth: {
        realm: "My Realm",
        logic: ->(_, u, p) { %w(admin foobar) == [u, p] }
      }

  def get(_)
    roy.protected!
    "Protected zone"
  end
end

Using user data


class AuthUserDataApp
  include Roy
  roy use: [:basic_auth],
      auth: {
        realm: "My Realm",
        logic: ->(override, u, p) {
          override || (%w(admin foobar) == [u, p])
        }
      }

  def get(path)
    roy.protected!(path =~ /private/)
    "Protected if path contains private"
  end
end

Defined Under Namespace

Modules: InstanceMethods

Class Method Summary collapse

Class Method Details

.setup(roy) ⇒ Object



45
46
47
# File 'lib/roy/basic_auth.rb', line 45

def self.setup(roy)
  roy.send(:extend, InstanceMethods)
end