oauth20 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +40 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +52 -0
- data/VERSION +1 -0
- data/lib/oauth20/access_token.rb +71 -0
- data/lib/oauth20/auth_code.rb +50 -0
- data/lib/oauth20/auth_error.rb +28 -0
- data/lib/oauth20/auth_request.rb +62 -0
- data/lib/oauth20/auth_response.rb +31 -0
- data/lib/oauth20/client.rb +29 -0
- data/lib/oauth20/storage.rb +30 -0
- data/lib/oauth20/storages/mysql_strategy.rb +22 -0
- data/lib/oauth20/storages/redis_strategy.rb +137 -0
- data/lib/oauth20/storages/strategy.rb +55 -0
- data/lib/oauth20/token_request.rb +65 -0
- data/lib/oauth20/token_response.rb +13 -0
- data/lib/oauth20/user.rb +22 -0
- data/lib/oauth20/utils.rb +12 -0
- data/lib/oauth20.rb +15 -0
- data/spec/integration/auth_request_spec.rb +29 -0
- data/spec/oauth2/access_token_spec.rb +87 -0
- data/spec/oauth2/auth_code_spec.rb +60 -0
- data/spec/oauth2/auth_request_spec.rb +84 -0
- data/spec/oauth2/auth_response_spec.rb +33 -0
- data/spec/oauth2/client_spec.rb +44 -0
- data/spec/oauth2/storage_spec.rb +15 -0
- data/spec/oauth2/storages/redis_strategy_spec.rb +174 -0
- data/spec/oauth2/token_request_spec.rb +122 -0
- data/spec/oauth2/token_response_spec.rb +22 -0
- data/spec/oauth2/user_spec.rb +5 -0
- data/spec/oauth2/utils_spec.rb +10 -0
- data/spec/oauth20_spec.rb +0 -0
- data/spec/spec_helper.rb +15 -0
- metadata +275 -0
@@ -0,0 +1,122 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OAuth2::TokenRequest do
|
4
|
+
before do
|
5
|
+
@code_data = {
|
6
|
+
:client_key => '1234',
|
7
|
+
:user_id => 1,
|
8
|
+
:created_at => Time.now,
|
9
|
+
:expires_at => Time.now + OAuth2::AuthCode::EXPIRES_IN,
|
10
|
+
:key => '1234'
|
11
|
+
}
|
12
|
+
|
13
|
+
OAuth2::TokenRequest.any_instance.stubs(:validate!).returns(true)
|
14
|
+
@request = OAuth2::TokenRequest.new('abcd', 'token', {:foo => 'bar'})
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'should store params' do
|
18
|
+
subject { @request }
|
19
|
+
|
20
|
+
its(:client_secret) { should == 'abcd' }
|
21
|
+
its(:grant_type) { should == 'token' }
|
22
|
+
its(:options) { should == {:foo => 'bar'} }
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "validate!" do
|
26
|
+
before do
|
27
|
+
OAuth2::TokenRequest.any_instance.unstub(:validate!)
|
28
|
+
OAuth2::Client.stubs(:find_by_key).returns(OAuth2::Client.new('test', {:secret => '12345'}))
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should raise invalid grant type exception" do
|
32
|
+
lambda {
|
33
|
+
OAuth2::TokenRequest.new('abcd', 'password', {}).validate!
|
34
|
+
}.should raise_exception('unsupported_grant_type')
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should raise invalid request" do
|
38
|
+
lambda {
|
39
|
+
OAuth2::TokenRequest.new('1', 'token', {}).validate!
|
40
|
+
}.should raise_exception('invalid_request')
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'invalid code token request' do
|
44
|
+
before do
|
45
|
+
OAuth2::AuthCode.stubs(:find_by_key).returns(OAuth2::AuthCode.new(@code_data))
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should raise invalid client exception' do
|
49
|
+
lambda {
|
50
|
+
OAuth2::TokenRequest.new('1', 'token', {:code => '12345', :redirect_uri => 'http://google.com'})
|
51
|
+
}.should raise_exception('invalid_grant')
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'expired code token request' do
|
56
|
+
before do
|
57
|
+
@code = OAuth2::AuthCode.new(@code_data)
|
58
|
+
@code.stubs(:expired?).returns(true)
|
59
|
+
OAuth2::AuthCode.stubs(:find_by_key).returns(@code)
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should raise invalid client exception' do
|
63
|
+
lambda {
|
64
|
+
OAuth2::TokenRequest.new('12345', 'token', {:code => '12345', :redirect_uri => 'http://google.com'})
|
65
|
+
}.should raise_exception('invalid_grant')
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'invalid client key request' do
|
70
|
+
before do
|
71
|
+
@code = OAuth2::AuthCode.new(@code_data)
|
72
|
+
OAuth2::AuthCode.stubs(:find_by_key).returns(@code)
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'should raise invalid client exception' do
|
76
|
+
lambda {
|
77
|
+
OAuth2::TokenRequest.new('1', 'token', {:code => '12345', :redirect_uri => 'http://google.com'})
|
78
|
+
}.should raise_exception('invalid_grant')
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context 'valid token request' do
|
83
|
+
before do
|
84
|
+
@code = OAuth2::AuthCode.new(@code_data)
|
85
|
+
OAuth2::AuthCode.stubs(:find_by_key).returns(@code)
|
86
|
+
|
87
|
+
@req = OAuth2::TokenRequest.new('12345', 'token', {:code => '1234', :redirect_uri => 'http://google.com'})
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'should find auth code by key' do
|
91
|
+
OAuth2::AuthCode.expects(:find_by_key).with('1234').returns(@code)
|
92
|
+
@req.validate!
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'should assign user and client' do
|
96
|
+
@req.validate!
|
97
|
+
@req.user_id.should == @code.user_id
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe "response" do
|
103
|
+
before do
|
104
|
+
#OAuth2::AuthCode.any_instance.expects(:invalidate).returns(true)
|
105
|
+
OAuth2::Storage.instance.stubs(:access_token_save).returns(true)
|
106
|
+
OAuth2::Storage.instance.stubs(:auth_code_save).returns(true)
|
107
|
+
|
108
|
+
@request.stubs(:client).returns(OAuth2::Client.new('name', {:key => '12345'}))
|
109
|
+
@request.stubs(:user_id).returns(1)
|
110
|
+
@request.stubs(:code).returns(OAuth2::AuthCode.new({}))
|
111
|
+
@code = OAuth2::AuthCode.new(@code_data)
|
112
|
+
OAuth2::AuthCode.stubs(:find_by_key).returns(@code)
|
113
|
+
@request.validate!
|
114
|
+
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
subject { @request }
|
119
|
+
|
120
|
+
its(:response) { should be_instance_of OAuth2::TokenResponse }
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OAuth2::TokenResponse do
|
4
|
+
before do
|
5
|
+
req = Object.new
|
6
|
+
req.stubs(:client).returns(OAuth2::Client.new('name', {:key => '12345'}))
|
7
|
+
req.stubs(:user_id).returns(1)
|
8
|
+
req.stubs(:code).returns(OAuth2::AuthCode.new({}))
|
9
|
+
|
10
|
+
@token = OAuth2::AccessToken.new({})
|
11
|
+
OAuth2::AccessToken.stubs(:new).returns(@token)
|
12
|
+
OAuth2::AuthCode.any_instance.stubs(:save).returns(true)
|
13
|
+
@token.stubs(:save).returns(true)
|
14
|
+
@res = OAuth2::TokenResponse.new(req)
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "to_json" do
|
18
|
+
it "should be valid" do
|
19
|
+
JSON.parse(@res.to_json).should == JSON.parse(@token.to_json)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
File without changes
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'oauth20'
|
5
|
+
require 'timecop'
|
6
|
+
require 'json'
|
7
|
+
require 'redis'
|
8
|
+
|
9
|
+
# Requires supporting files with custom matchers and macros, etc,
|
10
|
+
# in ./support/ and its subdirectories.
|
11
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
config.mock_with :mocha
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,275 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: oauth20
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 25
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Petr Janda
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-10-23 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
22
|
+
none: false
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
hash: 3
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
version_requirements: *id001
|
31
|
+
name: timecop
|
32
|
+
prerelease: false
|
33
|
+
type: :runtime
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
hash: 3
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
version: "0"
|
44
|
+
version_requirements: *id002
|
45
|
+
name: json
|
46
|
+
prerelease: false
|
47
|
+
type: :runtime
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
hash: 3
|
55
|
+
segments:
|
56
|
+
- 0
|
57
|
+
version: "0"
|
58
|
+
version_requirements: *id003
|
59
|
+
name: redis
|
60
|
+
prerelease: false
|
61
|
+
type: :runtime
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
hash: 3
|
69
|
+
segments:
|
70
|
+
- 2
|
71
|
+
- 3
|
72
|
+
- 0
|
73
|
+
version: 2.3.0
|
74
|
+
version_requirements: *id004
|
75
|
+
name: rspec
|
76
|
+
prerelease: false
|
77
|
+
type: :development
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ~>
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
hash: 23
|
85
|
+
segments:
|
86
|
+
- 1
|
87
|
+
- 0
|
88
|
+
- 0
|
89
|
+
version: 1.0.0
|
90
|
+
version_requirements: *id005
|
91
|
+
name: bundler
|
92
|
+
prerelease: false
|
93
|
+
type: :development
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ~>
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
hash: 7
|
101
|
+
segments:
|
102
|
+
- 1
|
103
|
+
- 6
|
104
|
+
- 4
|
105
|
+
version: 1.6.4
|
106
|
+
version_requirements: *id006
|
107
|
+
name: jeweler
|
108
|
+
prerelease: false
|
109
|
+
type: :development
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
112
|
+
none: false
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
hash: 3
|
117
|
+
segments:
|
118
|
+
- 0
|
119
|
+
version: "0"
|
120
|
+
version_requirements: *id007
|
121
|
+
name: rcov
|
122
|
+
prerelease: false
|
123
|
+
type: :development
|
124
|
+
- !ruby/object:Gem::Dependency
|
125
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
126
|
+
none: false
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
hash: 3
|
131
|
+
segments:
|
132
|
+
- 0
|
133
|
+
version: "0"
|
134
|
+
version_requirements: *id008
|
135
|
+
name: shoulda
|
136
|
+
prerelease: false
|
137
|
+
type: :development
|
138
|
+
- !ruby/object:Gem::Dependency
|
139
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
140
|
+
none: false
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
hash: 3
|
145
|
+
segments:
|
146
|
+
- 0
|
147
|
+
version: "0"
|
148
|
+
version_requirements: *id009
|
149
|
+
name: mocha
|
150
|
+
prerelease: false
|
151
|
+
type: :development
|
152
|
+
- !ruby/object:Gem::Dependency
|
153
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
154
|
+
none: false
|
155
|
+
requirements:
|
156
|
+
- - ">="
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
hash: 3
|
159
|
+
segments:
|
160
|
+
- 0
|
161
|
+
version: "0"
|
162
|
+
version_requirements: *id010
|
163
|
+
name: timecop
|
164
|
+
prerelease: false
|
165
|
+
type: :runtime
|
166
|
+
- !ruby/object:Gem::Dependency
|
167
|
+
requirement: &id011 !ruby/object:Gem::Requirement
|
168
|
+
none: false
|
169
|
+
requirements:
|
170
|
+
- - ">="
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
hash: 3
|
173
|
+
segments:
|
174
|
+
- 0
|
175
|
+
version: "0"
|
176
|
+
version_requirements: *id011
|
177
|
+
name: json
|
178
|
+
prerelease: false
|
179
|
+
type: :runtime
|
180
|
+
- !ruby/object:Gem::Dependency
|
181
|
+
requirement: &id012 !ruby/object:Gem::Requirement
|
182
|
+
none: false
|
183
|
+
requirements:
|
184
|
+
- - ">="
|
185
|
+
- !ruby/object:Gem::Version
|
186
|
+
hash: 3
|
187
|
+
segments:
|
188
|
+
- 0
|
189
|
+
version: "0"
|
190
|
+
version_requirements: *id012
|
191
|
+
name: redis
|
192
|
+
prerelease: false
|
193
|
+
type: :runtime
|
194
|
+
description: OAuth 2.0
|
195
|
+
email: petrjanda@me.com
|
196
|
+
executables: []
|
197
|
+
|
198
|
+
extensions: []
|
199
|
+
|
200
|
+
extra_rdoc_files:
|
201
|
+
- LICENSE.txt
|
202
|
+
- README.rdoc
|
203
|
+
files:
|
204
|
+
- .document
|
205
|
+
- .rspec
|
206
|
+
- Gemfile
|
207
|
+
- Gemfile.lock
|
208
|
+
- LICENSE.txt
|
209
|
+
- README.rdoc
|
210
|
+
- Rakefile
|
211
|
+
- VERSION
|
212
|
+
- lib/oauth20.rb
|
213
|
+
- lib/oauth20/access_token.rb
|
214
|
+
- lib/oauth20/auth_code.rb
|
215
|
+
- lib/oauth20/auth_error.rb
|
216
|
+
- lib/oauth20/auth_request.rb
|
217
|
+
- lib/oauth20/auth_response.rb
|
218
|
+
- lib/oauth20/client.rb
|
219
|
+
- lib/oauth20/storage.rb
|
220
|
+
- lib/oauth20/storages/mysql_strategy.rb
|
221
|
+
- lib/oauth20/storages/redis_strategy.rb
|
222
|
+
- lib/oauth20/storages/strategy.rb
|
223
|
+
- lib/oauth20/token_request.rb
|
224
|
+
- lib/oauth20/token_response.rb
|
225
|
+
- lib/oauth20/user.rb
|
226
|
+
- lib/oauth20/utils.rb
|
227
|
+
- spec/integration/auth_request_spec.rb
|
228
|
+
- spec/oauth2/access_token_spec.rb
|
229
|
+
- spec/oauth2/auth_code_spec.rb
|
230
|
+
- spec/oauth2/auth_request_spec.rb
|
231
|
+
- spec/oauth2/auth_response_spec.rb
|
232
|
+
- spec/oauth2/client_spec.rb
|
233
|
+
- spec/oauth2/storage_spec.rb
|
234
|
+
- spec/oauth2/storages/redis_strategy_spec.rb
|
235
|
+
- spec/oauth2/token_request_spec.rb
|
236
|
+
- spec/oauth2/token_response_spec.rb
|
237
|
+
- spec/oauth2/user_spec.rb
|
238
|
+
- spec/oauth2/utils_spec.rb
|
239
|
+
- spec/oauth20_spec.rb
|
240
|
+
- spec/spec_helper.rb
|
241
|
+
homepage: http://github.com/petrjanda/oauth20
|
242
|
+
licenses:
|
243
|
+
- MIT
|
244
|
+
post_install_message:
|
245
|
+
rdoc_options: []
|
246
|
+
|
247
|
+
require_paths:
|
248
|
+
- lib
|
249
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
250
|
+
none: false
|
251
|
+
requirements:
|
252
|
+
- - ">="
|
253
|
+
- !ruby/object:Gem::Version
|
254
|
+
hash: 3
|
255
|
+
segments:
|
256
|
+
- 0
|
257
|
+
version: "0"
|
258
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
259
|
+
none: false
|
260
|
+
requirements:
|
261
|
+
- - ">="
|
262
|
+
- !ruby/object:Gem::Version
|
263
|
+
hash: 3
|
264
|
+
segments:
|
265
|
+
- 0
|
266
|
+
version: "0"
|
267
|
+
requirements: []
|
268
|
+
|
269
|
+
rubyforge_project:
|
270
|
+
rubygems_version: 1.8.10
|
271
|
+
signing_key:
|
272
|
+
specification_version: 3
|
273
|
+
summary: OAuth 2.0
|
274
|
+
test_files: []
|
275
|
+
|