doorkeeper 2.1.4 → 3.1.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 (135) hide show
  1. checksums.yaml +4 -4
  2. data/.hound.yml +4 -0
  3. data/.travis.yml +5 -24
  4. data/CONTRIBUTING.md +23 -13
  5. data/Gemfile +3 -7
  6. data/{CHANGELOG.md → NEWS.md} +137 -42
  7. data/README.md +60 -46
  8. data/RELEASING.md +5 -3
  9. data/app/assets/stylesheets/doorkeeper/admin/application.css +1 -5
  10. data/app/controllers/doorkeeper/applications_controller.rb +2 -2
  11. data/app/helpers/doorkeeper/dashboard_helper.rb +1 -1
  12. data/app/validators/redirect_uri_validator.rb +1 -1
  13. data/app/views/doorkeeper/applications/_form.html.erb +13 -2
  14. data/app/views/doorkeeper/applications/show.html.erb +3 -2
  15. data/app/views/doorkeeper/authorizations/new.html.erb +1 -1
  16. data/app/views/layouts/doorkeeper/admin.html.erb +5 -2
  17. data/config/locales/en.yml +4 -32
  18. data/doorkeeper.gemspec +4 -8
  19. data/lib/doorkeeper/config.rb +20 -29
  20. data/lib/doorkeeper/engine.rb +7 -1
  21. data/lib/doorkeeper/errors.rb +12 -0
  22. data/lib/doorkeeper/grape/helpers.rb +1 -1
  23. data/lib/doorkeeper/helpers/controller.rb +6 -0
  24. data/lib/doorkeeper/models/access_grant_mixin.rb +3 -2
  25. data/lib/doorkeeper/models/access_token_mixin.rb +12 -4
  26. data/lib/doorkeeper/models/application_mixin.rb +11 -18
  27. data/lib/doorkeeper/models/concerns/revocable.rb +2 -2
  28. data/lib/doorkeeper/oauth/authorization/token.rb +15 -6
  29. data/lib/doorkeeper/oauth/authorization_code_request.rb +10 -5
  30. data/lib/doorkeeper/oauth/client.rb +9 -8
  31. data/lib/doorkeeper/oauth/client_credentials/creator.rb +3 -4
  32. data/lib/doorkeeper/oauth/error.rb +5 -1
  33. data/lib/doorkeeper/oauth/helpers/scope_checker.rb +1 -1
  34. data/lib/doorkeeper/oauth/refresh_token_request.rb +17 -7
  35. data/lib/doorkeeper/orm/active_record/access_grant.rb +2 -2
  36. data/lib/doorkeeper/orm/active_record/access_token.rb +2 -2
  37. data/lib/doorkeeper/orm/active_record/application.rb +2 -2
  38. data/lib/doorkeeper/orm/active_record.rb +22 -0
  39. data/lib/doorkeeper/rails/helpers.rb +19 -29
  40. data/lib/doorkeeper/request/authorization_code.rb +10 -15
  41. data/lib/doorkeeper/request/client_credentials.rb +9 -15
  42. data/lib/doorkeeper/request/code.rb +7 -13
  43. data/lib/doorkeeper/request/password.rb +10 -15
  44. data/lib/doorkeeper/request/refresh_token.rb +11 -13
  45. data/lib/doorkeeper/request/strategy.rb +17 -0
  46. data/lib/doorkeeper/request/token.rb +7 -13
  47. data/lib/doorkeeper/request.rb +18 -8
  48. data/lib/doorkeeper/server.rb +2 -2
  49. data/lib/doorkeeper/version.rb +1 -1
  50. data/lib/doorkeeper.rb +0 -4
  51. data/lib/generators/doorkeeper/templates/README +0 -20
  52. data/lib/generators/doorkeeper/templates/initializer.rb +5 -3
  53. data/lib/generators/doorkeeper/templates/migration.rb +8 -0
  54. data/spec/controllers/applications_controller_spec.rb +0 -1
  55. data/spec/controllers/protected_resources_controller_spec.rb +115 -14
  56. data/spec/controllers/token_info_controller_spec.rb +0 -4
  57. data/spec/controllers/tokens_controller_spec.rb +34 -3
  58. data/spec/dummy/app/models/user.rb +2 -24
  59. data/spec/dummy/config/application.rb +2 -1
  60. data/spec/dummy/config/initializers/doorkeeper.rb +0 -2
  61. data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +24 -0
  62. data/spec/lib/config_spec.rb +20 -4
  63. data/spec/lib/models/revocable_spec.rb +2 -2
  64. data/spec/lib/oauth/authorization_code_request_spec.rb +1 -1
  65. data/spec/lib/oauth/client/credentials_spec.rb +2 -2
  66. data/spec/lib/oauth/client_credentials/creator_spec.rb +25 -1
  67. data/spec/lib/oauth/error_response_spec.rb +7 -7
  68. data/spec/lib/oauth/error_spec.rb +9 -5
  69. data/spec/lib/oauth/helpers/scope_checker_spec.rb +3 -3
  70. data/spec/lib/oauth/password_access_token_request_spec.rb +1 -1
  71. data/spec/lib/oauth/pre_authorization_spec.rb +9 -10
  72. data/spec/lib/oauth/refresh_token_request_spec.rb +26 -6
  73. data/spec/lib/oauth/scopes_spec.rb +1 -1
  74. data/spec/lib/oauth/token_request_spec.rb +6 -3
  75. data/spec/lib/request/strategy_spec.rb +53 -0
  76. data/spec/lib/server_spec.rb +4 -2
  77. data/spec/models/doorkeeper/access_grant_spec.rb +5 -5
  78. data/spec/models/doorkeeper/access_token_spec.rb +102 -5
  79. data/spec/models/doorkeeper/application_spec.rb +13 -16
  80. data/spec/requests/applications/applications_request_spec.rb +1 -1
  81. data/spec/requests/endpoints/authorization_spec.rb +2 -1
  82. data/spec/requests/endpoints/token_spec.rb +9 -9
  83. data/spec/requests/flows/authorization_code_errors_spec.rb +4 -4
  84. data/spec/requests/flows/authorization_code_spec.rb +36 -2
  85. data/spec/requests/flows/implicit_grant_spec.rb +14 -5
  86. data/spec/requests/flows/password_spec.rb +14 -20
  87. data/spec/requests/flows/refresh_token_spec.rb +15 -7
  88. data/spec/requests/flows/revoke_token_spec.rb +9 -31
  89. data/spec/requests/protected_resources/metal_spec.rb +3 -3
  90. data/spec/requests/protected_resources/private_api_spec.rb +11 -0
  91. data/spec/routing/custom_controller_routes_spec.rb +1 -2
  92. data/spec/routing/default_routes_spec.rb +1 -2
  93. data/spec/routing/scoped_routes_spec.rb +0 -1
  94. data/spec/spec_helper_integration.rb +10 -7
  95. data/spec/support/helpers/access_token_request_helper.rb +1 -1
  96. data/spec/support/helpers/authorization_request_helper.rb +1 -1
  97. data/spec/support/helpers/config_helper.rb +1 -1
  98. data/spec/support/helpers/model_helper.rb +1 -1
  99. data/spec/support/helpers/request_spec_helper.rb +1 -1
  100. data/spec/support/helpers/url_helper.rb +1 -1
  101. data/spec/support/shared/models_shared_examples.rb +1 -1
  102. data/spec/validators/redirect_uri_validator_spec.rb +5 -0
  103. metadata +127 -98
  104. data/gemfiles/Gemfile.common.rb +0 -14
  105. data/gemfiles/Gemfile.mongo_mapper.rb +0 -5
  106. data/gemfiles/Gemfile.mongoid2.rb +0 -5
  107. data/gemfiles/Gemfile.mongoid3.rb +0 -4
  108. data/gemfiles/Gemfile.mongoid4.rb +0 -5
  109. data/lib/doorkeeper/generators/doorkeeper/mongo_mapper/indexes_generator.rb +0 -12
  110. data/lib/doorkeeper/generators/doorkeeper/mongo_mapper/templates/indexes.rb +0 -3
  111. data/lib/doorkeeper/orm/mongo_mapper/access_grant.rb +0 -24
  112. data/lib/doorkeeper/orm/mongo_mapper/access_token.rb +0 -43
  113. data/lib/doorkeeper/orm/mongo_mapper/application.rb +0 -29
  114. data/lib/doorkeeper/orm/mongo_mapper.rb +0 -11
  115. data/lib/doorkeeper/orm/mongoid2/access_grant.rb +0 -22
  116. data/lib/doorkeeper/orm/mongoid2/access_token.rb +0 -37
  117. data/lib/doorkeeper/orm/mongoid2/application.rb +0 -25
  118. data/lib/doorkeeper/orm/mongoid2/concerns/scopes.rb +0 -30
  119. data/lib/doorkeeper/orm/mongoid2.rb +0 -11
  120. data/lib/doorkeeper/orm/mongoid3/access_grant.rb +0 -22
  121. data/lib/doorkeeper/orm/mongoid3/access_token.rb +0 -37
  122. data/lib/doorkeeper/orm/mongoid3/application.rb +0 -25
  123. data/lib/doorkeeper/orm/mongoid3/concerns/scopes.rb +0 -30
  124. data/lib/doorkeeper/orm/mongoid3.rb +0 -11
  125. data/lib/doorkeeper/orm/mongoid4/access_grant.rb +0 -22
  126. data/lib/doorkeeper/orm/mongoid4/access_token.rb +0 -37
  127. data/lib/doorkeeper/orm/mongoid4/application.rb +0 -25
  128. data/lib/doorkeeper/orm/mongoid4/concerns/scopes.rb +0 -17
  129. data/lib/doorkeeper/orm/mongoid4.rb +0 -11
  130. data/spec/dummy/config/mongo.yml +0 -11
  131. data/spec/dummy/config/mongoid2.yml +0 -9
  132. data/spec/dummy/config/mongoid3.yml +0 -18
  133. data/spec/dummy/config/mongoid4.yml +0 -19
  134. data/spec/support/orm/mongo_mapper.rb +0 -10
  135. data/spec/support/orm/mongoid.rb +0 -10
data/README.md CHANGED
@@ -14,24 +14,25 @@ functionality to your Rails or Grape application.
14
14
  ## Documentation valid for `master` branch
15
15
 
16
16
  Please check the documentation for the version of doorkeeper you are using in:
17
- https://github.com/doorkeeper-gem/doorkeeper/releases.
17
+ https://github.com/doorkeeper-gem/doorkeeper/releases
18
18
 
19
19
  ## Table of Contents
20
20
 
21
+ <!-- START doctoc generated TOC please keep comment here to allow auto update -->
22
+ <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
21
23
  - [Useful links](#useful-links)
22
- - [Requirements](#requirements)
23
24
  - [Installation](#installation)
24
25
  - [Configuration](#configuration)
25
26
  - [Active Record](#active-record)
26
- - [Mongoid / MongoMapper](#mongoid--mongomapper)
27
- - [Mongoid indexes](#mongoid-indexes)
28
- - [MongoMapper indexes](#mongomapper-indexes)
27
+ - [Other ORMs](#other-orms)
29
28
  - [Routes](#routes)
30
29
  - [Authenticating](#authenticating)
30
+ - [Internationalization (I18n)](#internationalization-i18n)
31
31
  - [Protecting resources with OAuth (a.k.a your API endpoint)](#protecting-resources-with-oauth-aka-your-api-endpoint)
32
32
  - [Protect your API with OAuth when using Grape](#protect-your-api-with-oauth-when-using-grape)
33
33
  - [Route Constraints and other integrations](#route-constraints-and-other-integrations)
34
34
  - [Access Token Scopes](#access-token-scopes)
35
+ - [Custom Access Token Generator](#custom-access-token-generator)
35
36
  - [Authenticated resource owner](#authenticated-resource-owner)
36
37
  - [Applications list](#applications-list)
37
38
  - [Other customizations](#other-customizations)
@@ -40,23 +41,19 @@ https://github.com/doorkeeper-gem/doorkeeper/releases.
40
41
  - [Contributing](#contributing)
41
42
  - [Other resources](#other-resources)
42
43
  - [Wiki](#wiki)
43
- - [Live demo](#live-demo)
44
44
  - [Screencast](#screencast)
45
45
  - [Client applications](#client-applications)
46
46
  - [Contributors](#contributors)
47
+ - [IETF Standards](#ietf-standards)
47
48
  - [License](#license)
49
+ <!-- END doctoc generated TOC please keep comment here to allow auto update -->
50
+
48
51
 
49
52
  ## Useful links
50
53
 
51
54
  - For documentation, please check out our [wiki](https://github.com/doorkeeper-gem/doorkeeper/wiki)
52
55
  - For general questions, please post it in [stack overflow](http://stackoverflow.com/questions/tagged/doorkeeper)
53
56
 
54
- ## Requirements
55
-
56
- - Ruby >= 2.0.0
57
- - Rails >= 3.2
58
- - ORM ActiveRecord, Mongoid, MongoMapper
59
-
60
57
  ## Installation
61
58
 
62
59
  Put this in your Gemfile:
@@ -84,29 +81,12 @@ Don't forget to run the migration with:
84
81
 
85
82
  rake db:migrate
86
83
 
87
- ### Mongoid / MongoMapper
88
-
89
- Doorkeeper currently supports MongoMapper, Mongoid 2 and 3. To start using it,
90
- you have to set the `orm` configuration:
91
-
92
- ``` ruby
93
- Doorkeeper.configure do
94
- orm :mongoid2 # or :mongoid3, :mongoid4, :mongo_mapper
95
- end
96
- ```
97
-
98
- #### Mongoid indexes
84
+ ### Other ORMs
99
85
 
100
- Make sure you create indexes for doorkeeper models. You can do this either by
101
- running `rake db:mongoid:create_indexes` or (if you're using Mongoid 2) by
102
- adding `autocreate_indexes: true` to your `config/mongoid.yml`
86
+ See [doorkeeper-mongodb project] for mongoid and mongomapper support. Follow along
87
+ the implementation in that repository to extend doorkeeper with other ORMs.
103
88
 
104
- #### MongoMapper indexes
105
-
106
- Generate the `db/indexes.rb` file and create indexes for the doorkeeper models:
107
-
108
- rails generate doorkeeper:mongo_mapper:indexes
109
- rake db:index
89
+ [doorkeeper-mongodb project]: https://github.com/doorkeeper-gem/doorkeeper-mongodb
110
90
 
111
91
  ### Routes
112
92
 
@@ -125,7 +105,6 @@ This will mount following routes:
125
105
  GET /oauth/authorize/:code
126
106
  GET /oauth/authorize
127
107
  POST /oauth/authorize
128
- PUT /oauth/authorize
129
108
  DELETE /oauth/authorize
130
109
  POST /oauth/token
131
110
  POST /oauth/revoke
@@ -158,6 +137,12 @@ the methods defined over there.
158
137
  You may want to check other ways of authentication
159
138
  [here](https://github.com/doorkeeper-gem/doorkeeper/wiki/Authenticating-using-Clearance-or-DIY).
160
139
 
140
+
141
+ ### Internationalization (I18n)
142
+
143
+ See language files in [the I18n repository](https://github.com/doorkeeper-gem/doorkeeper-i18n).
144
+
145
+
161
146
  ## Protecting resources with OAuth (a.k.a your API endpoint)
162
147
 
163
148
  To protect your API with OAuth, you just need to setup `before_action`s
@@ -253,9 +238,42 @@ class Api::V1::ProductsController < Api::V1::ApiController
253
238
  end
254
239
  ```
255
240
 
256
- For a more detailed explanation about scopes usage, check out the related
257
- [page in the
258
- wiki](https://github.com/doorkeeper-gem/doorkeeper/wiki/Using-Scopes).
241
+ Please note that there is a logical OR between multiple required scopes. In
242
+ above example, `doorkeeper_authorize! :admin, :write` means that the access
243
+ token is required to have either `:admin` scope or `:write` scope, but not need
244
+ have both of them.
245
+
246
+ If want to require the access token to have multiple scopes at the same time,
247
+ use multiple `doorkeeper_authorize!`, for example:
248
+
249
+ ```ruby
250
+ class Api::V1::ProductsController < Api::V1::ApiController
251
+ before_action -> { doorkeeper_authorize! :public }, only: :index
252
+ before_action only: [:create, :update, :destroy] do
253
+ doorkeeper_authorize! :admin
254
+ doorkeeper_authorize! :write
255
+ end
256
+ end
257
+ ```
258
+
259
+ In above example, a client can call `:create` action only if its access token
260
+ have both `:admin` and `:write` scopes.
261
+
262
+ ### Custom Access Token Generator
263
+
264
+ By default a 128 bit access token will be generated. If you require a custom
265
+ token, such as [JWT](http://jwt.io), specify an object that responds to
266
+ `.generate(options = {})` and returns a string to be used as the token.
267
+
268
+ ```ruby
269
+ Doorkeeper.configure do
270
+ access_token_generator "Doorkeeper::JWT"
271
+ end
272
+ ```
273
+
274
+ JWT token support is available with
275
+ [Doorkeeper-JWT](https://github.com/chriswarren/doorkeeper-jwt).
276
+
259
277
 
260
278
  ### Authenticated resource owner
261
279
 
@@ -315,7 +333,9 @@ wiki](https://github.com/doorkeeper-gem/doorkeeper/wiki/Customizing-routes).
315
333
  If you want to upgrade doorkeeper to a new version, check out the [upgrading
316
334
  notes](https://github.com/doorkeeper-gem/doorkeeper/wiki/Migration-from-old-versions)
317
335
  and take a look at the
318
- [changelog](https://github.com/doorkeeper-gem/doorkeeper/blob/master/CHANGELOG.md).
336
+ [changelog](https://github.com/doorkeeper-gem/doorkeeper/blob/master/NEWS.md).
337
+
338
+ Doorkeeper follows [semantic versioning](http://semver.org/).
319
339
 
320
340
  ## Development
321
341
 
@@ -353,12 +373,6 @@ page](https://github.com/doorkeeper-gem/doorkeeper/wiki/Contributing).
353
373
  You can find everything about doorkeeper in our [wiki
354
374
  here](https://github.com/doorkeeper-gem/doorkeeper/wiki).
355
375
 
356
- ### Live demo
357
-
358
- Check out this [live demo](http://doorkeeper-provider.herokuapp.com) hosted on
359
- heroku. For more demos check out [the
360
- wiki](https://github.com/doorkeeper-gem/doorkeeper/wiki/Example-Applications).
361
-
362
376
  ### Screencast
363
377
 
364
378
  Check out this screencast from [railscasts.com](http://railscasts.com/): [#353
@@ -376,15 +390,15 @@ here](https://github.com/doorkeeper-gem/doorkeeper/wiki/Testing-your-provider-wi
376
390
  ### Contributors
377
391
 
378
392
  Thanks to all our [awesome
379
- contributors](https://github.com/doorkeeper-gem/doorkeeper/contributors)!
393
+ contributors](https://github.com/doorkeeper-gem/doorkeeper/graphs/contributors)!
380
394
 
381
395
 
382
396
  ### IETF Standards
383
397
 
384
398
  * [The OAuth 2.0 Authorization Framework](http://tools.ietf.org/html/rfc6749)
385
399
  * [OAuth 2.0 Threat Model and Security Considerations](http://tools.ietf.org/html/rfc6819)
400
+ * [OAuth 2.0 Token Revocation](http://tools.ietf.org/html/rfc7009)
386
401
 
387
402
  ### License
388
403
 
389
404
  MIT License. Copyright 2011 Applicake.
390
- [http://applicake.com](http://applicake.com)
data/RELEASING.md CHANGED
@@ -1,15 +1,17 @@
1
1
  # Releasing doorkeeper
2
2
 
3
3
  1. Update `lib/doorkeeper/version.rb` file accordingly.
4
- 2. Update `CHANGELOG.md` to reflect the changes since last release.
4
+ 2. Update `NEWS.md` to reflect the changes since last release.
5
5
  3. Commit changes. There shouldn’t be code changes, and thus CI doesn’t need to
6
6
  run, you can then add “[ci skip]” to the commit message.
7
- 4. Tag the release: `git tag vVERSION`
8
- 5. Push changes: `git push --tags`
7
+ 4. Tag the release: `git tag vVERSION -m "Release vVERSION"`
8
+ 5. Push changes: `git push && git push --tags`
9
9
  6. Build and publish the gem:
10
+
10
11
  ```bash
11
12
  gem build doorkeeper.gemspec
12
13
  gem push doorkeeper-*.gem
13
14
  ```
15
+
14
16
  7. Announce the new release, making sure to say “thank you” to the contributors
15
17
  who helped shape this version!
@@ -5,10 +5,6 @@
5
5
  *= require_tree .
6
6
  */
7
7
 
8
- body {
9
- padding-top: 60px;
10
- }
11
-
12
8
  td {
13
- vertical-align: middle !important;
9
+ vertical-align: middle !important;
14
10
  }
@@ -45,9 +45,9 @@ module Doorkeeper
45
45
 
46
46
  def application_params
47
47
  if params.respond_to?(:permit)
48
- params.require(:doorkeeper_application).permit(:name, :redirect_uri)
48
+ params.require(:doorkeeper_application).permit(:name, :redirect_uri, :scopes)
49
49
  else
50
- params[:doorkeeper_application].slice(:name, :redirect_uri) rescue nil
50
+ params[:doorkeeper_application].slice(:name, :redirect_uri, :scopes) rescue nil
51
51
  end
52
52
  end
53
53
  end
@@ -5,7 +5,7 @@ module Doorkeeper::DashboardHelper
5
5
  content_tag(:span, class: 'help-block') do
6
6
  msg.capitalize
7
7
  end
8
- end.reduce(&:join).html_safe
8
+ end.join.html_safe
9
9
  end
10
10
  end
11
11
 
@@ -29,6 +29,6 @@ class RedirectUriValidator < ActiveModel::EachValidator
29
29
 
30
30
  def invalid_ssl_uri?(uri)
31
31
  forces_ssl = Doorkeeper.configuration.force_ssl_in_redirect_uri
32
- forces_ssl && uri.try(:scheme) != 'https'
32
+ forces_ssl && uri.try(:scheme) == 'http'
33
33
  end
34
34
  end
@@ -17,8 +17,8 @@
17
17
  <%= f.text_area :redirect_uri, class: 'form-control' %>
18
18
  <%= doorkeeper_errors_for application, :redirect_uri %>
19
19
  <span class="help-block">
20
- <%= t('doorkeeper.applications.help.redirect_uri') %>
21
- </span>
20
+ <%= t('doorkeeper.applications.help.redirect_uri') %>
21
+ </span>
22
22
  <% if Doorkeeper.configuration.native_redirect_uri %>
23
23
  <span class="help-block">
24
24
  <%= raw t('doorkeeper.applications.help.native_redirect_uri', native_redirect_uri: "<code>#{ Doorkeeper.configuration.native_redirect_uri }</code>") %>
@@ -27,6 +27,17 @@
27
27
  </div>
28
28
  <% end %>
29
29
 
30
+ <%= content_tag :div, class: "form-group#{' has-error' if application.errors[:scopes].present?}" do %>
31
+ <%= f.label :scopes, class: 'col-sm-2 control-label' %>
32
+ <div class="col-sm-10">
33
+ <%= f.text_field :scopes, class: 'form-control' %>
34
+ <%= doorkeeper_errors_for application, :scopes %>
35
+ <span class="help-block">
36
+ <%= t('doorkeeper.applications.help.scopes') %>
37
+ </span>
38
+ </div>
39
+ <% end %>
40
+
30
41
  <div class="form-group">
31
42
  <div class="col-sm-offset-2 col-sm-10">
32
43
  <%= f.submit t('doorkeeper.applications.buttons.submit'), class: "btn btn-primary" %>
@@ -5,13 +5,14 @@
5
5
  <div class="row">
6
6
  <div class="col-md-8">
7
7
  <h4><%= t('.application_id') %>:</h4>
8
-
9
8
  <p><code id="application_id"><%= @application.uid %></code></p>
10
9
 
11
10
  <h4><%= t('.secret') %>:</h4>
12
-
13
11
  <p><code id="secret"><%= @application.secret %></code></p>
14
12
 
13
+ <h4><%= t('.scopes') %>:</h4>
14
+ <p><code id="scopes"><%= @application.scopes %></code></p>
15
+
15
16
  <h4><%= t('.callback_urls') %>:</h4>
16
17
 
17
18
  <table>
@@ -7,7 +7,7 @@
7
7
  <%= raw t('.prompt', client_name: "<strong class=\"text-info\">#{ @pre_auth.client.name }</strong>") %>
8
8
  </p>
9
9
 
10
- <% if @pre_auth.scopes %>
10
+ <% if @pre_auth.scopes.count > 0 %>
11
11
  <div id="oauth-permissions">
12
12
  <p><%= t('.able_to') %>:</p>
13
13
 
@@ -9,8 +9,8 @@
9
9
  <%= csrf_meta_tags %>
10
10
  </head>
11
11
  <body>
12
- <div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
13
- <div class="container">
12
+ <div class="navbar navbar-inverse navbar-static-top" role="navigation">
13
+ <div class="container-fluid">
14
14
  <div class="navbar-header">
15
15
  <%= link_to t('doorkeeper.layouts.admin.nav.oauth2_provider'), oauth_applications_path, class: 'navbar-brand' %>
16
16
  </div>
@@ -18,6 +18,9 @@
18
18
  <%= content_tag :li, class: "#{'active' if request.path == oauth_applications_path}" do %>
19
19
  <%= link_to t('doorkeeper.layouts.admin.nav.applications'), oauth_applications_path %>
20
20
  <% end %>
21
+ <%= content_tag :li do %>
22
+ <%= link_to 'Home', root_path %>
23
+ <% end %>
21
24
  </ul>
22
25
  </div>
23
26
  </div>
@@ -14,36 +14,6 @@ en:
14
14
  relative_uri: 'must be an absolute URI.'
15
15
  secured_uri: 'must be an HTTPS/SSL URI.'
16
16
 
17
- mongoid:
18
- attributes:
19
- doorkeeper/application:
20
- name: 'Name'
21
- redirect_uri: 'Redirect URI'
22
- errors:
23
- models:
24
- doorkeeper/application:
25
- attributes:
26
- redirect_uri:
27
- fragment_present: 'cannot contain a fragment.'
28
- invalid_uri: 'must be a valid URI.'
29
- relative_uri: 'must be an absolute URI.'
30
- secured_uri: 'must be an HTTPS/SSL URI.'
31
-
32
- mongo_mapper:
33
- attributes:
34
- doorkeeper/application:
35
- name: 'Name'
36
- redirect_uri: 'Redirect URI'
37
- errors:
38
- models:
39
- doorkeeper/application:
40
- attributes:
41
- redirect_uri:
42
- fragment_present: 'cannot contain a fragment.'
43
- invalid_uri: 'must be a valid URI.'
44
- relative_uri: 'must be an absolute URI.'
45
- secured_uri: 'must be an HTTPS/SSL URI.'
46
-
47
17
  doorkeeper:
48
18
  applications:
49
19
  confirmations:
@@ -59,6 +29,7 @@ en:
59
29
  help:
60
30
  redirect_uri: 'Use one line per URI'
61
31
  native_redirect_uri: 'Use %{native_redirect_uri} for local tests'
32
+ scopes: 'Separate scopes with spaces. Leave blank to use the default scopes.'
62
33
  edit:
63
34
  title: 'Edit application'
64
35
  index:
@@ -72,6 +43,7 @@ en:
72
43
  title: 'Application: %{name}'
73
44
  application_id: 'Application Id'
74
45
  secret: 'Secret'
46
+ scopes: 'Scopes'
75
47
  callback_urls: 'Callback urls'
76
48
  actions: 'Actions'
77
49
 
@@ -82,7 +54,7 @@ en:
82
54
  error:
83
55
  title: 'An error has occurred'
84
56
  new:
85
- title: 'Authorize required'
57
+ title: 'Authorization required'
86
58
  prompt: 'Authorize %{client_name} to use your account?'
87
59
  able_to: 'This application will be able to'
88
60
  show:
@@ -148,4 +120,4 @@ en:
148
120
  oauth2_provider: 'OAuth2 Provider'
149
121
  applications: 'Applications'
150
122
  application:
151
- title: 'OAuth authorize required'
123
+ title: 'OAuth authorization required'
data/doorkeeper.gemspec CHANGED
@@ -8,24 +8,20 @@ Gem::Specification.new do |s|
8
8
  s.authors = ["Felipe Elias Philipp", "Tute Costa"]
9
9
  s.email = %w(tutecosta@gmail.com)
10
10
  s.homepage = "https://github.com/doorkeeper-gem/doorkeeper"
11
- s.summary = "Doorkeeper is an OAuth 2 provider for Rails."
12
- s.description = "Doorkeeper is an OAuth 2 provider for Rails."
11
+ s.summary = "OAuth 2 provider for Rails and Grape"
12
+ s.description = "Doorkeeper is an OAuth 2 provider for Rails and Grape."
13
13
  s.license = 'MIT'
14
14
 
15
15
  s.files = `git ls-files`.split("\n")
16
- s.test_files = `git ls-files -- test/*`.split("\n")
16
+ s.test_files = `git ls-files -- spec/*`.split("\n")
17
17
  s.require_paths = ["lib"]
18
18
 
19
19
  s.add_dependency "railties", ">= 3.2"
20
20
 
21
- s.add_development_dependency "sqlite3", "~> 1.3.5"
22
- s.add_development_dependency "rspec-rails", "~> 2.99.0"
21
+ s.add_development_dependency "rspec-rails", "~> 3.4.0"
23
22
  s.add_development_dependency "capybara", "~> 2.3.0"
24
23
  s.add_development_dependency "generator_spec", "~> 0.9.0"
25
24
  s.add_development_dependency "factory_girl", "~> 4.5.0"
26
25
  s.add_development_dependency "timecop", "~> 0.7.0"
27
26
  s.add_development_dependency "database_cleaner", "~> 1.3.0"
28
- s.add_development_dependency "rspec-activemodel-mocks", "~> 1.0.0"
29
- s.add_development_dependency "bcrypt-ruby", "~> 3.0.1"
30
- s.add_development_dependency "pry", "~> 0.10.0"
31
27
  end
@@ -7,54 +7,38 @@ module Doorkeeper
7
7
 
8
8
  def self.configure(&block)
9
9
  @config = Config::Builder.new(&block).build
10
- enable_orm
11
- check_for_missing_columns
10
+ setup_orm_adapter
11
+ setup_orm_models
12
12
  setup_application_owner if @config.enable_application_owner?
13
+ check_requirements
13
14
  end
14
15
 
15
16
  def self.configuration
16
17
  @config || (fail MissingConfiguration.new)
17
18
  end
18
19
 
19
- def self.check_for_missing_columns
20
- if Doorkeeper.configuration.orm == :active_record &&
21
- ActiveRecord::Base.connected? &&
22
- ActiveRecord::Base.connection.table_exists?(
23
- Doorkeeper::Application.table_name
24
- ) &&
25
- !Doorkeeper::Application.new.attributes.include?("scopes")
26
-
27
- puts <<-MSG.squish
28
- [doorkeeper] Missing column: `oauth_applications.scopes`.
29
- If you are using ActiveRecord run `rails generate doorkeeper:application_scopes
30
- && rake db:migrate` to add it.
31
- MSG
32
- end
20
+ def self.check_requirements
21
+ @orm_adapter.check_requirements!(configuration)
33
22
  end
34
23
 
35
- def self.enable_orm
36
- class_name = "doorkeeper/orm/#{configuration.orm}".classify
37
- class_name.constantize.initialize_models!
24
+ def self.setup_orm_adapter
25
+ @orm_adapter = "doorkeeper/orm/#{configuration.orm}".classify.constantize
38
26
  rescue NameError => e
39
- if e.instance_of?(NameError)
40
- fail e, "ORM adapter not found (#{configuration.orm})", <<-error_msg
27
+ fail e, "ORM adapter not found (#{configuration.orm})", <<-ERROR_MSG.squish
41
28
  [doorkeeper] ORM adapter not found (#{configuration.orm}), or there was an error
42
29
  trying to load it.
43
30
 
44
31
  You probably need to add the related gem for this adapter to work with
45
32
  doorkeeper.
33
+ ERROR_MSG
34
+ end
46
35
 
47
- If you are working on the adapter itself, double check that the constant exists,
48
- and that your `initialize_models!` method doesn't raise any errors.\n
49
- error_msg
50
- else
51
- raise e
52
- end
36
+ def self.setup_orm_models
37
+ @orm_adapter.initialize_models!
53
38
  end
54
39
 
55
40
  def self.setup_application_owner
56
- require File.join(File.dirname(__FILE__), 'models', 'concerns', 'ownership')
57
- Application.send :include, Models::Ownership
41
+ @orm_adapter.initialize_application_owner!
58
42
  end
59
43
 
60
44
  class Config
@@ -108,6 +92,12 @@ and that your `initialize_models!` method doesn't raise any errors.\n
108
92
  def force_ssl_in_redirect_uri(boolean)
109
93
  @config.instance_variable_set("@force_ssl_in_redirect_uri", boolean)
110
94
  end
95
+
96
+ def access_token_generator(access_token_generator)
97
+ @config.instance_variable_set(
98
+ '@access_token_generator', access_token_generator
99
+ )
100
+ end
111
101
  end
112
102
 
113
103
  module Option
@@ -198,6 +188,7 @@ and that your `initialize_models!` method doesn't raise any errors.\n
198
188
  option :realm, default: 'Doorkeeper'
199
189
  option :force_ssl_in_redirect_uri, default: !Rails.env.development?
200
190
  option :grant_flows, default: %w(authorization_code client_credentials)
191
+ option :access_token_generator, default: "Doorkeeper::OAuth::Helpers::UniqueToken"
201
192
 
202
193
  attr_reader :reuse_access_token
203
194
 
@@ -1,7 +1,13 @@
1
1
  module Doorkeeper
2
2
  class Engine < Rails::Engine
3
3
  initializer "doorkeeper.params.filter" do |app|
4
- app.config.filter_parameters += %i(client_secret code token)
4
+ app.config.filter_parameters += [:client_secret, :code, :token]
5
+ end
6
+
7
+ initializer "doorkeeper.locales" do |app|
8
+ if app.config.i18n.fallbacks.blank?
9
+ app.config.i18n.fallbacks = [:en]
10
+ end
5
11
  end
6
12
 
7
13
  initializer "doorkeeper.routes" do
@@ -6,10 +6,22 @@ module Doorkeeper
6
6
  class InvalidAuthorizationStrategy < DoorkeeperError
7
7
  end
8
8
 
9
+ class InvalidTokenReuse < DoorkeeperError
10
+ end
11
+
12
+ class InvalidGrantReuse < DoorkeeperError
13
+ end
14
+
9
15
  class InvalidTokenStrategy < DoorkeeperError
10
16
  end
11
17
 
12
18
  class MissingRequestStrategy < DoorkeeperError
13
19
  end
20
+
21
+ class UnableToGenerateToken < DoorkeeperError
22
+ end
23
+
24
+ class TokenGeneratorNotFound < DoorkeeperError
25
+ end
14
26
  end
15
27
  end
@@ -26,7 +26,7 @@ module Doorkeeper
26
26
  403
27
27
  end
28
28
 
29
- error!({ error: error.description }, status_code)
29
+ error!({ error: error.description }, status_code, error.headers)
30
30
  end
31
31
 
32
32
  private
@@ -41,6 +41,12 @@ module Doorkeeper
41
41
  :unsupported_response_type
42
42
  when Errors::MissingRequestStrategy
43
43
  :invalid_request
44
+ when Errors::InvalidTokenReuse
45
+ :invalid_request
46
+ when Errors::InvalidGrantReuse
47
+ :invalid_grant
48
+ when Errors::DoorkeeperError
49
+ exception.message
44
50
  end
45
51
 
46
52
  OAuth::ErrorResponse.new name: error_name, state: params[:state]
@@ -7,11 +7,12 @@ module Doorkeeper
7
7
  include Models::Revocable
8
8
  include Models::Accessible
9
9
  include Models::Scopes
10
+ include ActiveModel::MassAssignmentSecurity if defined?(::ProtectedAttributes)
10
11
 
11
12
  included do
12
13
  belongs_to :application, class_name: 'Doorkeeper::Application', inverse_of: :access_grants
13
14
 
14
- if ::Rails.version.to_i < 4 || defined?(::ProtectedAttributes)
15
+ if respond_to?(:attr_accessible)
15
16
  attr_accessible :resource_owner_id, :application_id, :expires_in, :redirect_uri, :scopes
16
17
  end
17
18
 
@@ -23,7 +24,7 @@ module Doorkeeper
23
24
 
24
25
  module ClassMethods
25
26
  def by_token(token)
26
- where(token: token).limit(1).to_a.first
27
+ where(token: token.to_s).limit(1).to_a.first
27
28
  end
28
29
  end
29
30
 
@@ -7,6 +7,7 @@ module Doorkeeper
7
7
  include Models::Revocable
8
8
  include Models::Accessible
9
9
  include Models::Scopes
10
+ include ActiveModel::MassAssignmentSecurity if defined?(::ProtectedAttributes)
10
11
 
11
12
  included do
12
13
  belongs_to :application,
@@ -18,7 +19,7 @@ module Doorkeeper
18
19
 
19
20
  attr_writer :use_refresh_token
20
21
 
21
- if ::Rails.version.to_i < 4 || defined?(::ProtectedAttributes)
22
+ if respond_to?(:attr_accessible)
22
23
  attr_accessible :application_id, :resource_owner_id, :expires_in,
23
24
  :scopes, :use_refresh_token
24
25
  end
@@ -31,11 +32,11 @@ module Doorkeeper
31
32
 
32
33
  module ClassMethods
33
34
  def by_token(token)
34
- where(token: token).limit(1).to_a.first
35
+ where(token: token.to_s).limit(1).to_a.first
35
36
  end
36
37
 
37
38
  def by_refresh_token(refresh_token)
38
- where(refresh_token: refresh_token).first
39
+ where(refresh_token: refresh_token.to_s).first
39
40
  end
40
41
 
41
42
  def revoke_all_for(application_id, resource_owner)
@@ -128,7 +129,14 @@ module Doorkeeper
128
129
  end
129
130
 
130
131
  def generate_token
131
- self.token = UniqueToken.generate
132
+ generator = Doorkeeper.configuration.access_token_generator.constantize
133
+ self.token = generator.generate(resource_owner_id: resource_owner_id,
134
+ scopes: scopes, application: application,
135
+ expires_in: expires_in)
136
+ rescue NoMethodError
137
+ raise Errors::UnableToGenerateToken, "#{generator} does not respond to `.generate`."
138
+ rescue NameError
139
+ raise Errors::TokenGeneratorNotFound, "#{generator} not found"
132
140
  end
133
141
  end
134
142
  end