opro 0.0.1 → 0.0.2
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/Gemfile +6 -2
- data/Gemfile.lock +37 -33
- data/README.md +60 -31
- data/Rakefile +8 -0
- data/VERSION +1 -1
- data/app/controllers/oauth/auth_controller.rb +35 -36
- data/app/controllers/oauth/client_app_controller.rb +24 -0
- data/app/controllers/oauth/docs_controller.rb +1 -1
- data/app/controllers/oauth/tests_controller.rb +4 -26
- data/app/controllers/oauth/token_controller.rb +40 -0
- data/app/controllers/opro_controller.rb +4 -0
- data/app/models/oauth/access_grant.rb +47 -14
- data/app/models/oauth/{client_application.rb → client_appl.rb} +1 -1
- data/app/views/oauth/{client_application → client_app}/create.html.erb +1 -1
- data/app/views/oauth/{client_application → client_app}/index.html.erb +1 -1
- data/app/views/oauth/{client_application → client_app}/new.html.erb +1 -1
- data/app/views/oauth/docs/index.html.erb +8 -0
- data/app/views/oauth/docs/markdown/oauth.md.erb +2 -2
- data/app/views/oauth/docs/markdown/permissions.md.erb +30 -0
- data/app/views/oauth/docs/markdown/quick_start.md.erb +1 -1
- data/app/views/oauth/docs/markdown/refresh_tokens.md.erb +18 -0
- data/config/routes.rb +5 -10
- data/lib/generators/active_record/opro_generator.rb +1 -1
- data/lib/generators/active_record/templates/access_grants.rb +1 -1
- data/lib/generators/active_record/templates/client_applications.rb +1 -1
- data/lib/generators/opro/install_generator.rb +5 -0
- data/lib/generators/templates/opro.rb +10 -3
- data/lib/opro.rb +7 -1
- data/lib/opro/controllers/application_controller_helper.rb +7 -2
- data/lib/opro/engine.rb +4 -0
- data/lib/opro/rails/routes.rb +17 -0
- data/opro.gemspec +27 -15
- data/test/controllers/refresh_token_test.rb +0 -0
- data/test/dummy/config/environments/test.rb +4 -0
- data/test/dummy/config/initializers/opro.rb +10 -3
- data/test/dummy/config/routes.rb +2 -0
- data/test/dummy/db/migrate/20120514060322_create_opro_access_grants.rb +1 -1
- data/test/dummy/db/migrate/20120514060323_create_opro_client_applications.rb +1 -1
- data/test/integration/action_dispatch/auth_controller_test.rb +64 -0
- data/test/integration/action_dispatch/oauth_flow_test.rb +34 -0
- data/test/integration/action_dispatch/refresh_token_test.rb +54 -0
- data/test/integration/auth_controller_test.rb +8 -7
- data/test/integration/client_app_controller_test.rb +24 -0
- data/test/integration/docs_controller_test.rb +9 -1
- data/test/integration/oauth_test.rb +1 -4
- data/test/integration/refresh_token_test.rb +32 -0
- data/test/support/integration_case.rb +10 -1
- data/test/test_helper.rb +7 -3
- metadata +56 -36
- data/app/controllers/oauth/client_application_controller.rb +0 -21
- data/app/controllers/opro_application_controller.rb +0 -8
- data/test/integration/client_application_controller_test.rb +0 -24
@@ -1,8 +1,16 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class DocsControllerTest < ActiveSupport::IntegrationCase
|
4
|
-
test 'renders' do
|
4
|
+
test 'renders index' do
|
5
5
|
visit oauth_docs_path
|
6
6
|
assert_equal '/oauth_docs', current_path
|
7
7
|
end
|
8
|
+
|
9
|
+
test 'renders show' do
|
10
|
+
[:curl, :oauth, :quick_start].each do |doc|
|
11
|
+
doc_path = oauth_doc_path(:id => doc)
|
12
|
+
visit doc_path
|
13
|
+
assert_equal doc_path, current_path
|
14
|
+
end
|
15
|
+
end
|
8
16
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class CapybaraOauthTest < ActiveSupport::IntegrationCase
|
4
4
|
|
5
5
|
test 'invalid auth_token should do nothing' do
|
6
6
|
visit '/'
|
@@ -15,7 +15,4 @@ class OauthTest < ActiveSupport::IntegrationCase
|
|
15
15
|
assert has_content?('User is logged in')
|
16
16
|
end
|
17
17
|
|
18
|
-
test 'blacklisted route should not show user logged in' do
|
19
|
-
#TODO
|
20
|
-
end
|
21
18
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CapybaraRefreshTokenTest < ActiveSupport::IntegrationCase
|
4
|
+
|
5
|
+
setup do
|
6
|
+
Timecop.freeze(Time.now)
|
7
|
+
Opro.setup do |config|
|
8
|
+
config.require_refresh_within = 1.month
|
9
|
+
end
|
10
|
+
|
11
|
+
@user = create_user
|
12
|
+
@auth_grant = create_auth_grant_for_user(@user)
|
13
|
+
@client_app = @auth_grant.application
|
14
|
+
end
|
15
|
+
|
16
|
+
teardown do
|
17
|
+
Timecop.return # "turn off" Timecop
|
18
|
+
end
|
19
|
+
|
20
|
+
test "clients with an expired token do not get logged in" do
|
21
|
+
user = create_user
|
22
|
+
auth_grant = create_auth_grant_for_user(user)
|
23
|
+
access_token = auth_grant.access_token
|
24
|
+
|
25
|
+
Timecop.travel(5.months.from_now)
|
26
|
+
visit "/?access_token=#{access_token}"
|
27
|
+
|
28
|
+
assert has_content?('NO logged in users')
|
29
|
+
assert auth_grant.expired?
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -2,4 +2,13 @@
|
|
2
2
|
class ActiveSupport::IntegrationCase < ActiveSupport::TestCase
|
3
3
|
include Capybara::DSL
|
4
4
|
include Rails.application.routes.url_helpers
|
5
|
-
|
5
|
+
|
6
|
+
teardown do
|
7
|
+
DatabaseCleaner.clean # Truncate the database
|
8
|
+
Capybara.reset_sessions! # Forget the (simulated) browser state
|
9
|
+
Capybara.use_default_driver # Revert Capybara.current_driver to Capybara.default_driver
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
end
|
14
|
+
|
data/test/test_helper.rb
CHANGED
@@ -7,6 +7,9 @@ require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
|
7
7
|
require "rails/test_help"
|
8
8
|
|
9
9
|
require 'mocha'
|
10
|
+
require 'timecop'
|
11
|
+
require 'database_cleaner'
|
12
|
+
DatabaseCleaner.strategy = :truncation
|
10
13
|
|
11
14
|
ActionMailer::Base.delivery_method = :test
|
12
15
|
ActionMailer::Base.perform_deliveries = true
|
@@ -45,7 +48,7 @@ include Warden::Test::Helpers
|
|
45
48
|
Warden.test_mode!
|
46
49
|
|
47
50
|
def rand_name
|
48
|
-
'foo' + Time.now.to_f.to_s
|
51
|
+
'foo' + Time.now.to_f.to_s + rand(10000).to_s
|
49
52
|
end
|
50
53
|
|
51
54
|
|
@@ -56,7 +59,7 @@ end
|
|
56
59
|
def create_client_app(options= {})
|
57
60
|
user = options[:user] || create_user
|
58
61
|
name = options[:name] || rand_name
|
59
|
-
Oauth::
|
62
|
+
Oauth::ClientApp.create_with_user_and_name(user, name)
|
60
63
|
end
|
61
64
|
|
62
65
|
def user_with_client_app
|
@@ -68,9 +71,10 @@ end
|
|
68
71
|
def create_auth_grant_for_user(user = nil, app = nil)
|
69
72
|
app ||= create_client_app
|
70
73
|
user ||= create_user
|
71
|
-
Oauth::
|
74
|
+
Oauth::AuthGrant.create(:user => user, :application => app)
|
72
75
|
end
|
73
76
|
|
77
|
+
|
74
78
|
# Will run the given code as the user passed in
|
75
79
|
def as_user(user=nil, &block)
|
76
80
|
current_user = user || create_user
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opro
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,33 +9,33 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-18 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
16
|
-
requirement: &
|
16
|
+
requirement: &70290860455720 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 3.0
|
21
|
+
version: 3.1.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70290860455720
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rails
|
27
|
-
requirement: &
|
27
|
+
requirement: &70290860454680 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 3.0
|
32
|
+
version: 3.1.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70290860454680
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: bluecloth
|
38
|
-
requirement: &
|
38
|
+
requirement: &70290860453740 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70290860453740
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: mocha
|
49
|
-
requirement: &
|
49
|
+
requirement: &70290860453040 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,21 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70290860453040
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: timecop
|
60
|
+
requirement: &70290860452260 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70290860452260
|
58
69
|
- !ruby/object:Gem::Dependency
|
59
70
|
name: jeweler
|
60
|
-
requirement: &
|
71
|
+
requirement: &70290860451340 !ruby/object:Gem::Requirement
|
61
72
|
none: false
|
62
73
|
requirements:
|
63
74
|
- - ~>
|
@@ -65,10 +76,10 @@ dependencies:
|
|
65
76
|
version: 1.6.4
|
66
77
|
type: :development
|
67
78
|
prerelease: false
|
68
|
-
version_requirements: *
|
79
|
+
version_requirements: *70290860451340
|
69
80
|
- !ruby/object:Gem::Dependency
|
70
81
|
name: bundler
|
71
|
-
requirement: &
|
82
|
+
requirement: &70290860450280 !ruby/object:Gem::Requirement
|
72
83
|
none: false
|
73
84
|
requirements:
|
74
85
|
- - ! '>='
|
@@ -76,10 +87,10 @@ dependencies:
|
|
76
87
|
version: 1.1.3
|
77
88
|
type: :development
|
78
89
|
prerelease: false
|
79
|
-
version_requirements: *
|
90
|
+
version_requirements: *70290860450280
|
80
91
|
- !ruby/object:Gem::Dependency
|
81
92
|
name: capybara
|
82
|
-
requirement: &
|
93
|
+
requirement: &70290860449360 !ruby/object:Gem::Requirement
|
83
94
|
none: false
|
84
95
|
requirements:
|
85
96
|
- - ! '>='
|
@@ -87,10 +98,10 @@ dependencies:
|
|
87
98
|
version: 0.4.0
|
88
99
|
type: :development
|
89
100
|
prerelease: false
|
90
|
-
version_requirements: *
|
101
|
+
version_requirements: *70290860449360
|
91
102
|
- !ruby/object:Gem::Dependency
|
92
103
|
name: sqlite3
|
93
|
-
requirement: &
|
104
|
+
requirement: &70290860448620 !ruby/object:Gem::Requirement
|
94
105
|
none: false
|
95
106
|
requirements:
|
96
107
|
- - ! '>='
|
@@ -98,10 +109,10 @@ dependencies:
|
|
98
109
|
version: '0'
|
99
110
|
type: :development
|
100
111
|
prerelease: false
|
101
|
-
version_requirements: *
|
112
|
+
version_requirements: *70290860448620
|
102
113
|
- !ruby/object:Gem::Dependency
|
103
114
|
name: launchy
|
104
|
-
requirement: &
|
115
|
+
requirement: &70290860448000 !ruby/object:Gem::Requirement
|
105
116
|
none: false
|
106
117
|
requirements:
|
107
118
|
- - ! '>='
|
@@ -109,10 +120,10 @@ dependencies:
|
|
109
120
|
version: '0'
|
110
121
|
type: :development
|
111
122
|
prerelease: false
|
112
|
-
version_requirements: *
|
123
|
+
version_requirements: *70290860448000
|
113
124
|
- !ruby/object:Gem::Dependency
|
114
125
|
name: devise
|
115
|
-
requirement: &
|
126
|
+
requirement: &70290860447380 !ruby/object:Gem::Requirement
|
116
127
|
none: false
|
117
128
|
requirements:
|
118
129
|
- - ! '>='
|
@@ -120,10 +131,10 @@ dependencies:
|
|
120
131
|
version: '0'
|
121
132
|
type: :development
|
122
133
|
prerelease: false
|
123
|
-
version_requirements: *
|
134
|
+
version_requirements: *70290860447380
|
124
135
|
- !ruby/object:Gem::Dependency
|
125
136
|
name: rcov
|
126
|
-
requirement: &
|
137
|
+
requirement: &70290860446620 !ruby/object:Gem::Requirement
|
127
138
|
none: false
|
128
139
|
requirements:
|
129
140
|
- - ! '>='
|
@@ -131,10 +142,10 @@ dependencies:
|
|
131
142
|
version: '0'
|
132
143
|
type: :development
|
133
144
|
prerelease: false
|
134
|
-
version_requirements: *
|
145
|
+
version_requirements: *70290860446620
|
135
146
|
- !ruby/object:Gem::Dependency
|
136
147
|
name: simplecov
|
137
|
-
requirement: &
|
148
|
+
requirement: &70290860446000 !ruby/object:Gem::Requirement
|
138
149
|
none: false
|
139
150
|
requirements:
|
140
151
|
- - ! '>='
|
@@ -142,7 +153,7 @@ dependencies:
|
|
142
153
|
version: '0'
|
143
154
|
type: :development
|
144
155
|
prerelease: false
|
145
|
-
version_requirements: *
|
156
|
+
version_requirements: *70290860446000
|
146
157
|
description: ! ' Enable OAuth clients (iphone, android, web sites, etc.) to access
|
147
158
|
and use your Rails application, what you do with it is up to you'
|
148
159
|
email: richard.schneeman@gmail.com
|
@@ -159,20 +170,23 @@ files:
|
|
159
170
|
- Rakefile
|
160
171
|
- VERSION
|
161
172
|
- app/controllers/oauth/auth_controller.rb
|
162
|
-
- app/controllers/oauth/
|
173
|
+
- app/controllers/oauth/client_app_controller.rb
|
163
174
|
- app/controllers/oauth/docs_controller.rb
|
164
175
|
- app/controllers/oauth/tests_controller.rb
|
165
|
-
- app/controllers/
|
176
|
+
- app/controllers/oauth/token_controller.rb
|
177
|
+
- app/controllers/opro_controller.rb
|
166
178
|
- app/models/oauth/access_grant.rb
|
167
|
-
- app/models/oauth/
|
179
|
+
- app/models/oauth/client_appl.rb
|
168
180
|
- app/views/oauth/auth/new.html.erb
|
169
|
-
- app/views/oauth/
|
170
|
-
- app/views/oauth/
|
171
|
-
- app/views/oauth/
|
181
|
+
- app/views/oauth/client_app/create.html.erb
|
182
|
+
- app/views/oauth/client_app/index.html.erb
|
183
|
+
- app/views/oauth/client_app/new.html.erb
|
172
184
|
- app/views/oauth/docs/index.html.erb
|
173
185
|
- app/views/oauth/docs/markdown/curl.md.erb
|
174
186
|
- app/views/oauth/docs/markdown/oauth.md.erb
|
187
|
+
- app/views/oauth/docs/markdown/permissions.md.erb
|
175
188
|
- app/views/oauth/docs/markdown/quick_start.md.erb
|
189
|
+
- app/views/oauth/docs/markdown/refresh_tokens.md.erb
|
176
190
|
- app/views/oauth/docs/show.html.erb
|
177
191
|
- app/views/oauth/tests/index.html.erb
|
178
192
|
- config/routes.rb
|
@@ -186,8 +200,10 @@ files:
|
|
186
200
|
- lib/opro/controllers/concerns/error_messages.rb
|
187
201
|
- lib/opro/controllers/concerns/permissions.rb
|
188
202
|
- lib/opro/engine.rb
|
203
|
+
- lib/opro/rails/routes.rb
|
189
204
|
- opro.gemspec
|
190
205
|
- test/controllers/permissions_test.rb
|
206
|
+
- test/controllers/refresh_token_test.rb
|
191
207
|
- test/dummy/Rakefile
|
192
208
|
- test/dummy/app/controllers/application_controller.rb
|
193
209
|
- test/dummy/app/controllers/pages_controller.rb
|
@@ -231,10 +247,14 @@ files:
|
|
231
247
|
- test/dummy/public/javascripts/rails.js
|
232
248
|
- test/dummy/public/stylesheets/.gitkeep
|
233
249
|
- test/dummy/script/rails
|
250
|
+
- test/integration/action_dispatch/auth_controller_test.rb
|
251
|
+
- test/integration/action_dispatch/oauth_flow_test.rb
|
252
|
+
- test/integration/action_dispatch/refresh_token_test.rb
|
234
253
|
- test/integration/auth_controller_test.rb
|
235
|
-
- test/integration/
|
254
|
+
- test/integration/client_app_controller_test.rb
|
236
255
|
- test/integration/docs_controller_test.rb
|
237
256
|
- test/integration/oauth_test.rb
|
257
|
+
- test/integration/refresh_token_test.rb
|
238
258
|
- test/opro_test.rb
|
239
259
|
- test/support/integration_case.rb
|
240
260
|
- test/test_helper.rb
|
@@ -253,7 +273,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
253
273
|
version: '0'
|
254
274
|
segments:
|
255
275
|
- 0
|
256
|
-
hash: -
|
276
|
+
hash: -3291297708449199104
|
257
277
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
258
278
|
none: false
|
259
279
|
requirements:
|
@@ -1,21 +0,0 @@
|
|
1
|
-
class Oauth::ClientApplicationController < ApplicationController
|
2
|
-
before_filter :opro_authenticate_user!
|
3
|
-
|
4
|
-
def new
|
5
|
-
@client_app = Oauth::ClientApplication.new
|
6
|
-
end
|
7
|
-
|
8
|
-
def create
|
9
|
-
@client_app = Oauth::ClientApplication.find_by_user_id_and_name(current_user.id, params[:oauth_client_application][:name])
|
10
|
-
@client_app ||= Oauth::ClientApplication.create_with_user_and_name(current_user, params[:oauth_client_application][:name])
|
11
|
-
if @client_app.save
|
12
|
-
# do nothing
|
13
|
-
else
|
14
|
-
render :new
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def index
|
19
|
-
@client_apps = Oauth::ClientApplication.where(:user_id => current_user.id)
|
20
|
-
end
|
21
|
-
end
|
@@ -1,8 +0,0 @@
|
|
1
|
-
class ApplicationController < ActionController::Base
|
2
|
-
|
3
|
-
# Any code that would/should go into ApplicationController is
|
4
|
-
# now in lib/opro/conrollers/application_controller_helper.rb
|
5
|
-
# it is loaded into ApplicationController in lib/opro/engine.rb
|
6
|
-
# thanks for visiting, come back soon
|
7
|
-
|
8
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class ClientApplicationControllerTest < ActiveSupport::IntegrationCase
|
4
|
-
test 'must be logged in' do
|
5
|
-
visit new_oauth_client_application_path
|
6
|
-
assert_equal '/users/sign_in', current_path
|
7
|
-
end
|
8
|
-
|
9
|
-
test 'create client application' do
|
10
|
-
user = create_user
|
11
|
-
as_user(user).visit new_oauth_client_application_path
|
12
|
-
assert_equal '/oauth_client_applications/new', current_path
|
13
|
-
|
14
|
-
fill_in 'oauth_client_application_name', :with => rand_name
|
15
|
-
|
16
|
-
click_button 'submitApp'
|
17
|
-
assert_equal '/oauth_client_applications', current_path
|
18
|
-
|
19
|
-
last_client = Oauth::ClientApplication.order(:created_at).last
|
20
|
-
assert has_content?(last_client.name)
|
21
|
-
assert has_content?(last_client.client_id)
|
22
|
-
assert has_content?(last_client.client_secret)
|
23
|
-
end
|
24
|
-
end
|