Class: OmniGroupContacts::Middleware::OAuth1
- Includes:
- Authorization::OAuth1
- Defined in:
- lib/omnigroupcontacts/middleware/oauth1.rb
Constant Summary
Constants included from Authorization::OAuth1
Authorization::OAuth1::OAUTH_VERSION
Constants included from HTTPUtils
Instance Attribute Summary collapse
-
#callback_path ⇒ Object
(also: #redirect_path)
readonly
Returns the value of attribute callback_path.
-
#consumer_key ⇒ Object
readonly
Returns the value of attribute consumer_key.
-
#consumer_secret ⇒ Object
readonly
Returns the value of attribute consumer_secret.
Attributes inherited from BaseOAuth
Instance Method Summary collapse
- #callback ⇒ Object
-
#fetch_contacts ⇒ Object
Parses the authorization token from the query string and obtain the relative secret from the session.
-
#initialize(app, consumer_key, consumer_secret, options = {}) ⇒ OAuth1
constructor
A new instance of OAuth1.
- #redirect_to_authorization_site(auth_token) ⇒ Object
-
#request_authorization_from_user ⇒ Object
Obtains an authorization token from the server, stores it and the session and redirect the user to the authorization website.
- #token_secret_prop_name(oauth_token) ⇒ Object
Methods included from Authorization::OAuth1
#authorization_url, #fetch_access_token, #fetch_authorization_token, #oauth_signature
Methods included from HTTPUtils
encode, host_url_from_rack_env, query_string_to_map, scheme, to_query_string
Methods inherited from BaseOAuth
Constructor Details
#initialize(app, consumer_key, consumer_secret, options = {}) ⇒ OAuth1
Returns a new instance of OAuth1.
17 18 19 20 21 22 23 |
# File 'lib/omnigroupcontacts/middleware/oauth1.rb', line 17 def initialize app, consumer_key, consumer_secret, = {} super app, @consumer_key = consumer_key @consumer_secret = consumer_secret @callback_path = [:callback_path] || "#{ MOUNT_PATH }#{class_name}/callback" @token_prop_name = "#{base_prop_name}.oauth_token" end |
Instance Attribute Details
#callback_path ⇒ Object (readonly) Also known as: redirect_path
Returns the value of attribute callback_path.
15 16 17 |
# File 'lib/omnigroupcontacts/middleware/oauth1.rb', line 15 def callback_path @callback_path end |
#consumer_key ⇒ Object (readonly)
Returns the value of attribute consumer_key.
15 16 17 |
# File 'lib/omnigroupcontacts/middleware/oauth1.rb', line 15 def consumer_key @consumer_key end |
#consumer_secret ⇒ Object (readonly)
Returns the value of attribute consumer_secret.
15 16 17 |
# File 'lib/omnigroupcontacts/middleware/oauth1.rb', line 15 def consumer_secret @consumer_secret end |
Instance Method Details
#callback ⇒ Object
25 26 27 |
# File 'lib/omnigroupcontacts/middleware/oauth1.rb', line 25 def callback host_url_from_rack_env(@env) + callback_path end |
#fetch_contacts ⇒ Object
Parses the authorization token from the query string and obtain the relative secret from the session. Finally it calls fetch_contacts_from_token_and_verifier. If token is found in the query string an AuhorizationError is raised.
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/omnigroupcontacts/middleware/oauth1.rb', line 56 def fetch_contacts params = query_string_to_map(@env["QUERY_STRING"]) oauth_token = params["oauth_token"] oauth_verifier = params["oauth_verifier"] oauth_token_secret = session[token_secret_prop_name(oauth_token)] if oauth_token && oauth_verifier && oauth_token_secret fetch_contacts_from_token_and_verifier(oauth_token, oauth_token_secret, oauth_verifier) else raise AuthorizationError.new("User did not grant access to contacts list") end end |
#redirect_to_authorization_site(auth_token) ⇒ Object
45 46 47 48 49 |
# File 'lib/omnigroupcontacts/middleware/oauth1.rb', line 45 def auth_token = (auth_token) target_url = append_state_query() [302, {"Content-Type" => "application/x-www-form-urlencoded", "location" => target_url}, []] end |
#request_authorization_from_user ⇒ Object
Obtains an authorization token from the server, stores it and the session and redirect the user to the authorization website.
34 35 36 37 38 39 |
# File 'lib/omnigroupcontacts/middleware/oauth1.rb', line 34 def (auth_token, auth_token_secret) = session[@token_prop_name] = auth_token session[token_secret_prop_name(auth_token)] = auth_token_secret (auth_token) end |
#token_secret_prop_name(oauth_token) ⇒ Object
41 42 43 |
# File 'lib/omnigroupcontacts/middleware/oauth1.rb', line 41 def token_secret_prop_name oauth_token "#{base_prop_name}.#{oauth_token}.oauth_token_secret" end |