Module: AuthlogicConnect::Common::Variables

Includes:
State
Defined in:
lib/authlogic_connect/common/variables.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from State

#auth_controller?, #auth_params?, #auth_session?, #correct_request_class?, #is_auth_session?, #start_authentication?, #validate_password_with_oauth?, #validate_password_with_openid?

Instance Attribute Details

#processing_authenticationObject (readonly)

Returns the value of attribute processing_authentication.



4
5
6
# File 'lib/authlogic_connect/common/variables.rb', line 4

def processing_authentication
  @processing_authentication
end

Instance Method Details

#add_session_key(key, value) ⇒ Object



50
51
52
# File 'lib/authlogic_connect/common/variables.rb', line 50

def add_session_key(key, value)
  
end

#auth_callback_url(options = {}) ⇒ Object



32
33
34
# File 'lib/authlogic_connect/common/variables.rb', line 32

def auth_callback_url(options = {})
  auth_controller.url_for({:controller => auth_controller.controller_name, :action => auth_controller.action_name}.merge(options))
end

#auth_classObject



6
7
8
# File 'lib/authlogic_connect/common/variables.rb', line 6

def auth_class
  is_auth_session? ? self.class : session_class
end

#auth_controllerObject



10
11
12
# File 'lib/authlogic_connect/common/variables.rb', line 10

def auth_controller
  is_auth_session? ? controller : session_class.controller
end

#auth_paramsObject



14
15
16
17
18
19
20
21
# File 'lib/authlogic_connect/common/variables.rb', line 14

def auth_params
  return nil unless auth_controller?
  auth_controller.params.symbolize_keys!
  auth_controller.params.keys.each do |key|
    auth_controller.params[key.to_s] = auth_controller.params.delete(key) if key.to_s =~ /^OpenID/
  end
  auth_controller.params
end

#auth_sessionObject



23
24
25
26
27
28
29
30
# File 'lib/authlogic_connect/common/variables.rb', line 23

def auth_session
  return nil unless auth_controller?
  auth_controller.session.symbolize_keys!
  auth_controller.session.keys.each do |key|
    auth_controller.session[key.to_s] = auth_controller.session.delete(key) if key.to_s =~ /^OpenID/
  end
  auth_controller.session
end

#auth_typeObject

if we’ve said it’s a “user” (registration), or a “session” (login)



37
38
39
# File 'lib/authlogic_connect/common/variables.rb', line 37

def auth_type
  from_session_or_params(:authentication_type)
end

#authenticate_via_protocol(block_given = false, options = {}, &block) ⇒ Object

wraps the call to “save” (in yield). reason being, we need to somehow not allow oauth/openid validations to run when we don’t have a block. We can’t know that using class methods, so we create this property “processing_authentication”, which is used in the validation method. it’s value is set to “block_given”, which is the value of block_given?



64
65
66
67
68
69
# File 'lib/authlogic_connect/common/variables.rb', line 64

def authenticate_via_protocol(block_given = false, options = {}, &block)
  @processing_authentication = auth_controller? && block_given
  saved = yield start_authentication?
  @processing_authentication = false
  saved
end

#authentication_protocol(with, phase) ⇒ Object

returns boolean



72
73
74
75
76
# File 'lib/authlogic_connect/common/variables.rb', line 72

def authentication_protocol(with, phase)
  returning(send("#{phase.to_s}_#{with.to_s}?")) do |ready|
    send("#{phase.to_s}_#{with.to_s}") if ready
  end if send("using_#{with.to_s}?")
end

#auto_register?Boolean

Returns:

  • (Boolean)


120
121
122
# File 'lib/authlogic_connect/common/variables.rb', line 120

def auto_register?
  true
end

#cleanup_authentication_session(options = {}, &block) ⇒ Object

it only reaches this point once it has returned, or you have manually skipped the redirect and save was called directly.



80
81
82
83
84
85
86
# File 'lib/authlogic_connect/common/variables.rb', line 80

def cleanup_authentication_session(options = {}, &block)
  unless (options.has_key?(:keep_session) && options[:keep_session])
    %w(oauth openid).each do |type|
      send("cleanup_#{type.to_s}_session")
    end
  end
end

#from_session_or_params(attribute) ⇒ Object

auth_params and auth_session attributes are all String!



42
43
44
45
46
47
48
# File 'lib/authlogic_connect/common/variables.rb', line 42

def from_session_or_params(attribute)
  return nil unless auth_controller?
  key = attribute.is_a?(Symbol) ? attribute : attribute.to_sym
  result = auth_params[key] if (auth_params && auth_params[key])
  result = auth_session[key] if (result.nil? || result.blank?)
  result
end

#log(*methods) ⇒ Object



88
89
90
91
92
# File 'lib/authlogic_connect/common/variables.rb', line 88

def log(*methods)
  methods.each do |method|
    puts "#{method.to_s}: #{send(method).inspect}"
  end
end

#log_stateObject



94
95
96
97
98
99
100
101
# File 'lib/authlogic_connect/common/variables.rb', line 94

def log_state
  log(:correct_request_class?)
  log(:using_oauth?, :start_oauth?, :complete_oauth?)
  log(:oauth_request?, :oauth_response?, :stored_oauth_token_and_secret?)
  log(:using_openid?, :start_openid?, :complete_openid?, :openid_request?, :openid_response?)
  log(:authenticating_with_openid?)
  log(:stored_oauth_token_and_secret)
end

#optimized_session_key(key) ⇒ Object

because we may need to store 6+ session variables, all with pretty lengthy names, might as well just tinify them. just an idea



106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/authlogic_connect/common/variables.rb', line 106

def optimized_session_key(key)
  @optimized_session_keys ||= {
    :auth_request_class         => :authcl,
    :authentication_method      => :authme,
    :authentication_type        => :authty,
    :oauth_provider             => :authpr,
    :auth_callback_method       => :authcb,
    :oauth_request_token        => :authtk,
    :oauth_request_token_secret => :authsc,
    :auth_attributes            => :authat
  }
  @optimized_session_keys[key]
end

#remove_session_key(key) ⇒ Object



54
55
56
57
# File 'lib/authlogic_connect/common/variables.rb', line 54

def remove_session_key(key)
  keys = key.is_a?(Symbol) ? [key, key.to_s] : [key, key.to_sym]
  keys.each {|k| auth_session.delete(k)}
end