Permalink
Browse files

make 3-legged oauth available via configuration

  • Loading branch information...
1 parent 113955a commit 18998cdb16acf01a7f5bad470ff830596f32ac08 @rossta committed Jan 16, 2013
Showing with 50 additions and 8 deletions.
  1. +15 −1 README.md
  2. +1 −1 lib/trello/authorization.rb
  3. +5 −2 lib/trello/configuration.rb
  4. +26 −0 spec/configuration_spec.rb
  5. +3 −4 spec/oauth_policy_spec.rb
View
@@ -27,7 +27,7 @@ Trello.configure do |config|
end
```
-OAuth authorization
+2-legged OAuth authorization
```ruby
Trello.configure do |config|
@@ -38,6 +38,20 @@ Trello.configure do |config|
end
```
+3-legged OAuth authorization
+
+```ruby
+Trello.configure do |config|
+ config.consumer_key = TRELLO_CONSUMER_KEY
+ config.consumer_secret = TRELLO_CONSUMER_SECRET
+ config.return_url = "http://your.site.com/path/to/receive/post"
+ config.callback = Proc.new do |request_token|
+ DB.save(request_token.key, request_token.secret)
+ redirect_to request_token.authorize_url
+ end
+end
+```
+
## Special thanks
A special thanks goes out to [Ben Biddington](https://github.com/ben-biddington) who has contributed a significant amount
@@ -130,7 +130,7 @@ def build_token
if @oauth_token
OAuthCredential.new @oauth_token, @oauth_token_secret
else
- self.class.token || OAuthCredential.new
+ self.class.token
end
end
@@ -2,6 +2,7 @@ module Trello
class Configuration
attr_accessor :developer_public_key, :member_token
attr_accessor :consumer_key, :consumer_secret, :oauth_token, :oauth_token_secret
+ attr_accessor :callback, :return_url
def initialize(attrs = {})
attrs.each { |key, value| instance_variable_set("@#{key}", value) }
@@ -33,8 +34,10 @@ def oauth_credentials
:consumer_key => consumer_key,
:consumer_secret => consumer_secret,
:oauth_token => oauth_token,
- :oauth_token_secret => oauth_token_secret
- }
+ :oauth_token_secret => oauth_token_secret,
+ :return_url => return_url,
+ :callback => callback,
+ }.delete_if { |key, value| value.nil? }
end
def basic_credentials
View
@@ -35,6 +35,17 @@
configuration.member_token.should eq('member_token')
end
+ it "has a callback (for oauth)" do
+ callback = lambda { 'foobar' }
+ configuration.callback = callback
+ configuration.callback.call.should eq('foobar')
+ end
+
+ it "has a return_url" do
+ configuration.return_url = "http://www.example.com/callback"
+ configuration.return_url.should eq("http://www.example.com/callback")
+ end
+
describe "initialize" do
it "sets key attributes provided as a hash" do
configuration = Configuration.new(
@@ -76,6 +87,21 @@
)
end
+ it 'includes callback and return url if given' do
+ configuration = Configuration.new(
+ :consumer_key => 'consumer_key',
+ :consumer_secret => 'consumer_secret',
+ :return_url => 'http://example.com',
+ :callback => 'callback'
+ )
+ configuration.credentials.should eq(
+ :consumer_key => 'consumer_key',
+ :consumer_secret => 'consumer_secret',
+ :return_url => 'http://example.com',
+ :callback => 'callback'
+ )
+ end
+
it "returns a hash of basic auth policy attributes" do
configuration = Configuration.new(
:developer_public_key => 'developer_public_key',
@@ -40,7 +40,7 @@
policy.token.secret.should eq('xxx')
end
- it "is built from given consumer_key and consumer_secret" do
+ it "is built from given oauth_token and oauth_token_secret" do
policy = OAuthPolicy.new(
:oauth_token => 'oauth_token',
:oauth_token_secret => 'oauth_token_secret'
@@ -49,10 +49,9 @@
policy.token.secret.should eq('oauth_token_secret')
end
- it "is an empty token if none supplied to class" do
+ it "is an empty token if no oauth credentials supplied" do
policy = OAuthPolicy.new
- policy.token.key.should be_nil
- policy.token.secret.should be_nil
+ policy.token.should be_nil
end
end

0 comments on commit 18998cd

Please sign in to comment.