Module: AuthlogicConnect::Common::Variables

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

Instance Method Summary collapse

Methods included from State

#auth_params?, #auth_session?, #is_auth_session?

Instance Method Details

#add_session_key(key, value) ⇒ Object



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

def add_session_key(key, value)
  
end

#auth_callback_url(options = {}) ⇒ Object



28
29
30
# File 'lib/authlogic_connect/common/variables.rb', line 28

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

#auth_controllerObject



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

def auth_controller
  is_auth_session? ? controller : session_class.controller
end

#auth_paramsObject



18
19
20
21
22
23
24
25
26
# File 'lib/authlogic_connect/common/variables.rb', line 18

def auth_params
  return {} unless (auth_controller && auth_controller.params)

  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



8
9
10
11
12
13
14
15
16
# File 'lib/authlogic_connect/common/variables.rb', line 8

def auth_session
  return {} unless (auth_controller && auth_controller.session)

  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)



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

def auth_type
  from_session_or_params(:authentication_type)
end

#correct_request_class?Boolean

because user and session are so closely tied together, I am still uncertain as to how they are saved. So this makes sure if we are logging in, it must be saving the session, otherwise the user.

Returns:

  • (Boolean)


48
49
50
51
52
53
54
# File 'lib/authlogic_connect/common/variables.rb', line 48

def correct_request_class?
  if is_auth_session?
    auth_type.to_s == "session"
  else
    auth_type.to_s == "user"
  end
end

#from_session_or_params(by) ⇒ Object

auth_params and auth_session attributes are all String!



38
39
40
41
42
43
# File 'lib/authlogic_connect/common/variables.rb', line 38

def from_session_or_params(by)
  key = by.is_a?(Symbol) ? by : by.to_sym
  result = auth_params[key] if (auth_params && auth_params[key])
  result = auth_session[key] if (result.nil? || result.blank?)
  result
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



63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/authlogic_connect/common/variables.rb', line 63

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