Class: Trello::Authorization::OAuthPolicy
- Inherits:
-
Object
- Object
- Trello::Authorization::OAuthPolicy
- Defined in:
- lib/trello/authorization.rb
Overview
Handles the OAuth connectivity to Trello.
For 2-legged OAuth, do the following:
OAuthPolicy.consumer_credential = OAuthCredential.new "public_key", "secret"
OAuthPolicy.token = OAuthCredential.new "token_key", nil
For 3-legged OAuth, do the following:
OAuthPolicy.consumer_credential = OAuthCredential.new "public_key", "secret"
OAuthPolicy.return_url = "http://your.site.com/path/to/receive/post"
OAuthPolicy.callback = Proc.new do |request_token|
DB.save(request_token.key, request_token.secret)
redirect_to request_token.
end
Then, recreate the request token given the request token key and secret you saved earlier, and the consumer, and pass that RequestToken instance the #get_access_token method, and store that in OAuthPolicy.token as a OAuthCredential.
Class Attribute Summary collapse
-
.callback ⇒ Object
Returns the value of attribute callback.
-
.consumer_credential ⇒ Object
Returns the value of attribute consumer_credential.
-
.return_url ⇒ Object
Returns the value of attribute return_url.
-
.token ⇒ Object
Returns the value of attribute token.
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#callback ⇒ Object
Returns the value of attribute callback.
-
#consumer_credential ⇒ Object
Returns the value of attribute consumer_credential.
-
#return_url ⇒ Object
Returns the value of attribute return_url.
-
#token ⇒ Object
Returns the value of attribute token.
Class Method Summary collapse
Instance Method Summary collapse
- #authorize(request) ⇒ Object
- #consumer_key ⇒ Object
- #consumer_secret ⇒ Object
-
#initialize(attrs = {}) ⇒ OAuthPolicy
constructor
A new instance of OAuthPolicy.
- #oauth_token ⇒ Object
- #oauth_token_secret ⇒ Object
Constructor Details
#initialize(attrs = {}) ⇒ OAuthPolicy
Returns a new instance of OAuthPolicy.
84 85 86 87 88 89 90 91 |
# File 'lib/trello/authorization.rb', line 84 def initialize(attrs = {}) @consumer_key = attrs[:consumer_key] @consumer_secret = attrs[:consumer_secret] @oauth_token = attrs[:oauth_token] @oauth_token_secret = attrs[:oauth_token_secret] @return_url = attrs[:return_url] || self.class.return_url @callback = attrs[:callback] || self.class.callback end |
Class Attribute Details
.callback ⇒ Object
Returns the value of attribute callback.
74 75 76 |
# File 'lib/trello/authorization.rb', line 74 def callback @callback end |
.consumer_credential ⇒ Object
Returns the value of attribute consumer_credential.
74 75 76 |
# File 'lib/trello/authorization.rb', line 74 def consumer_credential @consumer_credential end |
.return_url ⇒ Object
Returns the value of attribute return_url.
74 75 76 |
# File 'lib/trello/authorization.rb', line 74 def return_url @return_url end |
.token ⇒ Object
Returns the value of attribute token.
74 75 76 |
# File 'lib/trello/authorization.rb', line 74 def token @token end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
81 82 83 |
# File 'lib/trello/authorization.rb', line 81 def attributes @attributes end |
#callback ⇒ Object
Returns the value of attribute callback.
82 83 84 |
# File 'lib/trello/authorization.rb', line 82 def callback @callback end |
#consumer_credential ⇒ Object
Returns the value of attribute consumer_credential.
82 83 84 |
# File 'lib/trello/authorization.rb', line 82 def consumer_credential @consumer_credential end |
#return_url ⇒ Object
Returns the value of attribute return_url.
82 83 84 |
# File 'lib/trello/authorization.rb', line 82 def return_url @return_url end |
#token ⇒ Object
Returns the value of attribute token.
82 83 84 |
# File 'lib/trello/authorization.rb', line 82 def token @token end |
Class Method Details
.authorize(request) ⇒ Object
76 77 78 |
# File 'lib/trello/authorization.rb', line 76 def (request) new.(request) end |
Instance Method Details
#authorize(request) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/trello/authorization.rb', line 93 def (request) unless consumer_credential Trello.logger.error "The consumer_credential has not been supplied." fail "The consumer_credential has not been supplied." end if token request.headers = {"Authorization" => get_auth_header(request.uri, :get)} request else consumer(return_url: return_url, callback_method: :postMessage) request_token = consumer.get_request_token(oauth_callback: return_url) callback.call request_token return nil end end |
#consumer_key ⇒ Object
118 119 120 |
# File 'lib/trello/authorization.rb', line 118 def consumer_key consumer_credential.key end |
#consumer_secret ⇒ Object
122 123 124 |
# File 'lib/trello/authorization.rb', line 122 def consumer_secret consumer_credential.secret end |
#oauth_token ⇒ Object
126 127 128 |
# File 'lib/trello/authorization.rb', line 126 def oauth_token token.key end |
#oauth_token_secret ⇒ Object
130 131 132 |
# File 'lib/trello/authorization.rb', line 130 def oauth_token_secret token.secret end |