oauth-plugin 0.4.0.pre6 → 0.4.0.pre7

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -8,3 +8,5 @@ pkg
8
8
  .swp
9
9
  .idea
10
10
  .rvmrc
11
+
12
+ Gemfile.lock
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ 0.4.0-pre7
2
+ - OAuth 1 requests using query or form encoded parameters where being interpreted as OAuth2 [pelleb]
3
+ - OAuth 2 requests were not checking for invalidated tokens. Please upgrade for this if you offer OAuth 2 [rymai]
4
+ - Handle case where credentials[:options] in consumer plugin was nil [marnen]
5
+ - Better facebook example [marnen]
1
6
  0.4.0-pre6
2
7
  - fixes issue with erb generator in rails 3 [pelleb]
3
8
  - various cleanups in generators [akonan]
data/Gemfile CHANGED
@@ -2,3 +2,26 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in oauth-plugin.gemspec
4
4
  gemspec
5
+
6
+ require 'rbconfig'
7
+
8
+ platforms :ruby do
9
+ if Config::CONFIG['target_os'] =~ /darwin/i
10
+ gem 'rb-fsevent'
11
+ gem 'growl'
12
+ end
13
+ if Config::CONFIG['target_os'] =~ /linux/i
14
+ gem 'rb-inotify', '>= 0.5.1'
15
+ gem 'libnotify', '~> 0.1.3'
16
+ end
17
+ end
18
+
19
+ platforms :jruby do
20
+ if Config::CONFIG['target_os'] =~ /darwin/i
21
+ gem 'growl'
22
+ end
23
+ if Config::CONFIG['target_os'] =~ /linux/i
24
+ gem 'rb-inotify', '>= 0.5.1'
25
+ gem 'libnotify', '~> 0.1.3'
26
+ end
27
+ end
data/Guardfile CHANGED
@@ -1,8 +1,8 @@
1
1
  # A sample Guardfile
2
2
  # More info at http://github.com/guard/guard#readme
3
3
 
4
- guard 'rspec', :version => 2 do
5
- watch('^spec/(.*)_spec.rb')
6
- watch('^lib/oauth/(.*)\.rb') { |m| "spec/#{m[1]}_spec.rb" }
7
- watch('^spec/spec_helper.rb') { "spec" }
4
+ guard 'rspec', :version => 2, :cli => '-c' do
5
+ watch(%r{^spec/(.*)_spec.rb})
6
+ watch(%r{^lib/oauth/(.+)\.rb}) { |m| "spec/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
8
  end
@@ -25,7 +25,12 @@
25
25
  # },
26
26
  # :facebook => {
27
27
  # :key => "",
28
- # :secret => ""
28
+ # :secret => "",
29
+ # :oauth_version => 2,
30
+ # :super_class => 'Oauth2Token' # unnecessary if you have an explicit "class FacebookToken < Oauth2Token",
31
+ # :options => {
32
+ # :site => "https://graph.facebook.com"
33
+ # }
29
34
  # },
30
35
  # :agree2 => {
31
36
  # :key => "",
@@ -1,5 +1,5 @@
1
1
  module Oauth
2
2
  module Plugin
3
- VERSION = "0.4.0.pre6"
3
+ VERSION = "0.4.0.pre7"
4
4
  end
5
5
  end
@@ -104,7 +104,7 @@ module OAuth
104
104
  end
105
105
 
106
106
  def current_client_application
107
- request.env["oauth.version"]==1 && env["oauth.client_application"] || current_token.try(:client_application)
107
+ request.env["oauth.version"]==1 && request.env["oauth.client_application"] || current_token.try(:client_application)
108
108
  end
109
109
 
110
110
  def oauth?
@@ -22,7 +22,8 @@ module Oauth
22
22
  end
23
23
 
24
24
  def consumer
25
- @consumer||=OAuth::Consumer.new credentials[:key],credentials[:secret],credentials[:options]
25
+ options = credentials[:options] || {}
26
+ @consumer||=OAuth::Consumer.new credentials[:key],credentials[:secret],options
26
27
  end
27
28
 
28
29
  def get_request_token(callback_url)
@@ -5,7 +5,7 @@ require "oauth/request_proxy/rack_request"
5
5
 
6
6
  module OAuth
7
7
  module Rack
8
-
8
+
9
9
  # An OAuth 1.0a filter to be used together with the oauth-plugin for rails.T
10
10
  # This is still experimental
11
11
  #
@@ -13,39 +13,36 @@ module OAuth
13
13
  #
14
14
  # require 'oauth/rack/oauth_filter'
15
15
  # config.middleware.use OAuth::Rack::OAuthFilter
16
-
17
-
18
-
16
+
19
17
  class OAuthFilter
20
18
  def initialize(app)
21
19
  @app = app
22
20
  end
23
-
24
- def call(env)
21
+
22
+ def call(env)
25
23
  request = ::Rack::Request.new(env)
26
- env["oauth_plugin"]=true
24
+ env["oauth_plugin"] = true
27
25
  strategies = []
28
26
  if token_string = oauth2_token(request)
29
- token = Oauth2Token.find_by_token(token_string) if token_string
30
- if token
31
- env["oauth.token"] = token
27
+ if token = Oauth2Token.first(:conditions => ['invalidated_at IS NULL AND authorized_at IS NOT NULL and token = ?', token_string])
28
+ env["oauth.token"] = token
32
29
  env["oauth.version"] = 2
33
30
  strategies << :oauth20_token
34
- strategies << :token
31
+ strategies << :token
35
32
  end
36
33
 
37
34
  elsif oauth1_verify(request) do |request_proxy|
38
35
  client_application = ClientApplication.find_by_key(request_proxy.consumer_key)
39
36
  env["oauth.client_application_candidate"] = client_application
40
- # Store this temporarily in client_application object for use in request token generation
41
- client_application.token_callback_url=request_proxy.oauth_callback if request_proxy.oauth_callback
42
37
 
38
+ # Store this temporarily in client_application object for use in request token generation
39
+ client_application.token_callback_url = request_proxy.oauth_callback if request_proxy.oauth_callback
43
40
  oauth_token = nil
44
-
41
+
45
42
  if request_proxy.token
46
- oauth_token = client_application.tokens.first(:conditions=>{:token => request_proxy.token})
43
+ oauth_token = client_application.tokens.first(:conditions => { :token => request_proxy.token })
47
44
  if oauth_token.respond_to?(:provided_oauth_verifier=)
48
- oauth_token.provided_oauth_verifier=request_proxy.oauth_verifier
45
+ oauth_token.provided_oauth_verifier = request_proxy.oauth_verifier
49
46
  end
50
47
  env["oauth.token_candidate"] = oauth_token
51
48
  end
@@ -75,7 +72,7 @@ module OAuth
75
72
  end
76
73
 
77
74
  def oauth1_verify(request, options = {}, &block)
78
- begin
75
+ begin
79
76
  signature = OAuth::Signature.build(request, options, &block)
80
77
  return false unless OauthNonce.remember(signature.request.nonce, signature.request.timestamp)
81
78
  value = signature.verify
@@ -86,10 +83,10 @@ module OAuth
86
83
  end
87
84
 
88
85
  def oauth2_token(request)
89
- request.params["oauth_token"] ||
86
+ (request.params["oauth_token"] && !request.params["oauth_signature"] ? request.params["oauth_token"] : nil ) ||
90
87
  request.env["HTTP_AUTHORIZATION"] &&
91
- request.env["HTTP_AUTHORIZATION"][/^(OAuth|Token) ([^\s]*)$/] && $2
88
+ request.env["HTTP_AUTHORIZATION"][/^(OAuth|Token) ([^\s]*)$/, 2]
92
89
  end
93
- end
90
+ end
94
91
  end
95
92
  end
@@ -3,14 +3,15 @@ require 'rack/test'
3
3
  require 'oauth/rack/oauth_filter'
4
4
  require 'multi_json'
5
5
  require 'forwardable'
6
+
6
7
  class OAuthEcho
7
8
  def call(env)
8
9
  response = {}
9
- response[:oauth_token] = env["oauth.token"].token if env["oauth.token"]
10
+ response[:oauth_token] = env["oauth.token"].token if env["oauth.token"]
10
11
  response[:client_application] = env["oauth.client_application"].key if env["oauth.client_application"]
11
- response[:oauth_version] = env["oauth.version"] if env["oauth.version"]
12
- response[:strategies] = env["oauth.strategies"] if env["oauth.strategies"]
13
- [200 ,{"Accept"=>"application/json"}, [MultiJson.encode(response)] ]
12
+ response[:oauth_version] = env["oauth.version"] if env["oauth.version"]
13
+ response[:strategies] = env["oauth.strategies"] if env["oauth.strategies"]
14
+ [200, { "Accept" => "application/json" }, [MultiJson.encode(response)]]
14
15
  end
15
16
  end
16
17
 
@@ -55,32 +56,122 @@ describe OAuth::Rack::OAuthFilter do
55
56
  response.should == {"client_application" => "my_consumer", "oauth_token"=>"my_token","oauth_version"=>1, "strategies"=>["oauth10_token","oauth10_request_token"]}
56
57
  end
57
58
 
58
- it "should authenticate with oauth2 auth header" do
59
- get '/',{},{"HTTP_AUTHORIZATION"=>"OAuth my_token"}
60
- last_response.should be_ok
61
- response = MultiJson.decode(last_response.body)
62
- response.should == {"oauth_token" => "my_token", "oauth_version"=>2, "strategies"=>["oauth20_token","token"]}
63
- end
59
+ describe "OAuth2" do
60
+ describe "token given through a HTTP Auth Header" do
61
+ context "authorized and non-invalidated token" do
62
+ it "authenticates" do
63
+ get '/', {}, { "HTTP_AUTHORIZATION" => "OAuth valid_token" }
64
+ last_response.should be_ok
65
+ response = MultiJson.decode(last_response.body)
66
+ response.should == { "oauth_token" => "valid_token", "oauth_version" => 2, "strategies"=> ["oauth20_token", "token"] }
67
+ end
68
+ end
69
+
70
+ context "non-authorized token" do
71
+ it "doesn't authenticate" do
72
+ get '/', {}, { "HTTP_AUTHORIZATION" => "OAuth not_authorized" }
73
+ last_response.should be_ok
74
+ response = MultiJson.decode(last_response.body)
75
+ response.should == {}
76
+ end
77
+ end
78
+
79
+ context "authorized and invalidated token" do
80
+ it "doesn't authenticate with an invalidated token" do
81
+ get '/', {}, { "HTTP_AUTHORIZATION" => "OAuth invalidated" }
82
+ last_response.should be_ok
83
+ response = MultiJson.decode(last_response.body)
84
+ response.should == {}
85
+ end
86
+ end
87
+ end
64
88
 
65
- it "should authenticate with pre draft 10 oauth2 auth header" do
66
- get '/',{},{"HTTP_AUTHORIZATION"=>"Token my_token"}
67
- last_response.should be_ok
68
- response = MultiJson.decode(last_response.body)
69
- response.should == {"oauth_token" => "my_token", "oauth_version"=>2, "strategies"=>["oauth20_token","token"]}
70
- end
89
+ describe "token given through a HTTP Auth Header following the OAuth2 pre draft" do
90
+ context "authorized and non-invalidated token" do
91
+ it "authenticates" do
92
+ get '/', {}, { "HTTP_AUTHORIZATION" => "Token valid_token" }
93
+ last_response.should be_ok
94
+ response = MultiJson.decode(last_response.body)
95
+ response.should == { "oauth_token" => "valid_token", "oauth_version" => 2, "strategies"=> ["oauth20_token", "token"] }
96
+ end
97
+ end
98
+
99
+ context "non-authorized token" do
100
+ it "doesn't authenticate" do
101
+ get '/', {}, { "HTTP_AUTHORIZATION" => "Token not_authorized" }
102
+ last_response.should be_ok
103
+ response = MultiJson.decode(last_response.body)
104
+ response.should == {}
105
+ end
106
+ end
107
+
108
+ context "authorized and invalidated token" do
109
+ it "doesn't authenticate with an invalidated token" do
110
+ get '/', {}, { "HTTP_AUTHORIZATION" => "Token invalidated" }
111
+ last_response.should be_ok
112
+ response = MultiJson.decode(last_response.body)
113
+ response.should == {}
114
+ end
115
+ end
116
+ end
71
117
 
72
- it "should authenticate with oauth2 query parameter" do
73
- get '/?oauth_token=my_token'
74
- last_response.should be_ok
75
- response = MultiJson.decode(last_response.body)
76
- response.should == {"oauth_token" => "my_token", "oauth_version"=>2, "strategies"=>["oauth20_token","token"]}
77
- end
118
+ describe "token given through a query parameter" do
119
+ context "authorized and non-invalidated token" do
120
+ it "authenticates" do
121
+ get '/?oauth_token=valid_token'
122
+ last_response.should be_ok
123
+ response = MultiJson.decode(last_response.body)
124
+ response.should == { "oauth_token" => "valid_token", "oauth_version" => 2, "strategies"=> ["oauth20_token", "token"] }
125
+ end
126
+ end
127
+
128
+ context "non-authorized token" do
129
+ it "doesn't authenticate" do
130
+ get '/?oauth_token=not_authorized'
131
+ last_response.should be_ok
132
+ response = MultiJson.decode(last_response.body)
133
+ response.should == {}
134
+ end
135
+ end
136
+
137
+ context "authorized and invalidated token" do
138
+ it "doesn't authenticate with an invalidated token" do
139
+ get '/?oauth_token=invalidated'
140
+ last_response.should be_ok
141
+ response = MultiJson.decode(last_response.body)
142
+ response.should == {}
143
+ end
144
+ end
145
+ end
78
146
 
79
- it "should authenticate with oauth2 post parameter" do
80
- post '/', :oauth_token=>'my_token'
81
- last_response.should be_ok
82
- response = MultiJson.decode(last_response.body)
83
- response.should == {"oauth_token" => "my_token", "oauth_version"=>2, "strategies"=>["oauth20_token","token"]}
147
+ describe "token given through a post parameter" do
148
+ context "authorized and non-invalidated token" do
149
+ it "authenticates" do
150
+ post '/', :oauth_token => 'valid_token'
151
+ last_response.should be_ok
152
+ response = MultiJson.decode(last_response.body)
153
+ response.should == { "oauth_token" => "valid_token", "oauth_version" => 2, "strategies"=> ["oauth20_token", "token"] }
154
+ end
155
+ end
156
+
157
+ context "non-authorized token" do
158
+ it "doesn't authenticate" do
159
+ post '/', :oauth_token => 'not_authorized'
160
+ last_response.should be_ok
161
+ response = MultiJson.decode(last_response.body)
162
+ response.should == {}
163
+ end
164
+ end
165
+
166
+ context "authorized and invalidated token" do
167
+ it "doesn't authenticate with an invalidated token" do
168
+ post '/', :oauth_token => 'invalidated'
169
+ last_response.should be_ok
170
+ response = MultiJson.decode(last_response.body)
171
+ response.should == {}
172
+ end
173
+ end
174
+ end
84
175
  end
85
176
 
86
177
 
@@ -108,8 +199,13 @@ describe OAuth::Rack::OAuthFilter do
108
199
  class OauthToken
109
200
  attr_accessor :token
110
201
 
111
- def self.find_by_token(token)
112
- OauthToken.new(token)
202
+ def self.first(conditions_hash)
203
+ case conditions_hash[:conditions].last
204
+ when "not_authorized", "invalidated"
205
+ nil
206
+ else
207
+ OauthToken.new(conditions_hash[:conditions].last)
208
+ end
113
209
  end
114
210
 
115
211
  def initialize(token)
@@ -132,5 +228,4 @@ describe OAuth::Rack::OAuthFilter do
132
228
  end
133
229
  end
134
230
 
135
-
136
231
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: oauth-plugin
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: 6
5
- version: 0.4.0.pre6
5
+ version: 0.4.0.pre7
6
6
  platform: ruby
7
7
  authors:
8
8
  - Pelle Braendgaard
@@ -145,7 +145,6 @@ files:
145
145
  - .gitignore
146
146
  - CHANGELOG
147
147
  - Gemfile
148
- - Gemfile.lock
149
148
  - Guardfile
150
149
  - MIT-LICENSE
151
150
  - README.rdoc
data/Gemfile.lock DELETED
@@ -1,66 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- oauth-plugin (0.4.0.pre5)
5
- multi_json
6
- oauth (~> 0.4.4)
7
- oauth2
8
- rack
9
-
10
- GEM
11
- remote: http://rubygems.org/
12
- specs:
13
- addressable (2.2.6)
14
- diff-lcs (1.1.2)
15
- fakeweb (1.3.0)
16
- faraday (0.6.1)
17
- addressable (~> 2.2.4)
18
- multipart-post (~> 1.1.0)
19
- rack (>= 1.1.0, < 2)
20
- fuubar (0.0.5)
21
- rspec (~> 2.0)
22
- rspec-instafail (~> 0.1.4)
23
- ruby-progressbar (~> 0.0.10)
24
- growl (1.0.3)
25
- guard (0.3.4)
26
- thor (~> 0.14.6)
27
- guard-rspec (0.3.1)
28
- guard (>= 0.2.2)
29
- multi_json (1.0.3)
30
- multi_xml (0.2.2)
31
- multipart-post (1.1.2)
32
- oauth (0.4.4)
33
- oauth2 (0.4.1)
34
- faraday (~> 0.6.1)
35
- multi_json (>= 0.0.5)
36
- opentransact (0.1.2)
37
- multi_json
38
- multi_xml
39
- oauth (~> 0.4.4)
40
- rack (1.3.0)
41
- rack-test (0.6.0)
42
- rack (>= 1.0)
43
- rspec (2.4.0)
44
- rspec-core (~> 2.4.0)
45
- rspec-expectations (~> 2.4.0)
46
- rspec-mocks (~> 2.4.0)
47
- rspec-core (2.4.0)
48
- rspec-expectations (2.4.0)
49
- diff-lcs (~> 1.1.2)
50
- rspec-instafail (0.1.7)
51
- rspec-mocks (2.4.0)
52
- ruby-progressbar (0.0.10)
53
- thor (0.14.6)
54
-
55
- PLATFORMS
56
- ruby
57
-
58
- DEPENDENCIES
59
- fakeweb
60
- fuubar
61
- growl
62
- guard-rspec
63
- oauth-plugin!
64
- opentransact
65
- rack-test
66
- rspec (~> 2.4.0)