Module: Picnic::Authentication

Defined in:
lib/picnic/authentication.rb

Overview

These modules (currently only one module, but more in the future) provide authentication for your Camping app.

Defined Under Namespace

Modules: Basic, Cas

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/picnic/authentication.rb', line 7

def self.included(base)
  base.module_eval do
    # Enable authentication for your app.
    #
    # For example:
    #
    #   Camping.goes :Blog
    #   Blog.picnic!
    #
    #   $CONF[:authentication] ||= {:username => 'admin', :password => 'picnic'}
    #   Blog.authenticate_using :basic
    #
    #   module Blog
    #     def self.authenticate(credentials)
    #       credentials[:username] == Taskr::Conf[:authentication][:username] &&
    #         credentials[:password] == Taskr::Conf[:authentication][:password]
    #     end
    #   end
    #
    # Note that in the above example we use the authentication configuration from
    # your app's conf file.
    #
    def authenticate_using(mod)
      mod = Picnic::Authentication.const_get(mod.to_s.camelize) unless mod.kind_of? Module
      
      $LOG.info("Enabling authentication for all requests using #{mod.inspect}.")
      
      module_eval do
        include mod
      end
    end
    module_function :authenticate_using
  end
end