/
variables.rb
executable file
·64 lines (54 loc) · 1.99 KB
/
variables.rb
1
2
3
4
5
6
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
module AuthlogicConnect::Oauth::Variables
include AuthlogicConnect::Oauth::State
# this doesn't do anything yet, just to show what variables
# we need from the form
def oauth_variables
[:oauth_provider]
end
# this comes straight from either the params or session.
# it is required for most of the other accessors in here
def oauth_provider
from_session_or_params(:oauth_provider)
end
# next is "token_class", which is found from the oauth_provider key.
# it is the OauthToken subclass, such as TwitterToken, which we
# use as the api for accessing oauth and saving the response to the database for a user.
def token_class
AuthlogicConnect.token(oauth_provider) unless oauth_provider.blank?
end
# This should go...
def oauth_response
auth_params && oauth_token
end
# the token from the response parameters
def oauth_token
return nil unless token_class
oauth_version == 1.0 ? auth_params[:oauth_token] : auth_params[:code]
end
# the version of oauth we're using. Accessed from the OauthToken subclass
def oauth_version
token_class.oauth_version
end
# the Oauth gem consumer, whereby we can make requests to the server
def oauth_consumer
token_class.consumer
end
def stored_oauth_token_and_secret
if auth_controller?
{:key => auth_params[:_key], :token => auth_params[:_token], :secret => auth_params[:_secret]}
else
{:key => nil, :token => nil, :secret => nil}
end
end
# this is a thick method.
# it gives you the final key and secret that we will store in the database
def oauth_token_and_secret
return stored_oauth_token_and_secret if stored_oauth_token_and_secret?
token_class.get_token_and_secret(
:token => auth_session[:oauth_request_token],
:secret => oauth_version == 1.0 ? auth_session[:oauth_request_token_secret] : oauth_token,
:oauth_verifier => auth_params[:oauth_verifier],
:redirect_uri => auth_callback_url
)
end
end