Module Picnic::Authentication::Basic
In: lib/picnic/authentication.rb

Picnic::Authentication::Basic provides Basic HTTP Authentication for your Camping app. The module defines a service method that only continues the request chain when proper credentials are provided by the client (browser).

Getting Started

To activate Basic Authentication for your application:

  1. Picnic-fy your Camping app (e.g: Camping.goes :your_app; YourApp.picnic!)
  2. Call YourApp.authenticate_using :basic.
  3. Define an authenticate method on your application module that takes a hash. The hash contains credentials like :username, :password, and :hostname, although future authentication modules may submit other credentials. The authenticate method should return true when the credentials are valid. Examples:
      module Blog
        def authenticate(credentials)
          credentials[:username] == 'admin' &&
            credentials[:password] == 'flapper30'
        end
        module_function :authenticate
      end
    

    or

      module Wiki
        def authenticate(credentials)
          u = credentials[:username]
          p = credentials[:password]
          Models::User.find_by_username_and_password u, p
        end
        module_function :authenticate
      end
    
  4. service sets @credentials to the credentials of the person who logged in.

This code is based on Camping::BasicAuth written by Manfred Stienstra (see www.fngtps.com/2006/05/basic-authentication-for-camping).

Methods

Public Instance methods

Reads the username and password from the headers and returns them.

[Validate]