doorkeeper 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of doorkeeper might be problematic. Click here for more details.

Files changed (35) hide show
  1. data/README.md +42 -14
  2. data/Rakefile +1 -1
  3. data/app/assets/stylesheets/doorkeeper/application.css +4 -0
  4. data/app/controllers/doorkeeper/application_controller.rb +2 -2
  5. data/app/controllers/doorkeeper/application_controller.rbc +32 -20
  6. data/app/controllers/doorkeeper/authorizations_controller.rbc +86 -22
  7. data/app/controllers/doorkeeper/authorized_applications_controller.rb +13 -0
  8. data/app/controllers/doorkeeper/authorized_applications_controller.rbc +393 -0
  9. data/app/controllers/doorkeeper/tokens_controller.rb +4 -0
  10. data/app/models/access_grant.rb +8 -0
  11. data/app/models/access_grant.rbc +204 -39
  12. data/app/models/access_token.rb +31 -3
  13. data/app/models/access_token.rbc +270 -72
  14. data/app/models/application.rb +8 -1
  15. data/app/models/application.rbc +307 -61
  16. data/app/views/doorkeeper/authorizations/new.html.erb +17 -0
  17. data/app/views/doorkeeper/authorized_applications/index.html.erb +26 -0
  18. data/config/routes.rb +1 -0
  19. data/config/routes.rbc +48 -4
  20. data/lib/doorkeeper/config.rb +82 -22
  21. data/lib/doorkeeper/config.rbc +739 -295
  22. data/lib/doorkeeper/config/scope.rb +11 -0
  23. data/lib/doorkeeper/config/scopes.rb +57 -0
  24. data/lib/doorkeeper/config/scopes_builder.rb +18 -0
  25. data/lib/doorkeeper/doorkeeper_for.rb +96 -16
  26. data/lib/doorkeeper/oauth/access_token_request.rb +57 -18
  27. data/lib/doorkeeper/oauth/access_token_request.rbc +256 -67
  28. data/lib/doorkeeper/oauth/authorization_request.rb +31 -4
  29. data/lib/doorkeeper/oauth/authorization_request.rbc +230 -65
  30. data/lib/doorkeeper/version.rb +1 -1
  31. data/lib/doorkeeper/version.rbc +1 -1
  32. data/lib/generators/doorkeeper/templates/README +3 -0
  33. data/lib/generators/doorkeeper/templates/initializer.rb +13 -0
  34. data/lib/generators/doorkeeper/templates/migration.rb +4 -1
  35. metadata +35 -18
data/README.md CHANGED
@@ -4,9 +4,9 @@
4
4
 
5
5
  Doorkeeper is a gem that makes it easy to introduce OAuth 2 provider functionality to your application.
6
6
 
7
- So far it supports only Authorization Code flow, but we will [gradually introduce other flows](https://github.com/applicake/doorkeeper/wiki/Supported-Features).
7
+ The gem is under constant development. It is based in the [version 22 of the OAuth specification](http://tools.ietf.org/html/draft-ietf-oauth-v2-22) and it still does not support all OAuth features.
8
8
 
9
- For more information about OAuth 2 go to [OAuth 2 Specs (Draft)](http://tools.ietf.org/html/draft-ietf-oauth-v2-22).
9
+ For more information about the supported features, check out the related [page in the wiki](https://github.com/applicake/doorkeeper/wiki/Supported-Features). For more information about OAuth 2 go to [OAuth 2 Specs (Draft)](http://tools.ietf.org/html/draft-ietf-oauth-v2-22).
10
10
 
11
11
  ## Installation
12
12
 
@@ -20,13 +20,13 @@ Run the installation generator with:
20
20
 
21
21
  rails generate doorkeeper:install
22
22
 
23
- This will generate the doorkeeper initializer and the oauth tables migration. Don't forget to run the migration in your application:
23
+ This will generate the doorkeeper initializer and the OAuth tables migration. Don't forget to run the migration in your application:
24
24
 
25
25
  rake db:migrate
26
26
 
27
27
  ## Configuration
28
28
 
29
- The installation will mount the Doorkeeper routes to your app like this:
29
+ The installation script will automatically add the Doorkeeper routes into your app, like this:
30
30
 
31
31
  ``` ruby
32
32
  Rails.application.routes.draw do
@@ -53,7 +53,7 @@ Doorkeeper.configure do
53
53
  end
54
54
  ```
55
55
 
56
- If you use devise, you may want to use warden to authenticate the block:
56
+ If you use [devise](https://github.com/plataformatec/devise), you may want to use warden to authenticate the block:
57
57
 
58
58
  ``` ruby
59
59
  resource_owner_authenticator do |routes|
@@ -61,15 +61,17 @@ resource_owner_authenticator do |routes|
61
61
  end
62
62
  ```
63
63
 
64
- ## Protecting resources (a.k.a your API endpoint)
64
+ ## Protecting resources with OAuth (a.k.a your API endpoint)
65
65
 
66
- In your api controller, add the `doorkeeper_for` to require the oauth token:
66
+ To protect your API with OAuth, doorkeeper only requires you to call `doorkeeper_for` helper, specifying the actions you want to protect.
67
+
68
+ For example, if you have a products controller under api/v1, you can require the OAuth authentication with:
67
69
 
68
70
  ``` ruby
69
- class Api::V1::ProtectedResourcesController < Api::V1::ApiController
70
- doorkeeper_for :all # Require access token for all actions
71
- doorkeeper_for :only => :index # Only for index action
72
- doorkeeper_for :except => :show # All actions except show
71
+ class Api::V1::ProductsController < Api::V1::ApiController
72
+ doorkeeper_for :all # Require access token for all actions
73
+ doorkeeper_for :all, :except => :index # All actions except show
74
+ doorkeeper_for :index, :show # Only for index and show action
73
75
 
74
76
  # your actions
75
77
  end
@@ -77,16 +79,29 @@ end
77
79
 
78
80
  You don't need to setup any before filter, `doorkeeper_for` will handle that for you.
79
81
 
80
- ## Authenticated resource owner
82
+ ### Access Token Scopes
83
+
84
+ You can also require the access token to have specific scopes in certain actions:
85
+
86
+ ```ruby
87
+ class Api::V1::ProductsController < Api::V1::ApiController
88
+ doorkeeper_for :index, :show, :scopes => [:public]
89
+ doorkeeper_for :update, :create, :scopes => [:admin, :write]
90
+ end
91
+ ```
92
+
93
+ For a more detailed explanation about scopes usage, check out the related [page in the wiki](https://github.com/applicake/doorkeeper/wiki/Using-Scopes).
94
+
95
+ ### Authenticated resource owner
81
96
 
82
- If you want to return data based on the current resource owner for example, the access token user credentials, you'll need to define a method in your controller to return the resource owner instance:
97
+ If you want to return data based on the current resource owner, in other words, the access token owner, you may want to define a method in your controller that returns the resource owner instance:
83
98
 
84
99
  ``` ruby
85
100
  class Api::V1::CredentialsController < Api::V1::ApiController
86
101
  doorkeeper_for :all
87
102
  respond_to :json
88
103
 
89
- # GET /api/v1/me.json
104
+ # GET /me.json
90
105
  def me
91
106
  respond_with current_resource_owner
92
107
  end
@@ -100,6 +115,8 @@ class Api::V1::CredentialsController < Api::V1::ApiController
100
115
  end
101
116
  ```
102
117
 
118
+ In this example, we're returning the credentials (`me.json`) of the access token owner.
119
+
103
120
  ## Other resources
104
121
 
105
122
  ### Live demo
@@ -119,3 +136,14 @@ Also, check out our [contributing guidelines page](https://github.com/applicake/
119
136
  ### Supported ruby versions
120
137
 
121
138
  All supported ruby versions are [listed here](https://github.com/applicake/doorkeeper/wiki/Supported-Ruby-versions)
139
+
140
+ ## Additional information
141
+
142
+ ### Maintainers
143
+
144
+ - Felipe Elias Philipp ([github.com/felipeelias](https://github.com/felipeelias))
145
+ - Piotr Jakubowski ([github.com/piotrj](https://github.com/piotrj))
146
+
147
+ ### License
148
+
149
+ MIT License. Copyright 2011 Applicake. [http://applicake.com](http://applicake.com)
data/Rakefile CHANGED
@@ -26,7 +26,7 @@ desc 'Default: run specs.'
26
26
  task :default => :spec
27
27
 
28
28
  desc "Run all specs"
29
- RSpec::Core::RakeTask.new(:spec => "app:test:prepare")
29
+ RSpec::Core::RakeTask.new(:spec)
30
30
 
31
31
  namespace :doorkeeper do
32
32
  desc "Install doorkeeper in dummy app"
@@ -13,3 +13,7 @@ body {
13
13
  .inline_block {
14
14
  display: inline-block;
15
15
  }
16
+
17
+ table td {
18
+ vertical-align: middle;
19
+ }
@@ -7,11 +7,11 @@ module Doorkeeper
7
7
  end
8
8
 
9
9
  def current_resource_owner
10
- instance_exec(main_app, &Doorkeeper.authenticate_resource_owner)
10
+ instance_exec(main_app, &Doorkeeper.configuration.authenticate_resource_owner)
11
11
  end
12
12
 
13
13
  def authenticate_admin!
14
- if block = Doorkeeper.authenticate_admin
14
+ if block = Doorkeeper.configuration.authenticate_admin
15
15
  instance_exec(main_app, &block)
16
16
  end
17
17
  end
@@ -276,7 +276,7 @@ x
276
276
  22
277
277
  current_resource_owner
278
278
  i
279
- 26
279
+ 29
280
280
  5
281
281
  5
282
282
  48
@@ -287,20 +287,23 @@ i
287
287
  49
288
288
  3
289
289
  0
290
+ 49
291
+ 4
292
+ 0
290
293
  13
291
294
  70
292
295
  10
293
- 21
296
+ 24
294
297
  44
295
298
  43
296
- 4
299
+ 5
297
300
  12
298
301
  49
299
- 5
302
+ 6
300
303
  1
301
304
  47
302
305
  50
303
- 6
306
+ 7
304
307
  1
305
308
  11
306
309
  I
@@ -313,7 +316,7 @@ I
313
316
  0
314
317
  n
315
318
  p
316
- 7
319
+ 8
317
320
  x
318
321
  8
319
322
  main_app
@@ -322,6 +325,9 @@ x
322
325
  Doorkeeper
323
326
  n
324
327
  x
328
+ 13
329
+ configuration
330
+ x
325
331
  27
326
332
  authenticate_resource_owner
327
333
  x
@@ -344,7 +350,7 @@ I
344
350
  I
345
351
  a
346
352
  I
347
- 1a
353
+ 1d
348
354
  x
349
355
  92
350
356
  /Users/felipeelias/Applicake/doorkeeper/app/controllers/doorkeeper/application_controller.rb
@@ -361,40 +367,43 @@ x
361
367
  19
362
368
  authenticate_admin!
363
369
  i
364
- 35
370
+ 38
365
371
  45
366
372
  0
367
373
  1
368
374
  49
369
375
  2
370
376
  0
377
+ 49
378
+ 3
379
+ 0
371
380
  19
372
381
  0
373
382
  9
374
- 33
383
+ 36
375
384
  5
376
385
  5
377
386
  48
378
- 3
387
+ 4
379
388
  20
380
389
  0
381
390
  13
382
391
  70
383
392
  10
384
- 27
393
+ 30
385
394
  44
386
395
  43
387
- 4
396
+ 5
388
397
  12
389
398
  49
390
- 5
399
+ 6
391
400
  1
392
401
  47
393
402
  50
394
- 6
403
+ 7
395
404
  1
396
405
  8
397
- 34
406
+ 37
398
407
  1
399
408
  11
400
409
  I
@@ -407,12 +416,15 @@ I
407
416
  0
408
417
  n
409
418
  p
410
- 7
419
+ 8
411
420
  x
412
421
  10
413
422
  Doorkeeper
414
423
  n
415
424
  x
425
+ 13
426
+ configuration
427
+ x
416
428
  18
417
429
  authenticate_admin
418
430
  x
@@ -438,19 +450,19 @@ I
438
450
  I
439
451
  e
440
452
  I
441
- a
453
+ d
442
454
  I
443
455
  f
444
456
  I
445
- 21
457
+ 24
446
458
  I
447
459
  e
448
460
  I
449
- 22
461
+ 25
450
462
  I
451
463
  0
452
464
  I
453
- 23
465
+ 26
454
466
  x
455
467
  92
456
468
  /Users/felipeelias/Applicake/doorkeeper/app/controllers/doorkeeper/application_controller.rb
@@ -180,7 +180,7 @@ x
180
180
  3
181
181
  new
182
182
  i
183
- 19
183
+ 47
184
184
  5
185
185
  48
186
186
  0
@@ -188,16 +188,44 @@ i
188
188
  1
189
189
  0
190
190
  9
191
- 11
191
+ 39
192
+ 5
193
+ 48
194
+ 0
195
+ 49
196
+ 2
197
+ 0
198
+ 9
199
+ 36
200
+ 5
201
+ 48
202
+ 0
203
+ 49
204
+ 3
205
+ 0
206
+ 15
207
+ 5
208
+ 5
209
+ 48
210
+ 0
211
+ 49
212
+ 4
213
+ 0
214
+ 47
215
+ 49
216
+ 5
192
217
  1
193
218
  8
194
- 18
219
+ 37
220
+ 1
221
+ 8
222
+ 46
195
223
  5
196
224
  7
197
- 2
225
+ 6
198
226
  47
199
227
  49
200
- 3
228
+ 7
201
229
  1
202
230
  11
203
231
  I
@@ -210,7 +238,7 @@ I
210
238
  0
211
239
  n
212
240
  p
213
- 4
241
+ 8
214
242
  x
215
243
  13
216
244
  authorization
@@ -218,13 +246,25 @@ x
218
246
  6
219
247
  valid?
220
248
  x
249
+ 20
250
+ access_token_exists?
251
+ x
252
+ 9
253
+ authorize
254
+ x
255
+ 20
256
+ success_redirect_uri
257
+ x
258
+ 11
259
+ redirect_to
260
+ x
221
261
  5
222
262
  error
223
263
  x
224
264
  6
225
265
  render
226
266
  p
227
- 7
267
+ 19
228
268
  I
229
269
  -1
230
270
  I
@@ -234,11 +274,35 @@ I
234
274
  I
235
275
  5
236
276
  I
237
- 12
277
+ 8
278
+ I
279
+ 6
280
+ I
281
+ 10
282
+ I
283
+ 7
284
+ I
285
+ 17
286
+ I
287
+ 8
288
+ I
289
+ 24
290
+ I
291
+ 6
292
+ I
293
+ 25
238
294
  I
239
295
  0
240
296
  I
241
- 13
297
+ 27
298
+ I
299
+ b
300
+ I
301
+ 2e
302
+ I
303
+ 0
304
+ I
305
+ 2f
242
306
  x
243
307
  95
244
308
  /Users/felipeelias/Applicake/doorkeeper/app/controllers/doorkeeper/authorizations_controller.rb
@@ -325,19 +389,19 @@ p
325
389
  I
326
390
  -1
327
391
  I
328
- 8
392
+ f
329
393
  I
330
394
  0
331
395
  I
332
- 9
396
+ 10
333
397
  I
334
398
  8
335
399
  I
336
- a
400
+ 11
337
401
  I
338
402
  15
339
403
  I
340
- c
404
+ 13
341
405
  I
342
406
  1c
343
407
  I
@@ -408,15 +472,15 @@ p
408
472
  I
409
473
  -1
410
474
  I
411
- 10
475
+ 17
412
476
  I
413
477
  0
414
478
  I
415
- 11
479
+ 18
416
480
  I
417
481
  7
418
482
  I
419
- 12
483
+ 19
420
484
  I
421
485
  13
422
486
  x
@@ -532,11 +596,11 @@ p
532
596
  I
533
597
  -1
534
598
  I
535
- 17
599
+ 1e
536
600
  I
537
601
  0
538
602
  I
539
- 18
603
+ 1f
540
604
  I
541
605
  31
542
606
  x
@@ -557,19 +621,19 @@ I
557
621
  I
558
622
  18
559
623
  I
560
- 8
624
+ f
561
625
  I
562
626
  26
563
627
  I
564
- 10
628
+ 17
565
629
  I
566
630
  34
567
631
  I
568
- 15
632
+ 1c
569
633
  I
570
634
  38
571
635
  I
572
- 17
636
+ 1e
573
637
  I
574
638
  46
575
639
  x