doorkeeper 0.3.0 → 0.4.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.
Files changed (176) hide show
  1. data/.gitignore +12 -0
  2. data/.rspec +1 -0
  3. data/.travis.yml +8 -0
  4. data/CHANGELOG.md +98 -0
  5. data/Gemfile +6 -0
  6. data/README.md +42 -6
  7. data/app/controllers/doorkeeper/application_controller.rb +4 -11
  8. data/app/controllers/doorkeeper/applications_controller.rb +7 -1
  9. data/app/controllers/doorkeeper/authorizations_controller.rb +11 -1
  10. data/app/controllers/doorkeeper/authorized_applications_controller.rb +3 -3
  11. data/app/controllers/doorkeeper/tokens_controller.rb +19 -5
  12. data/app/models/doorkeeper/access_grant.rb +28 -0
  13. data/app/models/doorkeeper/access_token.rb +65 -0
  14. data/app/models/doorkeeper/application.rb +54 -0
  15. data/app/views/doorkeeper/applications/index.html.erb +1 -1
  16. data/app/views/doorkeeper/authorizations/error.html.erb +1 -1
  17. data/app/views/doorkeeper/authorizations/new.html.erb +15 -15
  18. data/app/views/doorkeeper/authorized_applications/index.html.erb +1 -2
  19. data/config/locales/en.yml +3 -0
  20. data/doorkeeper.gemspec +28 -0
  21. data/gemfiles/gemfile.rails-3.1.x +7 -0
  22. data/gemfiles/gemfile.rails-3.2.x +7 -0
  23. data/lib/doorkeeper/config.rb +73 -12
  24. data/lib/doorkeeper/doorkeeper_for.rb +19 -15
  25. data/lib/doorkeeper/engine.rb +28 -0
  26. data/lib/doorkeeper/models/scopes.rb +13 -0
  27. data/lib/doorkeeper/oauth/access_token_request.rb +9 -20
  28. data/lib/doorkeeper/oauth/authorization/code.rb +1 -1
  29. data/lib/doorkeeper/oauth/authorization/token.rb +2 -2
  30. data/lib/doorkeeper/oauth/authorization_request.rb +18 -23
  31. data/lib/doorkeeper/oauth/client/credentials.rb +21 -0
  32. data/lib/doorkeeper/oauth/client/methods.rb +18 -0
  33. data/lib/doorkeeper/oauth/client.rb +27 -0
  34. data/lib/doorkeeper/oauth/client_credentials/creator.rb +29 -0
  35. data/lib/doorkeeper/oauth/client_credentials/issuer.rb +35 -0
  36. data/lib/doorkeeper/oauth/client_credentials/response.rb +42 -0
  37. data/lib/doorkeeper/oauth/client_credentials/validation.rb +33 -0
  38. data/lib/doorkeeper/oauth/client_credentials_request.rb +46 -0
  39. data/lib/doorkeeper/oauth/error.rb +9 -0
  40. data/lib/doorkeeper/oauth/error_response.rb +30 -0
  41. data/lib/doorkeeper/oauth/helpers/scope_checker.rb +2 -2
  42. data/lib/doorkeeper/oauth/password_access_token_request.rb +130 -0
  43. data/lib/doorkeeper/oauth/scopes.rb +60 -0
  44. data/lib/doorkeeper/version.rb +1 -1
  45. data/lib/doorkeeper.rb +23 -3
  46. data/lib/generators/doorkeeper/install_generator.rb +1 -0
  47. data/lib/generators/doorkeeper/templates/initializer.rb +12 -7
  48. data/lib/generators/doorkeeper/templates/migration.rb +1 -1
  49. data/lib/generators/doorkeeper/views_generator.rb +15 -0
  50. data/script/rails +6 -0
  51. data/script/run_all +11 -0
  52. data/spec/controllers/applications_controller_spec.rb +18 -0
  53. data/spec/controllers/authorizations_controller_spec.rb +131 -0
  54. data/spec/controllers/protected_resources_controller_spec.rb +308 -0
  55. data/spec/controllers/tokens_controller_spec.rb +34 -0
  56. data/spec/dummy/Rakefile +7 -0
  57. data/spec/dummy/app/assets/javascripts/application.js +9 -0
  58. data/spec/dummy/app/assets/stylesheets/application.css +7 -0
  59. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  60. data/spec/dummy/app/controllers/full_protected_resources_controller.rb +12 -0
  61. data/spec/dummy/app/controllers/home_controller.rb +17 -0
  62. data/spec/dummy/app/controllers/semi_protected_resources_controller.rb +11 -0
  63. data/spec/dummy/app/helpers/application_helper.rb +5 -0
  64. data/spec/dummy/app/models/user.rb +11 -0
  65. data/spec/dummy/app/views/home/index.html.erb +0 -0
  66. data/spec/dummy/app/views/layouts/application.html.erb +16 -0
  67. data/spec/dummy/config/application.rb +53 -0
  68. data/spec/dummy/config/boot.rb +10 -0
  69. data/spec/dummy/config/database.yml +15 -0
  70. data/spec/dummy/config/environment.rb +5 -0
  71. data/spec/dummy/config/environments/development.rb +30 -0
  72. data/spec/dummy/config/environments/production.rb +60 -0
  73. data/spec/dummy/config/environments/test.rb +39 -0
  74. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  75. data/spec/dummy/config/initializers/doorkeeper.rb +41 -0
  76. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  77. data/spec/dummy/config/initializers/session_store.rb +8 -0
  78. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  79. data/spec/dummy/config/locales/doorkeeper.en.yml +5 -0
  80. data/spec/dummy/config/routes.rb +8 -0
  81. data/spec/dummy/config.ru +4 -0
  82. data/spec/dummy/db/migrate/20111122132257_create_users.rb +9 -0
  83. data/spec/dummy/db/migrate/20120312140401_add_password_to_users.rb +5 -0
  84. data/spec/dummy/db/migrate/20120524202412_create_doorkeeper_tables.rb +42 -0
  85. data/spec/dummy/db/schema.rb +62 -0
  86. data/spec/dummy/public/404.html +26 -0
  87. data/spec/dummy/public/422.html +26 -0
  88. data/spec/dummy/public/500.html +26 -0
  89. data/spec/dummy/public/favicon.ico +0 -0
  90. data/spec/dummy/script/rails +6 -0
  91. data/spec/factories/access_grant.rb +9 -0
  92. data/spec/factories/access_token.rb +7 -0
  93. data/spec/factories/application.rb +6 -0
  94. data/spec/generators/install_generator_spec.rb +35 -0
  95. data/spec/generators/templates/routes.rb +3 -0
  96. data/spec/generators/views_generator_spec.rb +27 -0
  97. data/spec/lib/config_spec.rb +87 -0
  98. data/spec/lib/models/expirable_spec.rb +49 -0
  99. data/spec/lib/models/revocable_spec.rb +31 -0
  100. data/spec/lib/models/scopes_spec.rb +32 -0
  101. data/spec/lib/oauth/access_token_request_spec.rb +240 -0
  102. data/spec/lib/oauth/authorization/uri_builder_spec.rb +37 -0
  103. data/spec/lib/oauth/authorization_request_spec.rb +286 -0
  104. data/spec/lib/oauth/client/credentials_spec.rb +47 -0
  105. data/spec/lib/oauth/client/methods_spec.rb +54 -0
  106. data/spec/lib/oauth/client_credentials/creator_spec.rb +47 -0
  107. data/spec/lib/oauth/client_credentials/issuer_spec.rb +57 -0
  108. data/spec/lib/oauth/client_credentials/response_spec.rb +58 -0
  109. data/spec/lib/oauth/client_credentials/validation_spec.rb +29 -0
  110. data/spec/lib/oauth/client_credentials_integration_spec.rb +27 -0
  111. data/spec/lib/oauth/client_credentials_request_spec.rb +60 -0
  112. data/spec/lib/oauth/client_spec.rb +42 -0
  113. data/spec/lib/oauth/error_response_spec.rb +40 -0
  114. data/spec/lib/oauth/error_spec.rb +19 -0
  115. data/spec/lib/oauth/helpers/scope_checker_spec.rb +74 -0
  116. data/spec/lib/oauth/helpers/unique_token_spec.rb +38 -0
  117. data/spec/lib/oauth/helpers/uri_checker_spec.rb +64 -0
  118. data/spec/lib/oauth/password_access_token_request_spec.rb +152 -0
  119. data/spec/lib/oauth/scopes_spec.rb +115 -0
  120. data/spec/models/doorkeeper/access_grant_spec.rb +36 -0
  121. data/spec/models/doorkeeper/access_token_spec.rb +113 -0
  122. data/spec/models/doorkeeper/application_spec.rb +129 -0
  123. data/spec/requests/applications/applications_request_spec.rb +92 -0
  124. data/spec/requests/applications/authorized_applications_spec.rb +30 -0
  125. data/spec/requests/endpoints/authorization_spec.rb +63 -0
  126. data/spec/requests/endpoints/token_spec.rb +29 -0
  127. data/spec/requests/flows/authorization_code_errors_spec.rb +111 -0
  128. data/spec/requests/flows/authorization_code_spec.rb +125 -0
  129. data/spec/requests/flows/client_credentials_spec.rb +56 -0
  130. data/spec/requests/flows/implicit_grant_errors_spec.rb +31 -0
  131. data/spec/requests/flows/implicit_grant_spec.rb +19 -0
  132. data/spec/requests/flows/password_spec.rb +52 -0
  133. data/spec/requests/flows/refresh_token_spec.rb +66 -0
  134. data/spec/requests/flows/skip_authorization_spec.rb +40 -0
  135. data/spec/requests/protected_resources/private_api_spec.rb +43 -0
  136. data/spec/spec_helper.rb +1 -0
  137. data/spec/spec_helper_integration.rb +28 -0
  138. data/spec/support/dependencies/database_cleaner.rb +16 -0
  139. data/spec/support/dependencies/factory_girl.rb +5 -0
  140. data/spec/support/helpers/access_token_request_helper.rb +11 -0
  141. data/spec/support/helpers/authorization_request_helper.rb +32 -0
  142. data/spec/support/helpers/config_helper.rb +9 -0
  143. data/spec/support/helpers/model_helper.rb +45 -0
  144. data/spec/support/helpers/request_spec_helper.rb +72 -0
  145. data/spec/support/helpers/url_helper.rb +51 -0
  146. data/spec/support/shared/controllers_shared_context.rb +60 -0
  147. data/spec/support/shared/models_shared_examples.rb +44 -0
  148. metadata +163 -57
  149. data/app/controllers/doorkeeper/application_controller.rbc +0 -675
  150. data/app/controllers/doorkeeper/applications_controller.rbc +0 -954
  151. data/app/controllers/doorkeeper/authorizations_controller.rbc +0 -659
  152. data/app/controllers/doorkeeper/authorized_applications_controller.rbc +0 -393
  153. data/app/controllers/doorkeeper/tokens_controller.rbc +0 -423
  154. data/app/helpers/doorkeeper/application_helper.rbc +0 -127
  155. data/app/models/access_grant.rb +0 -31
  156. data/app/models/access_grant.rbc +0 -821
  157. data/app/models/access_token.rb +0 -70
  158. data/app/models/access_token.rbc +0 -979
  159. data/app/models/application.rb +0 -45
  160. data/app/models/application.rbc +0 -753
  161. data/config/initializers/form_errors.rbc +0 -272
  162. data/config/routes.rbc +0 -366
  163. data/lib/doorkeeper/config/scope.rb +0 -11
  164. data/lib/doorkeeper/config/scopes.rb +0 -61
  165. data/lib/doorkeeper/config/scopes_builder.rb +0 -18
  166. data/lib/doorkeeper/config.rbc +0 -1385
  167. data/lib/doorkeeper/doorkeeper_for.rbc +0 -1029
  168. data/lib/doorkeeper/engine.rbc +0 -318
  169. data/lib/doorkeeper/oauth/access_token_request.rbc +0 -2042
  170. data/lib/doorkeeper/oauth/authorization_request.rbc +0 -2272
  171. data/lib/doorkeeper/oauth/random_string.rbc +0 -437
  172. data/lib/doorkeeper/validations.rbc +0 -774
  173. data/lib/doorkeeper/version.rbc +0 -130
  174. data/lib/doorkeeper.rbc +0 -407
  175. data/lib/generators/doorkeeper/install_generator.rbc +0 -453
  176. data/lib/tasks/doorkeeper_tasks.rake.compiled.rbc +0 -40
@@ -0,0 +1,308 @@
1
+ require 'spec_helper_integration'
2
+
3
+ module ControllerActions
4
+ def index
5
+ render :text => "index"
6
+ end
7
+
8
+ def show
9
+ render :text => "show"
10
+ end
11
+ end
12
+
13
+ shared_examples "specified for particular actions" do
14
+ context "with valid token", :token => :valid do
15
+ it "allows into index action" do
16
+ get :index, :access_token => token_string
17
+ response.should be_success
18
+ end
19
+
20
+ it "allows into show action" do
21
+ get :show, :id => "3", :access_token => token_string
22
+ response.should be_success
23
+ end
24
+ end
25
+
26
+ context "with invalid token", :token => :invalid do
27
+ include_context "invalid token"
28
+
29
+ it "does not allow into index action" do
30
+ get :index, :access_token => token_string
31
+ response.status.should == 401
32
+ end
33
+
34
+ it "allows into show action" do
35
+ get :show, :id => "5", :access_token => token_string
36
+ response.should be_success
37
+ end
38
+ end
39
+ end
40
+
41
+ shared_examples "specified with except" do
42
+ context "with valid token", :token => :valid do
43
+ it "allows into index action" do
44
+ get :index, :access_token => token_string
45
+ response.should be_success
46
+ end
47
+
48
+ it "allows into show action" do
49
+ get :show, :id => "4", :access_token => token_string
50
+ response.should be_success
51
+ end
52
+ end
53
+
54
+ context "with invalid token", :token => :invalid do
55
+ it "allows into index action" do
56
+ get :index, :access_token => token_string
57
+ response.should be_success
58
+ end
59
+
60
+ it "does not allow into show action" do
61
+ get :show, :id => "14", :access_token => token_string
62
+ response.status.should == 401
63
+ end
64
+ end
65
+ end
66
+
67
+ describe "Doorkeeper_for helper" do
68
+ context "accepts token code specified as" do
69
+ controller do
70
+ doorkeeper_for :all
71
+
72
+ def index
73
+ render :text => "index"
74
+ end
75
+ end
76
+
77
+ let :token_string do
78
+ "1A2BC3"
79
+ end
80
+
81
+ it "access_token param" do
82
+ Doorkeeper::AccessToken.should_receive(:find_by_token).with(token_string)
83
+ get :index, :access_token => token_string
84
+ end
85
+
86
+ it "bearer_token param" do
87
+ Doorkeeper::AccessToken.should_receive(:find_by_token).with(token_string)
88
+ get :index, :bearer_token => token_string
89
+ end
90
+
91
+ it "Authorization header" do
92
+ Doorkeeper::AccessToken.should_receive(:find_by_token).with(token_string)
93
+ request.env["HTTP_AUTHORIZATION"] = "Bearer #{token_string}"
94
+ get :index
95
+ end
96
+
97
+ it "different kind of Authorization header" do
98
+ Doorkeeper::AccessToken.should_not_receive(:find_by_token)
99
+ request.env["HTTP_AUTHORIZATION"] = "Basic #{Base64.encode64("foo:bar")}"
100
+ get :index
101
+ end
102
+
103
+ it "doesn't change Authorization header value" do
104
+ Doorkeeper::AccessToken.should_receive(:find_by_token).exactly(2).times
105
+ request.env["HTTP_AUTHORIZATION"] = "Bearer #{token_string}"
106
+ get :index
107
+ get :index
108
+ end
109
+ end
110
+
111
+ context "defined for all actions" do
112
+ controller do
113
+ doorkeeper_for :all
114
+
115
+ include ControllerActions
116
+ end
117
+
118
+ context "with valid token", :token => :valid do
119
+ it "allows into index action" do
120
+ get :index, :access_token => token_string
121
+ response.should be_success
122
+ end
123
+
124
+ it "allows into show action" do
125
+ get :show, :id => "4", :access_token => token_string
126
+ response.should be_success
127
+ end
128
+ end
129
+
130
+ context "with invalid token", :token => :invalid do
131
+ it "does not allow into index action" do
132
+ get :index, :access_token => token_string
133
+ response.status.should == 401
134
+ end
135
+
136
+ it "does not allow into show action" do
137
+ get :show, :id => "4", :access_token => token_string
138
+ response.status.should == 401
139
+ end
140
+ end
141
+ end
142
+
143
+ context "defined only for index action" do
144
+ controller do
145
+ doorkeeper_for :index
146
+
147
+ include ControllerActions
148
+ end
149
+ include_examples "specified for particular actions"
150
+ end
151
+
152
+ context "defined for actions except index" do
153
+ controller do
154
+ doorkeeper_for :all, :except => :index
155
+
156
+ include ControllerActions
157
+ end
158
+
159
+ include_examples "specified with except"
160
+ end
161
+
162
+ context "defined with scopes" do
163
+ controller do
164
+ doorkeeper_for :all, :scopes => [:write]
165
+
166
+ include ControllerActions
167
+ end
168
+
169
+ let :token_string do
170
+ "1A2DUWE"
171
+ end
172
+
173
+ it "allows if the token has particular scopes" do
174
+ token = double(Doorkeeper::AccessToken, :accessible? => true, :scopes => [:write, :public])
175
+ Doorkeeper::AccessToken.should_receive(:find_by_token).with(token_string).and_return(token)
176
+ get :index, :access_token => token_string
177
+ response.should be_success
178
+ end
179
+
180
+ it "does not allow if the token does not include given scope" do
181
+ token = double(Doorkeeper::AccessToken, :accessible? => true, :scopes => [:public])
182
+ Doorkeeper::AccessToken.should_receive(:find_by_token).with(token_string).and_return(token)
183
+ get :index, :access_token => token_string
184
+ response.status.should == 401
185
+ end
186
+ end
187
+
188
+ context "when custom unauthorized render options are configured" do
189
+ controller do
190
+ doorkeeper_for :all
191
+
192
+ include ControllerActions
193
+ end
194
+
195
+ context "with a JSON custom render", :token => :invalid do
196
+ before do
197
+ controller.should_receive(:doorkeeper_unauthorized_render_options).and_return({ :json => ActiveSupport::JSON.encode({ :error => "Unauthorized" }) } )
198
+ end
199
+
200
+ it "it renders a custom JSON response", :token => :invalid do
201
+ get :index, :access_token => token_string
202
+ response.status.should == 401
203
+ response.content_type.should == 'application/json'
204
+ parsed_body = JSON.parse(response.body)
205
+ parsed_body.should_not be_nil
206
+ parsed_body['error'].should == 'Unauthorized'
207
+ end
208
+
209
+ end
210
+
211
+ context "with a text custom render", :token => :invalid do
212
+ before do
213
+ controller.should_receive(:doorkeeper_unauthorized_render_options).and_return({ :text => "Unauthorized" } )
214
+ end
215
+
216
+ it "it renders a custom JSON response", :token => :invalid do
217
+ get :index, :access_token => token_string
218
+ response.status.should == 401
219
+ response.content_type.should == 'text/html'
220
+ response.body.should == 'Unauthorized'
221
+ end
222
+ end
223
+ end
224
+
225
+ context "when defined with conditional if block" do
226
+ controller do
227
+ doorkeeper_for :index, :if => lambda { the_false }
228
+ doorkeeper_for :show, :if => lambda { the_true }
229
+
230
+ include ControllerActions
231
+
232
+ private
233
+ def the_true
234
+ true
235
+ end
236
+
237
+ def the_false
238
+ false
239
+ end
240
+ end
241
+
242
+ context "with valid token", :token => :valid do
243
+ it "enables access if passed block evaluates to false" do
244
+ get :index, :access_token => token_string
245
+ response.should be_success
246
+ end
247
+
248
+ it "enables access if passed block evaluates to true" do
249
+ get :show, :id => 1, :access_token => token_string
250
+ response.should be_success
251
+ end
252
+ end
253
+
254
+ context "with invalid token", :token => :invalid do
255
+ it "enables access if passed block evaluates to false" do
256
+ get :index, :access_token => token_string
257
+ response.should be_success
258
+ end
259
+
260
+ it "does not enable access if passed block evaluates to true" do
261
+ get :show, :id => 3, :access_token => token_string
262
+ response.status.should == 401
263
+ end
264
+ end
265
+ end
266
+
267
+ context "when defined with conditional unless block" do
268
+ controller do
269
+ doorkeeper_for :index, :unless => lambda { the_false }
270
+ doorkeeper_for :show, :unless => lambda { the_true }
271
+
272
+ include ControllerActions
273
+
274
+ def the_true
275
+ true
276
+ end
277
+
278
+ private
279
+
280
+ def the_false
281
+ false
282
+ end
283
+ end
284
+
285
+ context "with valid token", :token => :valid do
286
+ it "allows access if passed block evaluates to false" do
287
+ get :index, :access_token => token_string
288
+ response.should be_success
289
+ end
290
+
291
+ it "allows access if passed block evaluates to true" do
292
+ get :show, :id => 1, :access_token => token_string
293
+ response.should be_success
294
+ end
295
+ end
296
+
297
+ context "with invalid token", :token => :invalid do
298
+ it "does not allow access if passed block evaluates to false" do
299
+ get :index, :access_token => token_string
300
+ end
301
+
302
+ it "allows access if passed block evaluates to true" do
303
+ get :show, :id => 3, :access_token => token_string
304
+ response.should be_success
305
+ end
306
+ end
307
+ end
308
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper_integration'
2
+
3
+ describe Doorkeeper::TokensController do
4
+ describe "when authorization has succeeded" do
5
+ let :token do
6
+ double(:token, :authorize => true)
7
+ end
8
+
9
+ before do
10
+ controller.stub(:token) { token }
11
+ end
12
+
13
+ it "returns the authorization" do
14
+ token.should_receive(:authorization)
15
+ post :create, :use_route => :doorkeeper
16
+ end
17
+ end
18
+
19
+ describe "when authorization has failed" do
20
+ let :token do
21
+ double(:token, :authorize => false)
22
+ end
23
+
24
+ before do
25
+ controller.stub(:token) { token }
26
+ end
27
+
28
+ it "returns the error response" do
29
+ token.stub(:error_response => stub(:to_json => [], :status => :unauthorized))
30
+ post :create, :use_route => :doorkeeper
31
+ response.status.should == 401
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
3
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4
+
5
+ require File.expand_path('../config/application', __FILE__)
6
+
7
+ Dummy::Application.load_tasks
@@ -0,0 +1,9 @@
1
+ // This is a manifest file that'll be compiled into including all the files listed below.
2
+ // Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
3
+ // be included in the compiled file accessible from http://example.com/assets/application.js
4
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
5
+ // the compiled file.
6
+ //
7
+ //= require jquery
8
+ //= require jquery_ujs
9
+ //= require_tree .
@@ -0,0 +1,7 @@
1
+ /*
2
+ * This is a manifest file that'll automatically include all the stylesheets available in this directory
3
+ * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
4
+ * the top of the compiled file, but it's generally better to create a new file per style scope.
5
+ *= require_self
6
+ *= require_tree .
7
+ */
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ end
@@ -0,0 +1,12 @@
1
+ class FullProtectedResourcesController < ApplicationController
2
+ doorkeeper_for :index
3
+ doorkeeper_for :show, :scopes => [:admin]
4
+
5
+ def index
6
+ render :text => "index"
7
+ end
8
+
9
+ def show
10
+ render :text => "show"
11
+ end
12
+ end
@@ -0,0 +1,17 @@
1
+ class HomeController < ApplicationController
2
+ def index
3
+ end
4
+
5
+ def sign_in
6
+ session[:user_id] = if Rails.env.development?
7
+ User.first || User.create!(:name => "Joe", :password => "sekret")
8
+ else
9
+ User.first
10
+ end
11
+ redirect_to '/'
12
+ end
13
+
14
+ def callback
15
+ render :text => "ok"
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ class SemiProtectedResourcesController < ApplicationController
2
+ doorkeeper_for :index
3
+
4
+ def index
5
+ render :text => "protected index"
6
+ end
7
+
8
+ def show
9
+ render :text => "protected show"
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ module ApplicationHelper
2
+ def current_user
3
+ @current_user ||= User.find_by_id(session[:user_id])
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ class User < ActiveRecord::Base
2
+ has_secure_password
3
+ validates_presence_of :password, :on => :create
4
+
5
+ attr_accessible :name, :password
6
+
7
+ def self.authenticate!(name, password)
8
+ owner = User.find_by_name(name)
9
+ owner.authenticate(password) if owner
10
+ end
11
+ end
File without changes
@@ -0,0 +1,16 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag "application" %>
6
+ <%= javascript_include_tag "application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= link_to "Sign in", '/sign_in' %>
12
+
13
+ <%= yield %>
14
+
15
+ </body>
16
+ </html>
@@ -0,0 +1,53 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ # Pick the frameworks you want:
4
+ require "active_record/railtie"
5
+ require "action_controller/railtie"
6
+ # require "action_mailer/railtie"
7
+ require "active_resource/railtie"
8
+ require "sprockets/railtie"
9
+ # require "rails/test_unit/railtie"
10
+
11
+ Bundler.require
12
+ require "doorkeeper"
13
+
14
+ module Dummy
15
+ class Application < Rails::Application
16
+ # Settings in config/environments/* take precedence over those specified here.
17
+ # Application configuration should go into files in config/initializers
18
+ # -- all .rb files in that directory are automatically loaded.
19
+
20
+ # Custom directories with classes and modules you want to be autoloadable.
21
+ # config.autoload_paths += %W(#{config.root}/extras)
22
+
23
+ # Only load the plugins named here, in the order given (default is alphabetical).
24
+ # :all can be used as a placeholder for all plugins not explicitly named.
25
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
26
+
27
+ # Activate observers that should always be running.
28
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
29
+
30
+ config.active_record.whitelist_attributes = true
31
+
32
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
33
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
34
+ # config.time_zone = 'Central Time (US & Canada)'
35
+
36
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
37
+ config.i18n.load_path += Dir[Rails.root.join('../../', 'config/locales', '*.{rb,yml}').to_s]
38
+ # config.i18n.default_locale = :en
39
+
40
+ # Configure the default encoding used in templates for Ruby 1.9.
41
+ config.encoding = "utf-8"
42
+
43
+ # Configure sensitive parameters which will be filtered from the log file.
44
+ config.filter_parameters += [:password]
45
+
46
+ # Enable the asset pipeline
47
+ config.assets.enabled = true
48
+
49
+ # Version of your assets, change this if you want to expire all your assets
50
+ config.assets.version = '1.0'
51
+ end
52
+ end
53
+
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ gemfile = File.expand_path('../../../../Gemfile', __FILE__)
3
+
4
+ if File.exist?(gemfile)
5
+ ENV['BUNDLE_GEMFILE'] = gemfile
6
+ require 'bundler'
7
+ Bundler.setup
8
+ end
9
+
10
+ $:.unshift File.expand_path('../../../../lib', __FILE__)
@@ -0,0 +1,15 @@
1
+ development:
2
+ adapter: sqlite3
3
+ database: db/development.sqlite3
4
+ pool: 5
5
+ timeout: 5000
6
+
7
+ test:
8
+ adapter: sqlite3
9
+ database: ":memory:"
10
+ timeout: 500
11
+
12
+ production:
13
+ adapter: sqlite3
14
+ database: ":memory:"
15
+ timeout: 500
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ Dummy::Application.initialize!
@@ -0,0 +1,30 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # In the development environment your application's code is reloaded on
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the web server when you make code changes.
7
+ config.cache_classes = false
8
+
9
+ # Log error messages when you accidentally call methods on nil.
10
+ config.whiny_nils = true
11
+
12
+ # Show full error reports and disable caching
13
+ config.consider_all_requests_local = true
14
+ config.action_controller.perform_caching = false
15
+
16
+ # Don't care if the mailer can't send
17
+ # config.action_mailer.raise_delivery_errors = false
18
+
19
+ # Print deprecation notices to the Rails logger
20
+ config.active_support.deprecation = :log
21
+
22
+ # Only use best-standards-support built into browsers
23
+ config.action_dispatch.best_standards_support = :builtin
24
+
25
+ # Do not compress assets
26
+ config.assets.compress = false
27
+
28
+ # Expands the lines which load the assets
29
+ config.assets.debug = true
30
+ end
@@ -0,0 +1,60 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # Code is not reloaded between requests
5
+ config.cache_classes = true
6
+
7
+ # Full error reports are disabled and caching is turned on
8
+ config.consider_all_requests_local = false
9
+ config.action_controller.perform_caching = true
10
+
11
+ # Disable Rails's static asset server (Apache or nginx will already do this)
12
+ config.serve_static_assets = false
13
+
14
+ # Compress JavaScripts and CSS
15
+ config.assets.compress = true
16
+
17
+ # Don't fallback to assets pipeline if a precompiled asset is missed
18
+ config.assets.compile = false
19
+
20
+ # Generate digests for assets URLs
21
+ config.assets.digest = true
22
+
23
+ # Defaults to Rails.root.join("public/assets")
24
+ # config.assets.manifest = YOUR_PATH
25
+
26
+ # Specifies the header that your server uses for sending files
27
+ # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
28
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
29
+
30
+ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
31
+ # config.force_ssl = true
32
+
33
+ # See everything in the log (default is :info)
34
+ # config.log_level = :debug
35
+
36
+ # Use a different logger for distributed setups
37
+ # config.logger = SyslogLogger.new
38
+
39
+ # Use a different cache store in production
40
+ # config.cache_store = :mem_cache_store
41
+
42
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server
43
+ # config.action_controller.asset_host = "http://assets.example.com"
44
+
45
+ # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
46
+ # config.assets.precompile += %w( search.js )
47
+
48
+ # Disable delivery errors, bad email addresses will be ignored
49
+ # config.action_mailer.raise_delivery_errors = false
50
+
51
+ # Enable threaded mode
52
+ # config.threadsafe!
53
+
54
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
55
+ # the I18n.default_locale when a translation can not be found)
56
+ config.i18n.fallbacks = true
57
+
58
+ # Send deprecation notices to registered listeners
59
+ config.active_support.deprecation = :notify
60
+ end
@@ -0,0 +1,39 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # The test environment is used exclusively to run your application's
5
+ # test suite. You never need to work with it otherwise. Remember that
6
+ # your test database is "scratch space" for the test suite and is wiped
7
+ # and recreated between test runs. Don't rely on the data there!
8
+ config.cache_classes = true
9
+
10
+ # Configure static asset server for tests with Cache-Control for performance
11
+ config.serve_static_assets = true
12
+ config.static_cache_control = "public, max-age=3600"
13
+
14
+ # Log error messages when you accidentally call methods on nil
15
+ config.whiny_nils = true
16
+
17
+ # Show full error reports and disable caching
18
+ config.consider_all_requests_local = true
19
+ config.action_controller.perform_caching = false
20
+
21
+ # Raise exceptions instead of rendering exception templates
22
+ config.action_dispatch.show_exceptions = false
23
+
24
+ # Disable request forgery protection in test environment
25
+ config.action_controller.allow_forgery_protection = false
26
+
27
+ # Tell Action Mailer not to deliver emails to the real world.
28
+ # The :test delivery method accumulates sent emails in the
29
+ # ActionMailer::Base.deliveries array.
30
+ # config.action_mailer.delivery_method = :test
31
+
32
+ # Use SQL instead of Active Record's schema dumper when creating the test database.
33
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
34
+ # like if you have constraints or database-specific column types
35
+ # config.active_record.schema_format = :sql
36
+
37
+ # Print deprecation notices to the stderr
38
+ config.active_support.deprecation = :stderr
39
+ end
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
+ # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5
+
6
+ # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7
+ # Rails.backtrace_cleaner.remove_silencers!