Module: Rack::Webauth::Helpers

Included in:
WardenStrategy::InstanceMethods
Defined in:
lib/rack-webauth.rb

Overview

Helpers. See Rack::Webauth for usage overview.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

ActionController support. If this is included in ActionController::Base descendants, it adds itself as a helper as well.


50
51
52
53
54
# File 'lib/rack-webauth.rb', line 50

def self.included(base)
  if defined?(ActionController) && base.kind_of?(ActionController::Base)
    base.send(:helper, self)
  end
end

Instance Method Details

#webauthObject

Helper to access the Rack::Webauth::Info object from environment. Requires either “env” or “request.env” to be available.

Example Usage:

webauth.logged_in?       #=> true
webauth.            #=> "blue"
webauth.attributes       #=> { "FOO" => ["x", "y"], "BAR" => "z" }
webauth.privgroup        #=> "cn=admins,ou=groups,dc=example,dc=com"
webauth.authrule         #=> "valid-user"
webauth.token_creation   #=> Sat Jan 29 20:47:59 +0100 2011
webauth.token_expiration #=> Sun Jan 30 06:47:59 +0100 2011

68
69
70
71
72
73
74
75
# File 'lib/rack-webauth.rb', line 68

def webauth
  (respond_to?(:env) ?
   env[NS] :
   (respond_to?(:request) &&
    request.respond_to?(:env) ?
    request.env[NS] :
    (raise Rack::Webauth::Info::NotAvailable.new("Neither 'env' nor 'request.env' available. Can't access webauth-info"))))
end