doorkeeper 0.1.0 → 0.1.1

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 (32) hide show
  1. data/README.md +63 -48
  2. data/app/assets/stylesheets/doorkeeper/application.css +10 -2
  3. data/app/controllers/doorkeeper/application_controller.rbc +663 -0
  4. data/app/controllers/doorkeeper/applications_controller.rbc +954 -0
  5. data/app/controllers/doorkeeper/authorizations_controller.rb +8 -1
  6. data/app/controllers/doorkeeper/authorizations_controller.rbc +595 -0
  7. data/app/controllers/doorkeeper/tokens_controller.rbc +423 -0
  8. data/app/helpers/doorkeeper/application_helper.rbc +127 -0
  9. data/app/models/access_grant.rb +10 -2
  10. data/app/models/access_grant.rbc +656 -0
  11. data/app/models/access_token.rbc +781 -0
  12. data/app/models/application.rbc +507 -0
  13. data/app/views/doorkeeper/authorizations/new.html.erb +16 -12
  14. data/app/views/layouts/doorkeeper/application.html.erb +9 -0
  15. data/config/initializers/form_errors.rbc +272 -0
  16. data/config/routes.rbc +322 -0
  17. data/lib/doorkeeper.rbc +407 -0
  18. data/lib/doorkeeper/config.rbc +941 -0
  19. data/lib/doorkeeper/doorkeeper_for.rbc +1029 -0
  20. data/lib/doorkeeper/engine.rbc +318 -0
  21. data/lib/doorkeeper/oauth/access_token_request.rb +9 -2
  22. data/lib/doorkeeper/oauth/access_token_request.rbc +1853 -0
  23. data/lib/doorkeeper/oauth/authorization_request.rb +5 -0
  24. data/lib/doorkeeper/oauth/authorization_request.rbc +2107 -0
  25. data/lib/doorkeeper/oauth/random_string.rbc +437 -0
  26. data/lib/doorkeeper/validations.rbc +774 -0
  27. data/lib/doorkeeper/version.rb +1 -1
  28. data/lib/doorkeeper/version.rbc +130 -0
  29. data/lib/generators/doorkeeper/install_generator.rbc +453 -0
  30. data/lib/generators/doorkeeper/templates/migration.rb +1 -0
  31. data/lib/tasks/doorkeeper_tasks.rake.compiled.rbc +40 -0
  32. metadata +44 -17
data/README.md CHANGED
@@ -2,20 +2,19 @@
2
2
 
3
3
  [![Build Status](https://secure.travis-ci.org/applicake/doorkeeper.png)](http://travis-ci.org/applicake/doorkeeper)
4
4
 
5
- Doorkeeper is a gem that makes it easy to introduce oauth2 provider
6
- functionality to your application.
5
+ Doorkeeper is a gem that makes it easy to introduce OAuth 2 provider functionality to your application.
7
6
 
8
- So far it supports only Authorization Code
9
- flow, but we will gradually introduce other flows.
7
+ So far it supports only Authorization Code flow, but we will [gradually introduce other flows](https://github.com/applicake/doorkeeper/wiki/Supported-Features).
10
8
 
11
- For more information about Oauth2 go to
12
- [Oauth2 Specs (Draft)](http://tools.ietf.org/html/draft-ietf-oauth-v2-22)
9
+ For more information about OAuth 2 go to [OAuth 2 Specs (Draft)](http://tools.ietf.org/html/draft-ietf-oauth-v2-22).
13
10
 
14
11
  ## Installation
15
12
 
16
13
  Put this in your Gemfile:
17
14
 
18
- gem 'doorkeeper'
15
+ ``` ruby
16
+ gem 'doorkeeper'
17
+ ```
19
18
 
20
19
  Run the installation generator with:
21
20
 
@@ -29,10 +28,12 @@ This will generate the doorkeeper initializer and the oauth tables migration. Do
29
28
 
30
29
  The installation will mount the Doorkeeper routes to your app like this:
31
30
 
32
- Rails.application.routes.draw do
33
- mount Doorkeeper::Engine => "/oauth"
34
- # your routes
35
- end
31
+ ``` ruby
32
+ Rails.application.routes.draw do
33
+ mount Doorkeeper::Engine => "/oauth"
34
+ # your routes
35
+ end
36
+ ```
36
37
 
37
38
  This will mount following routes:
38
39
 
@@ -44,63 +45,77 @@ This will mount following routes:
44
45
 
45
46
  You need to configure Doorkeeper in order to provide resource_owner model and authentication block `initializers/doorkeeper.rb`
46
47
 
47
- Doorkeeper.configure do
48
- resource_owner_authenticator do |routes|
49
- current_user || redirect_to('/sign_in', :alert => "Needs sign in.") # returns nil if current_user is not logged in
50
- end
51
- end
48
+ ``` ruby
49
+ Doorkeeper.configure do
50
+ resource_owner_authenticator do |routes|
51
+ current_user || redirect_to('/sign_in', :alert => "Needs sign in.") # returns nil if current_user is not logged in
52
+ end
53
+ end
54
+ ```
52
55
 
53
56
  If you use devise, you may want to use warden to authenticate the block:
54
57
 
55
- resource_owner_authenticator do |routes|
56
- current_user || warden.authenticate!(:scope => :user)
57
- end
58
+ ``` ruby
59
+ resource_owner_authenticator do |routes|
60
+ current_user || warden.authenticate!(:scope => :user)
61
+ end
62
+ ```
58
63
 
59
64
  ## Protecting resources (a.k.a your API endpoint)
60
65
 
61
- In the controller add the before_filter to authorize the token
66
+ In your api controller, add the `doorkeeper_for` to require the oauth token:
62
67
 
63
- class ProtectedResourcesController < ApplicationController
64
- doorkeeper_for :all # For all actions
65
- doorkeeper_for :only => :index # Require token only for index action
66
- doorkeeper_for :except => :show # Require token for all actions except show
67
- end
68
+ ``` 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
68
73
 
69
- ## Creating and using client applications
74
+ # your actions
75
+ end
76
+ ```
70
77
 
71
- To start using OAuth 2 as a client first fire up the server with `rails server`, go to `/oauth/applications` and create an application for your client.
78
+ You don't need to setup any before filter, `doorkeeper_for` will handle that for you.
72
79
 
73
- Choose a name and a callback url for it. If you use oauth2 gem you can specify your just generated client as:
80
+ ## Authenticated resource owner
74
81
 
75
- require 'oauth2'
76
- client_id = '...' # your client's id
77
- client_secret = '...' # your client's secret
78
- redirect_uri = '...' # your client's redirect uri
79
- client = OAuth2::Client.new(
80
- client_id,
81
- client_secret,
82
- :site => "http://localhost:3000"
83
- )
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:
84
83
 
85
- If you changed the default mount path `/oauth` in your `routes.rb` you need to specify it in the oauth client as `:authorize_url` and `:token_url`. For more information, check the oauth2 gem documentation.
84
+ ``` ruby
85
+ class Api::V1::CredentialsController < Api::V1::ApiController
86
+ doorkeeper_for :all
87
+ respond_to :json
86
88
 
87
- After that you can try to request an authorization code with the oauth2 gem as follow:
89
+ # GET /api/v1/me.json
90
+ def me
91
+ respond_with current_resource_owner
92
+ end
88
93
 
89
- client.auth_code.authorize_url(:redirect_uri => redirect_uri)
90
- # => http://localhost:3000/oauth/authorize?response_type=code&client_id=...&redirect_uri=...
94
+ private
91
95
 
92
- If you visit the returned url, you'll see a screen to authorize your app. Click on `authorize` and you'll be redirected to your client redirect url.
96
+ # Find the user that owns the access token
97
+ def current_resource_owner
98
+ User.find(doorkeeper_token.resource_owner_id) if doorkeeper_token
99
+ end
100
+ end
101
+ ```
93
102
 
94
- Grab the code from the redirect url and request a access token with the following:
103
+ ## Other resources
95
104
 
96
- token = client.auth_code.get_token(parms[:code], :redirect_uri => redirect_uri)
105
+ ### Live demo
97
106
 
98
- You now have an access token to access you protected resources.
107
+ Check out this [live demo](http://doorkeeper-provider.herokuapp.com) hosted on heroku. For more demos check out [the wiki](https://github.com/applicake/doorkeeper/wiki/Example-Applications).
99
108
 
100
- ## Contributing/Development
109
+ ### Client applications
101
110
 
102
- Check our [contributing guidelines page in the wiki](https://github.com/applicake/doorkeeper/wiki/Contributing)
111
+ After you set up the provider, you may want to create a client application to test the integration. Check out these [client examples](https://github.com/applicake/doorkeeper/wiki/Example-Applications) in our wiki or follow this [tutorial here](https://github.com/applicake/doorkeeper/wiki/Testing-your-provider-with-OAuth2-gem).
103
112
 
104
- ## Supported ruby versions
113
+ ### Contributing/Development
114
+
115
+ Want to contribute and don't know where to start? Check out [features we're missing](https://github.com/applicake/doorkeeper/wiki/Supported-Features), create [example apps](https://github.com/applicake/doorkeeper/wiki/Example-Applications), integrate the gem with your app and let us know!
116
+
117
+ Also, check out our [contributing guidelines page](https://github.com/applicake/doorkeeper/wiki/Contributing).
118
+
119
+ ### Supported ruby versions
105
120
 
106
121
  All supported ruby versions are [listed here](https://github.com/applicake/doorkeeper/wiki/Supported-Ruby-versions)
@@ -3,5 +3,13 @@
3
3
  * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
4
4
  * the top of the compiled file, but it's generally better to create a new file per style scope.
5
5
  *= require_self
6
- *= require_tree .
7
- */
6
+ *= require_tree .
7
+ */
8
+
9
+ body {
10
+ padding-top: 60px;
11
+ }
12
+
13
+ .inline_block {
14
+ display: inline-block;
15
+ }
@@ -0,0 +1,663 @@
1
+ !RBIX
2
+ 9595534255132031488
3
+ x
4
+ M
5
+ 1
6
+ n
7
+ n
8
+ x
9
+ 10
10
+ __script__
11
+ i
12
+ 28
13
+ 99
14
+ 7
15
+ 0
16
+ 65
17
+ 49
18
+ 1
19
+ 2
20
+ 13
21
+ 99
22
+ 12
23
+ 7
24
+ 2
25
+ 12
26
+ 7
27
+ 3
28
+ 12
29
+ 65
30
+ 12
31
+ 49
32
+ 4
33
+ 4
34
+ 15
35
+ 49
36
+ 2
37
+ 0
38
+ 15
39
+ 2
40
+ 11
41
+ I
42
+ 6
43
+ I
44
+ 0
45
+ I
46
+ 0
47
+ I
48
+ 0
49
+ n
50
+ p
51
+ 5
52
+ x
53
+ 10
54
+ Doorkeeper
55
+ x
56
+ 11
57
+ open_module
58
+ x
59
+ 15
60
+ __module_init__
61
+ M
62
+ 1
63
+ n
64
+ n
65
+ x
66
+ 10
67
+ Doorkeeper
68
+ i
69
+ 33
70
+ 5
71
+ 66
72
+ 99
73
+ 7
74
+ 0
75
+ 45
76
+ 1
77
+ 2
78
+ 43
79
+ 3
80
+ 65
81
+ 49
82
+ 4
83
+ 3
84
+ 13
85
+ 99
86
+ 12
87
+ 7
88
+ 5
89
+ 12
90
+ 7
91
+ 6
92
+ 12
93
+ 65
94
+ 12
95
+ 49
96
+ 7
97
+ 4
98
+ 15
99
+ 49
100
+ 5
101
+ 0
102
+ 11
103
+ I
104
+ 6
105
+ I
106
+ 0
107
+ I
108
+ 0
109
+ I
110
+ 0
111
+ n
112
+ p
113
+ 8
114
+ x
115
+ 21
116
+ ApplicationController
117
+ x
118
+ 16
119
+ ActionController
120
+ n
121
+ x
122
+ 4
123
+ Base
124
+ x
125
+ 10
126
+ open_class
127
+ x
128
+ 14
129
+ __class_init__
130
+ M
131
+ 1
132
+ n
133
+ n
134
+ x
135
+ 21
136
+ ApplicationController
137
+ i
138
+ 62
139
+ 5
140
+ 66
141
+ 5
142
+ 48
143
+ 0
144
+ 15
145
+ 99
146
+ 7
147
+ 1
148
+ 7
149
+ 2
150
+ 65
151
+ 67
152
+ 49
153
+ 3
154
+ 0
155
+ 49
156
+ 4
157
+ 4
158
+ 15
159
+ 99
160
+ 7
161
+ 5
162
+ 7
163
+ 6
164
+ 65
165
+ 67
166
+ 49
167
+ 3
168
+ 0
169
+ 49
170
+ 4
171
+ 4
172
+ 15
173
+ 99
174
+ 7
175
+ 7
176
+ 7
177
+ 8
178
+ 65
179
+ 67
180
+ 49
181
+ 3
182
+ 0
183
+ 49
184
+ 4
185
+ 4
186
+ 15
187
+ 99
188
+ 7
189
+ 9
190
+ 7
191
+ 10
192
+ 65
193
+ 67
194
+ 49
195
+ 3
196
+ 0
197
+ 49
198
+ 4
199
+ 4
200
+ 11
201
+ I
202
+ 5
203
+ I
204
+ 0
205
+ I
206
+ 0
207
+ I
208
+ 0
209
+ n
210
+ p
211
+ 11
212
+ x
213
+ 7
214
+ private
215
+ x
216
+ 28
217
+ authenticate_resource_owner!
218
+ M
219
+ 1
220
+ n
221
+ n
222
+ x
223
+ 28
224
+ authenticate_resource_owner!
225
+ i
226
+ 4
227
+ 5
228
+ 48
229
+ 0
230
+ 11
231
+ I
232
+ 1
233
+ I
234
+ 0
235
+ I
236
+ 0
237
+ I
238
+ 0
239
+ n
240
+ p
241
+ 1
242
+ x
243
+ 22
244
+ current_resource_owner
245
+ p
246
+ 5
247
+ I
248
+ -1
249
+ I
250
+ 5
251
+ I
252
+ 0
253
+ I
254
+ 6
255
+ I
256
+ 4
257
+ x
258
+ 92
259
+ /Users/felipeelias/Applicake/doorkeeper/app/controllers/doorkeeper/application_controller.rb
260
+ p
261
+ 0
262
+ x
263
+ 17
264
+ method_visibility
265
+ x
266
+ 15
267
+ add_defn_method
268
+ x
269
+ 22
270
+ current_resource_owner
271
+ M
272
+ 1
273
+ n
274
+ n
275
+ x
276
+ 22
277
+ current_resource_owner
278
+ i
279
+ 26
280
+ 5
281
+ 5
282
+ 48
283
+ 0
284
+ 45
285
+ 1
286
+ 2
287
+ 49
288
+ 3
289
+ 0
290
+ 13
291
+ 70
292
+ 10
293
+ 21
294
+ 44
295
+ 43
296
+ 4
297
+ 12
298
+ 49
299
+ 5
300
+ 1
301
+ 47
302
+ 50
303
+ 6
304
+ 1
305
+ 11
306
+ I
307
+ 4
308
+ I
309
+ 0
310
+ I
311
+ 0
312
+ I
313
+ 0
314
+ n
315
+ p
316
+ 7
317
+ x
318
+ 8
319
+ main_app
320
+ x
321
+ 10
322
+ Doorkeeper
323
+ n
324
+ x
325
+ 27
326
+ authenticate_resource_owner
327
+ x
328
+ 4
329
+ Proc
330
+ x
331
+ 14
332
+ __from_block__
333
+ x
334
+ 13
335
+ instance_exec
336
+ p
337
+ 5
338
+ I
339
+ -1
340
+ I
341
+ 9
342
+ I
343
+ 0
344
+ I
345
+ a
346
+ I
347
+ 1a
348
+ x
349
+ 92
350
+ /Users/felipeelias/Applicake/doorkeeper/app/controllers/doorkeeper/application_controller.rb
351
+ p
352
+ 0
353
+ x
354
+ 19
355
+ authenticate_admin!
356
+ M
357
+ 1
358
+ n
359
+ n
360
+ x
361
+ 19
362
+ authenticate_admin!
363
+ i
364
+ 35
365
+ 45
366
+ 0
367
+ 1
368
+ 49
369
+ 2
370
+ 0
371
+ 19
372
+ 0
373
+ 9
374
+ 33
375
+ 5
376
+ 5
377
+ 48
378
+ 3
379
+ 20
380
+ 0
381
+ 13
382
+ 70
383
+ 10
384
+ 27
385
+ 44
386
+ 43
387
+ 4
388
+ 12
389
+ 49
390
+ 5
391
+ 1
392
+ 47
393
+ 50
394
+ 6
395
+ 1
396
+ 8
397
+ 34
398
+ 1
399
+ 11
400
+ I
401
+ 5
402
+ I
403
+ 1
404
+ I
405
+ 0
406
+ I
407
+ 0
408
+ n
409
+ p
410
+ 7
411
+ x
412
+ 10
413
+ Doorkeeper
414
+ n
415
+ x
416
+ 18
417
+ authenticate_admin
418
+ x
419
+ 8
420
+ main_app
421
+ x
422
+ 4
423
+ Proc
424
+ x
425
+ 14
426
+ __from_block__
427
+ x
428
+ 13
429
+ instance_exec
430
+ p
431
+ 11
432
+ I
433
+ -1
434
+ I
435
+ d
436
+ I
437
+ 0
438
+ I
439
+ e
440
+ I
441
+ a
442
+ I
443
+ f
444
+ I
445
+ 21
446
+ I
447
+ e
448
+ I
449
+ 22
450
+ I
451
+ 0
452
+ I
453
+ 23
454
+ x
455
+ 92
456
+ /Users/felipeelias/Applicake/doorkeeper/app/controllers/doorkeeper/application_controller.rb
457
+ p
458
+ 1
459
+ x
460
+ 5
461
+ block
462
+ x
463
+ 14
464
+ method_missing
465
+ M
466
+ 1
467
+ n
468
+ n
469
+ x
470
+ 14
471
+ method_missing
472
+ i
473
+ 51
474
+ 95
475
+ 19
476
+ 2
477
+ 15
478
+ 20
479
+ 0
480
+ 7
481
+ 0
482
+ 13
483
+ 70
484
+ 9
485
+ 24
486
+ 15
487
+ 44
488
+ 43
489
+ 1
490
+ 7
491
+ 2
492
+ 78
493
+ 49
494
+ 3
495
+ 2
496
+ 6
497
+ 0
498
+ 49
499
+ 4
500
+ 1
501
+ 9
502
+ 47
503
+ 5
504
+ 7
505
+ 5
506
+ 20
507
+ 0
508
+ 47
509
+ 101
510
+ 6
511
+ 7
512
+ 7
513
+ 63
514
+ 3
515
+ 47
516
+ 49
517
+ 8
518
+ 1
519
+ 8
520
+ 50
521
+ 54
522
+ 89
523
+ 9
524
+ 11
525
+ I
526
+ 7
527
+ I
528
+ 3
529
+ I
530
+ 1
531
+ I
532
+ 1
533
+ I
534
+ 1
535
+ p
536
+ 10
537
+ n
538
+ x
539
+ 6
540
+ Regexp
541
+ s
542
+ 12
543
+ _(url|path)$
544
+ x
545
+ 3
546
+ new
547
+ x
548
+ 2
549
+ =~
550
+ s
551
+ 61
552
+ Your path has not been found. Didn't you mean to call routes.
553
+ x
554
+ 4
555
+ to_s
556
+ s
557
+ 36
558
+ in doorkeeper configuration blocks?
559
+ x
560
+ 5
561
+ raise
562
+ x
563
+ 14
564
+ method_missing
565
+ p
566
+ 11
567
+ I
568
+ -1
569
+ I
570
+ 13
571
+ I
572
+ 4
573
+ I
574
+ 14
575
+ I
576
+ 1d
577
+ I
578
+ 15
579
+ I
580
+ 2f
581
+ I
582
+ 17
583
+ I
584
+ 32
585
+ I
586
+ 0
587
+ I
588
+ 33
589
+ x
590
+ 92
591
+ /Users/felipeelias/Applicake/doorkeeper/app/controllers/doorkeeper/application_controller.rb
592
+ p
593
+ 3
594
+ x
595
+ 6
596
+ method
597
+ x
598
+ 4
599
+ args
600
+ x
601
+ 5
602
+ block
603
+ p
604
+ 11
605
+ I
606
+ 2
607
+ I
608
+ 3
609
+ I
610
+ 6
611
+ I
612
+ 5
613
+ I
614
+ 14
615
+ I
616
+ 9
617
+ I
618
+ 22
619
+ I
620
+ d
621
+ I
622
+ 30
623
+ I
624
+ 13
625
+ I
626
+ 3e
627
+ x
628
+ 92
629
+ /Users/felipeelias/Applicake/doorkeeper/app/controllers/doorkeeper/application_controller.rb
630
+ p
631
+ 0
632
+ x
633
+ 13
634
+ attach_method
635
+ p
636
+ 3
637
+ I
638
+ 2
639
+ I
640
+ 2
641
+ I
642
+ 21
643
+ x
644
+ 92
645
+ /Users/felipeelias/Applicake/doorkeeper/app/controllers/doorkeeper/application_controller.rb
646
+ p
647
+ 0
648
+ x
649
+ 13
650
+ attach_method
651
+ p
652
+ 3
653
+ I
654
+ 0
655
+ I
656
+ 1
657
+ I
658
+ 1c
659
+ x
660
+ 92
661
+ /Users/felipeelias/Applicake/doorkeeper/app/controllers/doorkeeper/application_controller.rb
662
+ p
663
+ 0