warden_oauth_provider 1.0.0

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.
@@ -0,0 +1,158 @@
1
+ require 'spec_helper'
2
+
3
+ describe WardenOauthProvider::TokenStrategy do
4
+
5
+ before(:all) do
6
+ @client_application = Factory.create(:client_application)
7
+ @user = Factory(:user)
8
+ end
9
+
10
+ it "should allow to authenticate a token multiple times in a session" do
11
+
12
+ class TestSession
13
+ cattr_accessor :session
14
+ def initialize(app)
15
+ @app = app
16
+ end
17
+
18
+ def call(env)
19
+ env['rack.session'] = TestSession.session
20
+ @app.call(env)
21
+ end
22
+ end
23
+ TestSession.session = {}
24
+
25
+ session = TestSession
26
+
27
+
28
+ # Step 1 - Request token
29
+ auth_str_step1 = oauth_header({
30
+ :realm => "MoneyBird",
31
+ :oauth_consumer_key => @client_application.key,
32
+ :oauth_signature_method => "PLAINTEXT",
33
+ :oauth_timestamp => Time.now.to_i+1,
34
+ :oauth_nonce => Time.now.to_f+1,
35
+ :oauth_callback => "oob",
36
+ :oauth_signature => @client_application.secret + "%26"
37
+ })
38
+ env_step1 = env_with_params("/oauth/request_token", {}, {
39
+ "HTTP_AUTHORIZATION" => auth_str_step1
40
+ })
41
+ response = setup_rack.call(env_step1)
42
+ response.first.should == 200
43
+ oauth_response = Hash[*response.last.first.split("&").collect { |v| v.split("=") }.flatten]
44
+ oauth_request_token = oauth_response["oauth_token"]
45
+ oauth_request_token_secret = oauth_response["oauth_token_secret"]
46
+
47
+ # Step 2 - Authorize
48
+ req = WardenOauthProvider::Token::Request.find_by_token(oauth_request_token)
49
+ env_step2 = env_with_params("/oauth/authorize", {:oauth_token => oauth_request_token, :username => "John"}, {})
50
+ response = setup_rack(nil, :session => session).call(env_step2)
51
+ response.first.should == 302
52
+ location = URI.parse(response[1]["Location"])
53
+ oauth_response = Hash[*location.query.split("&").collect { |v| v.split("=") }.flatten]
54
+ oauth_verifier = oauth_response["oauth_verifier"]
55
+
56
+ # Step 3 - Access token
57
+ auth_str_step3 = oauth_header({
58
+ :realm => "MoneyBird",
59
+ :oauth_consumer_key => @client_application.key,
60
+ :oauth_token => oauth_request_token,
61
+ :oauth_signature_method => "PLAINTEXT",
62
+ :oauth_timestamp => Time.now.to_i+2,
63
+ :oauth_nonce => Time.now.to_f+2,
64
+ :oauth_verifier => oauth_verifier,
65
+ :oauth_signature => @client_application.secret + "%26" + oauth_request_token_secret
66
+ })
67
+ env_step3 = env_with_params("/oauth/access_token", {}, {
68
+ "HTTP_AUTHORIZATION" => auth_str_step3
69
+ })
70
+ response = setup_rack.call(env_step3)
71
+ response.first.should == 200
72
+ oauth_response = Hash[*response.last.first.split("&").collect { |v| v.split("=") }.flatten]
73
+ oauth_access_token = oauth_response["oauth_token"]
74
+ oauth_access_token_secret = oauth_response["oauth_token_secret"]
75
+
76
+ # Step 4 - App request with access token
77
+ auth_str_step4 = oauth_header({
78
+ :realm => "MoneyBird",
79
+ :oauth_consumer_key => @client_application.key,
80
+ :oauth_token => oauth_access_token,
81
+ :oauth_signature_method => "PLAINTEXT",
82
+ :oauth_timestamp => Time.now.to_i+3,
83
+ :oauth_nonce => Time.now.to_f+3,
84
+ :oauth_signature => @client_application.secret + "%26" + oauth_access_token_secret
85
+ })
86
+ env_step4 = env_with_params("/invoices", {}, {
87
+ "HTTP_AUTHORIZATION" => auth_str_step4
88
+ })
89
+ response = setup_rack.call(env_step4)
90
+ response.first.should == 200
91
+
92
+ # Step 1 - Request token
93
+ auth_str_step1 = oauth_header({
94
+ :realm => "MoneyBird",
95
+ :oauth_consumer_key => @client_application.key,
96
+ :oauth_signature_method => "PLAINTEXT",
97
+ :oauth_timestamp => Time.now.to_i+1,
98
+ :oauth_nonce => Time.now.to_f+1,
99
+ :oauth_callback => "oob",
100
+ :oauth_signature => @client_application.secret + "%26"
101
+ })
102
+ env_step1 = env_with_params("/oauth/request_token", {}, {
103
+ "HTTP_AUTHORIZATION" => auth_str_step1
104
+ })
105
+ response = setup_rack.call(env_step1)
106
+ response.first.should == 200
107
+ oauth_response = Hash[*response.last.first.split("&").collect { |v| v.split("=") }.flatten]
108
+ oauth_request_token = oauth_response["oauth_token"]
109
+ oauth_request_token_secret = oauth_response["oauth_token_secret"]
110
+
111
+ # Step 2 - Authorize
112
+ req = WardenOauthProvider::Token::Request.find_by_token(oauth_request_token)
113
+ env_step2 = env_with_params("/oauth/authorize", {:oauth_token => oauth_request_token, :username => "John"}, {})
114
+ response = setup_rack(nil, :session => session).call(env_step2)
115
+ response.first.should == 302
116
+ location = URI.parse(response[1]["Location"])
117
+ oauth_response = Hash[*location.query.split("&").collect { |v| v.split("=") }.flatten]
118
+ oauth_verifier = oauth_response["oauth_verifier"]
119
+
120
+ # Step 3 - Access token
121
+ auth_str_step3 = oauth_header({
122
+ :realm => "MoneyBird",
123
+ :oauth_consumer_key => @client_application.key,
124
+ :oauth_token => oauth_request_token,
125
+ :oauth_signature_method => "PLAINTEXT",
126
+ :oauth_timestamp => Time.now.to_i+2,
127
+ :oauth_nonce => Time.now.to_f+2,
128
+ :oauth_verifier => oauth_verifier,
129
+ :oauth_signature => @client_application.secret + "%26" + oauth_request_token_secret
130
+ })
131
+ env_step3 = env_with_params("/oauth/access_token", {}, {
132
+ "HTTP_AUTHORIZATION" => auth_str_step3
133
+ })
134
+ response = setup_rack.call(env_step3)
135
+ response.first.should == 200
136
+ oauth_response = Hash[*response.last.first.split("&").collect { |v| v.split("=") }.flatten]
137
+ oauth_access_token = oauth_response["oauth_token"]
138
+ oauth_access_token_secret = oauth_response["oauth_token_secret"]
139
+
140
+ # Step 4 - App request with access token
141
+ auth_str_step4 = oauth_header({
142
+ :realm => "MoneyBird",
143
+ :oauth_consumer_key => @client_application.key,
144
+ :oauth_token => oauth_access_token,
145
+ :oauth_signature_method => "PLAINTEXT",
146
+ :oauth_timestamp => Time.now.to_i+3,
147
+ :oauth_nonce => Time.now.to_f+3,
148
+ :oauth_signature => @client_application.secret + "%26" + oauth_access_token_secret
149
+ })
150
+ env_step4 = env_with_params("/invoices", {}, {
151
+ "HTTP_AUTHORIZATION" => auth_str_step4
152
+ })
153
+ response = setup_rack.call(env_step4)
154
+ response.first.should == 200
155
+
156
+ end
157
+
158
+ end
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "warden_oauth_provider/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "warden_oauth_provider"
7
+ s.version = WardenOauthProvider::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Edwin Vlieg", "Berend van Bruijnsvoort"]
10
+ s.email = ["info@moneybird.nl"]
11
+ s.homepage = "http://www.moneybird.nl"
12
+ s.summary = %q{Warden strategy for OAuth provider}
13
+ s.description = %q{Warden strategy for OAuth provider}
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_dependency 'warden', '~> 1.0.0'
21
+ s.add_dependency 'oauth', '~> 0.4.0'
22
+ s.add_dependency 'activerecord', '~> 3.0.0'
23
+ s.add_development_dependency 'rspec', '~> 2.0'
24
+ s.add_development_dependency 'rake'
25
+ s.add_development_dependency 'sqlite3'
26
+ s.add_development_dependency 'factory_girl', '~> 1.3.0'
27
+ end
metadata ADDED
@@ -0,0 +1,214 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: warden_oauth_provider
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Edwin Vlieg
14
+ - Berend van Bruijnsvoort
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2011-07-29 00:00:00 +02:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: warden
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ hash: 23
31
+ segments:
32
+ - 1
33
+ - 0
34
+ - 0
35
+ version: 1.0.0
36
+ type: :runtime
37
+ version_requirements: *id001
38
+ - !ruby/object:Gem::Dependency
39
+ name: oauth
40
+ prerelease: false
41
+ requirement: &id002 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ hash: 15
47
+ segments:
48
+ - 0
49
+ - 4
50
+ - 0
51
+ version: 0.4.0
52
+ type: :runtime
53
+ version_requirements: *id002
54
+ - !ruby/object:Gem::Dependency
55
+ name: activerecord
56
+ prerelease: false
57
+ requirement: &id003 !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ hash: 7
63
+ segments:
64
+ - 3
65
+ - 0
66
+ - 0
67
+ version: 3.0.0
68
+ type: :runtime
69
+ version_requirements: *id003
70
+ - !ruby/object:Gem::Dependency
71
+ name: rspec
72
+ prerelease: false
73
+ requirement: &id004 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ hash: 3
79
+ segments:
80
+ - 2
81
+ - 0
82
+ version: "2.0"
83
+ type: :development
84
+ version_requirements: *id004
85
+ - !ruby/object:Gem::Dependency
86
+ name: rake
87
+ prerelease: false
88
+ requirement: &id005 !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ hash: 3
94
+ segments:
95
+ - 0
96
+ version: "0"
97
+ type: :development
98
+ version_requirements: *id005
99
+ - !ruby/object:Gem::Dependency
100
+ name: sqlite3
101
+ prerelease: false
102
+ requirement: &id006 !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ hash: 3
108
+ segments:
109
+ - 0
110
+ version: "0"
111
+ type: :development
112
+ version_requirements: *id006
113
+ - !ruby/object:Gem::Dependency
114
+ name: factory_girl
115
+ prerelease: false
116
+ requirement: &id007 !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ~>
120
+ - !ruby/object:Gem::Version
121
+ hash: 27
122
+ segments:
123
+ - 1
124
+ - 3
125
+ - 0
126
+ version: 1.3.0
127
+ type: :development
128
+ version_requirements: *id007
129
+ description: Warden strategy for OAuth provider
130
+ email:
131
+ - info@moneybird.nl
132
+ executables: []
133
+
134
+ extensions: []
135
+
136
+ extra_rdoc_files: []
137
+
138
+ files:
139
+ - .gitignore
140
+ - Gemfile
141
+ - LICENSE
142
+ - README.textile
143
+ - Rakefile
144
+ - lib/generators/warden_oauth_provider/install/install_generator.rb
145
+ - lib/generators/warden_oauth_provider/install/templates/migration.rb
146
+ - lib/warden_oauth_provider.rb
147
+ - lib/warden_oauth_provider/client_application.rb
148
+ - lib/warden_oauth_provider/nonce.rb
149
+ - lib/warden_oauth_provider/provider_strategy.rb
150
+ - lib/warden_oauth_provider/token/access.rb
151
+ - lib/warden_oauth_provider/token/base.rb
152
+ - lib/warden_oauth_provider/token/request.rb
153
+ - lib/warden_oauth_provider/token_strategy.rb
154
+ - lib/warden_oauth_provider/version.rb
155
+ - spec/access_token_spec.rb
156
+ - spec/all_steps_spec.rb
157
+ - spec/authorize_spec.rb
158
+ - spec/client_application_spec.rb
159
+ - spec/helpers/factories.rb
160
+ - spec/helpers/request_helper.rb
161
+ - spec/nonce_spec.rb
162
+ - spec/oauth_request_spec.rb
163
+ - spec/request_token_spec.rb
164
+ - spec/spec_helper.rb
165
+ - spec/token_spec.rb
166
+ - spec/token_strategy_spec.rb
167
+ - warden_oauth_provider.gemspec
168
+ has_rdoc: true
169
+ homepage: http://www.moneybird.nl
170
+ licenses: []
171
+
172
+ post_install_message:
173
+ rdoc_options: []
174
+
175
+ require_paths:
176
+ - lib
177
+ required_ruby_version: !ruby/object:Gem::Requirement
178
+ none: false
179
+ requirements:
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ hash: 3
183
+ segments:
184
+ - 0
185
+ version: "0"
186
+ required_rubygems_version: !ruby/object:Gem::Requirement
187
+ none: false
188
+ requirements:
189
+ - - ">="
190
+ - !ruby/object:Gem::Version
191
+ hash: 3
192
+ segments:
193
+ - 0
194
+ version: "0"
195
+ requirements: []
196
+
197
+ rubyforge_project:
198
+ rubygems_version: 1.6.2
199
+ signing_key:
200
+ specification_version: 3
201
+ summary: Warden strategy for OAuth provider
202
+ test_files:
203
+ - spec/access_token_spec.rb
204
+ - spec/all_steps_spec.rb
205
+ - spec/authorize_spec.rb
206
+ - spec/client_application_spec.rb
207
+ - spec/helpers/factories.rb
208
+ - spec/helpers/request_helper.rb
209
+ - spec/nonce_spec.rb
210
+ - spec/oauth_request_spec.rb
211
+ - spec/request_token_spec.rb
212
+ - spec/spec_helper.rb
213
+ - spec/token_spec.rb
214
+ - spec/token_strategy_spec.rb