Module: AuthlogicConnect::Oauth::Process

Includes:
Variables
Included in:
Session::InstanceMethods, User::InstanceMethods
Defined in:
lib/authlogic_connect/oauth/process.rb

Instance Method Summary collapse

Methods included from Variables

#oauth_consumer, #oauth_provider, #oauth_response, #oauth_token, #oauth_token_and_secret, #oauth_variables, #oauth_version, #stored_oauth_token_and_secret, #token_class

Methods included from State

#allow_oauth_redirect?, #authenticating_with_oauth?, #complete_oauth?, #new_oauth_request?, #oauth_complete?, #oauth_provider?, #oauth_request?, #oauth_response?, #start_oauth?, #stored_oauth_token_and_secret?, #using_oauth?, #validate_password_with_oauth?

Instance Method Details

#cleanup_oauth_sessionObject

Step last, after the response having lots of trouble testing logging and out multiple times, so there needs to be a solid way to know when a user has messed up loggin in.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/authlogic_connect/oauth/process.rb', line 60

def cleanup_oauth_session
  [:auth_request_class,
    :authentication_type,
    :auth_method,
    :auth_attributes,
    :oauth_provider,
    :auth_callback_method,
    :oauth_request_token,
    :oauth_request_token_secret,
    :_key,
    :_token,
    :_secret,
  ].each {|key| remove_session_key(key)}
end

#complete_oauthObject

Step 4: on callback, run this method



22
23
24
25
26
27
28
29
30
# File 'lib/authlogic_connect/oauth/process.rb', line 22

def complete_oauth
  # implemented in User and Session Oauth modules
  unless new_oauth_request? # shouldn't be validating if it's redirecting...
    restore_attributes
    complete_oauth_transaction
    return true
  end
  return false
end

#restore_attributesObject



54
55
# File 'lib/authlogic_connect/oauth/process.rb', line 54

def restore_attributes
end

#save_auth_session_token(request) ⇒ Object

Step 3b (if version 1.0 of oauth)



48
49
50
51
52
# File 'lib/authlogic_connect/oauth/process.rb', line 48

def save_auth_session_token(request)
  # store token and secret
  auth_session[:oauth_request_token]        = request.token
  auth_session[:oauth_request_token_secret] = request.secret
end

#save_oauth_sessionObject

Step 3a: save our passed-parameters into the session, so we can retrieve them after the redirect calls back



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/authlogic_connect/oauth/process.rb', line 34

def save_oauth_session
  # Store the class which is redirecting, so we can ensure other classes
  # don't get confused and attempt to use the response
  auth_session[:auth_request_class]         = self.class.name

  auth_session[:authentication_type]        = auth_params[:authentication_type]
  auth_session[:oauth_provider]             = auth_params[:oauth_provider]
  auth_session[:auth_method]                = "oauth"
  
  # Tell our rack callback filter what method the current request is using
  auth_session[:auth_callback_method]       = auth_controller.request.method
end

#start_oauthObject

Step 3: if new_oauth_request?, redirect to oauth provider



13
14
15
16
17
18
19
# File 'lib/authlogic_connect/oauth/process.rb', line 13

def start_oauth
  save_oauth_session
  authorize_url = token_class.authorize_url(auth_callback_url) do |request_token|
    save_auth_session_token(request_token) # only for oauth version 1
  end
  auth_controller.redirect_to authorize_url
end

#validate_by_oauthObject

Step 2: after save is called, it runs this method for validation



6
7
8
9
10
# File 'lib/authlogic_connect/oauth/process.rb', line 6

def validate_by_oauth
  if processing_authentication
    authentication_protocol(:oauth, :start) || authentication_protocol(:oauth, :complete)
  end
end