doorkeeper 1.4.1 → 2.0.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 (127) hide show
  1. checksums.yaml +4 -4
  2. data/.hound.yml +3 -0
  3. data/.travis.yml +38 -10
  4. data/CHANGELOG.md +43 -1
  5. data/CONTRIBUTING.md +35 -0
  6. data/Gemfile +4 -26
  7. data/README.md +21 -55
  8. data/Rakefile +3 -1
  9. data/app/controllers/doorkeeper/application_controller.rb +2 -2
  10. data/app/controllers/doorkeeper/applications_controller.rb +4 -5
  11. data/app/controllers/doorkeeper/authorizations_controller.rb +4 -2
  12. data/app/controllers/doorkeeper/tokens_controller.rb +2 -2
  13. data/app/helpers/doorkeeper/{form_errors_helper.rb → dashboard_helper.rb} +5 -1
  14. data/app/validators/redirect_uri_validator.rb +6 -0
  15. data/app/views/doorkeeper/applications/_delete_form.html.erb +1 -1
  16. data/app/views/doorkeeper/applications/_form.html.erb +3 -3
  17. data/app/views/doorkeeper/applications/index.html.erb +1 -1
  18. data/config/locales/en.yml +6 -3
  19. data/doorkeeper.gemspec +3 -3
  20. data/gemfiles/Gemfile.common.rb +11 -0
  21. data/gemfiles/Gemfile.mongo_mapper.rb +5 -0
  22. data/gemfiles/Gemfile.mongoid2.rb +5 -0
  23. data/gemfiles/Gemfile.mongoid3.rb +4 -0
  24. data/gemfiles/Gemfile.mongoid4.rb +5 -0
  25. data/lib/doorkeeper/config.rb +34 -24
  26. data/lib/doorkeeper/engine.rb +1 -2
  27. data/lib/doorkeeper/generators/doorkeeper/mongo_mapper/indexes_generator.rb +12 -0
  28. data/lib/doorkeeper/models/access_grant_mixin.rb +36 -0
  29. data/lib/doorkeeper/models/access_token_mixin.rb +122 -0
  30. data/lib/doorkeeper/models/application_mixin.rb +60 -0
  31. data/lib/doorkeeper/models/{expirable.rb → concerns/expirable.rb} +6 -5
  32. data/lib/doorkeeper/models/{ownership.rb → concerns/ownership.rb} +7 -7
  33. data/lib/doorkeeper/models/{revocable.rb → concerns/revocable.rb} +1 -1
  34. data/lib/doorkeeper/models/concerns/scopes.rb +17 -0
  35. data/lib/doorkeeper/oauth/authorization/token.rb +6 -6
  36. data/lib/doorkeeper/oauth/client.rb +1 -1
  37. data/lib/doorkeeper/oauth/password_access_token_request.rb +3 -3
  38. data/lib/doorkeeper/oauth/pre_authorization.rb +5 -1
  39. data/lib/doorkeeper/oauth/refresh_token_request.rb +6 -6
  40. data/lib/doorkeeper/oauth/scopes.rb +6 -1
  41. data/lib/doorkeeper/oauth/token.rb +3 -2
  42. data/lib/doorkeeper/orm/active_record/access_grant.rb +7 -0
  43. data/lib/doorkeeper/orm/active_record/access_token.rb +21 -0
  44. data/lib/doorkeeper/{models → orm}/active_record/application.rb +1 -3
  45. data/lib/doorkeeper/orm/active_record.rb +17 -0
  46. data/lib/doorkeeper/{models → orm}/mongo_mapper/access_grant.rb +4 -5
  47. data/lib/doorkeeper/{models → orm}/mongo_mapper/access_token.rb +12 -17
  48. data/lib/doorkeeper/{models → orm}/mongo_mapper/application.rb +3 -4
  49. data/lib/doorkeeper/orm/mongo_mapper.rb +11 -0
  50. data/lib/doorkeeper/{models → orm}/mongoid2/access_grant.rb +5 -3
  51. data/lib/doorkeeper/{models → orm}/mongoid2/access_token.rb +10 -12
  52. data/lib/doorkeeper/{models → orm}/mongoid2/application.rb +3 -0
  53. data/lib/doorkeeper/orm/mongoid2/concerns/scopes.rb +30 -0
  54. data/lib/doorkeeper/orm/mongoid2.rb +11 -0
  55. data/lib/doorkeeper/orm/mongoid3/access_grant.rb +22 -0
  56. data/lib/doorkeeper/orm/mongoid3/access_token.rb +37 -0
  57. data/lib/doorkeeper/{models/mongoid3_4 → orm/mongoid3}/application.rb +3 -0
  58. data/lib/doorkeeper/orm/mongoid3/concerns/scopes.rb +30 -0
  59. data/lib/doorkeeper/orm/mongoid3.rb +11 -0
  60. data/lib/doorkeeper/orm/mongoid4/access_grant.rb +22 -0
  61. data/lib/doorkeeper/orm/mongoid4/access_token.rb +37 -0
  62. data/lib/doorkeeper/orm/mongoid4/application.rb +25 -0
  63. data/lib/doorkeeper/orm/mongoid4/concerns/scopes.rb +17 -0
  64. data/lib/doorkeeper/orm/mongoid4.rb +11 -0
  65. data/lib/doorkeeper/rails/helpers.rb +63 -0
  66. data/lib/doorkeeper/rails/routes.rb +1 -12
  67. data/lib/doorkeeper/request/code.rb +0 -1
  68. data/lib/doorkeeper/request/token.rb +0 -1
  69. data/lib/doorkeeper/server.rb +1 -1
  70. data/lib/doorkeeper/version.rb +1 -1
  71. data/lib/doorkeeper.rb +15 -6
  72. data/lib/generators/doorkeeper/application_owner_generator.rb +4 -1
  73. data/lib/generators/doorkeeper/application_scopes_generator.rb +34 -0
  74. data/lib/generators/doorkeeper/templates/add_scopes_to_oauth_applications.rb +5 -0
  75. data/lib/generators/doorkeeper/templates/initializer.rb +8 -1
  76. data/lib/generators/doorkeeper/templates/migration.rb +1 -0
  77. data/lib/generators/doorkeeper/views_generator.rb +4 -5
  78. data/spec/controllers/applications_controller_spec.rb +7 -7
  79. data/spec/controllers/protected_resources_controller_spec.rb +25 -175
  80. data/spec/controllers/tokens_controller_spec.rb +15 -9
  81. data/spec/dummy/app/controllers/full_protected_resources_controller.rb +2 -2
  82. data/spec/dummy/app/controllers/metal_controller.rb +2 -2
  83. data/spec/dummy/app/controllers/semi_protected_resources_controller.rb +2 -2
  84. data/spec/dummy/app/models/user.rb +5 -5
  85. data/spec/dummy/config/application.rb +3 -1
  86. data/spec/dummy/config/boot.rb +4 -1
  87. data/spec/dummy/db/development.sqlite3 +0 -0
  88. data/spec/dummy/db/migrate/20141209001746_add_scopes_to_oauth_applications.rb +5 -0
  89. data/spec/dummy/db/schema.rb +41 -40
  90. data/spec/factories.rb +24 -0
  91. data/spec/lib/config_spec.rb +30 -10
  92. data/spec/lib/models/expirable_spec.rb +1 -1
  93. data/spec/lib/models/revocable_spec.rb +8 -3
  94. data/spec/lib/models/scopes_spec.rb +3 -3
  95. data/spec/lib/oauth/client_spec.rb +1 -1
  96. data/spec/lib/oauth/password_access_token_request_spec.rb +1 -1
  97. data/spec/lib/oauth/pre_authorization_spec.rb +43 -9
  98. data/spec/lib/oauth/token_request_spec.rb +28 -1
  99. data/spec/lib/oauth/token_spec.rb +1 -1
  100. data/spec/models/doorkeeper/application_spec.rb +16 -1
  101. data/spec/requests/applications/applications_request_spec.rb +6 -4
  102. data/spec/requests/flows/implicit_grant_spec.rb +32 -0
  103. data/spec/requests/flows/refresh_token_spec.rb +12 -3
  104. data/spec/spec_helper_integration.rb +8 -2
  105. data/spec/support/shared/controllers_shared_context.rb +2 -2
  106. data/spec/validators/redirect_uri_validator_spec.rb +30 -3
  107. metadata +52 -39
  108. data/lib/doorkeeper/doorkeeper_for.rb +0 -69
  109. data/lib/doorkeeper/helpers/filter.rb +0 -64
  110. data/lib/doorkeeper/models/access_grant.rb +0 -30
  111. data/lib/doorkeeper/models/access_token.rb +0 -106
  112. data/lib/doorkeeper/models/active_record/access_grant.rb +0 -9
  113. data/lib/doorkeeper/models/active_record/access_token.rb +0 -25
  114. data/lib/doorkeeper/models/application.rb +0 -40
  115. data/lib/doorkeeper/models/mongoid/scopes.rb +0 -15
  116. data/lib/doorkeeper/models/mongoid/version.rb +0 -15
  117. data/lib/doorkeeper/models/mongoid3_4/access_grant.rb +0 -27
  118. data/lib/doorkeeper/models/mongoid3_4/access_token.rb +0 -46
  119. data/lib/doorkeeper/models/scopes.rb +0 -21
  120. data/lib/generators/doorkeeper/mongo_mapper/indexes_generator.rb +0 -12
  121. data/script/rails +0 -5
  122. data/script/run_all +0 -14
  123. data/spec/factories/access_grant.rb +0 -9
  124. data/spec/factories/access_token.rb +0 -11
  125. data/spec/factories/application.rb +0 -6
  126. /data/lib/{generators/doorkeeper → doorkeeper/generators/doorkeeper/mongo_mapper}/templates/indexes.rb +0 -0
  127. /data/lib/doorkeeper/models/{accessible.rb → concerns/accessible.rb} +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3980ae7bb2071ab9aa5f29952fc42fd5b04c0d7e
4
- data.tar.gz: 71725d944d80d72391f12ab12056f28ae3a6e963
3
+ metadata.gz: bb6985f71c5db8c5a96f9205a290aa6d36956177
4
+ data.tar.gz: 4d96f1493d890735bdeaf379c6345a949ecd0857
5
5
  SHA512:
6
- metadata.gz: 48254ea12523bc9c00a1e07b512987357887453d490f9dac13b1266044c674fb713089abacb3e8213b5d1e8f1038d82d4ad8a9024f6cc9be93b11a679203d935
7
- data.tar.gz: fa222e77888ed9373bb60e50981ba91bfeb301f548b4c8a0286593a94a6cb358a23acde563b91fde38b07e23c37b523f86c93b1b6f1bc6c18218b83d13dfa8c9
6
+ metadata.gz: 0efb46569e591675b5a208a7cae0d72eb746a17ea99573359e7788374afdcc9b052ef38577abba6681aecb89ddc95e7d6dc0b09bb7201beeb2ac0c4f671d899f
7
+ data.tar.gz: c3786d7fb5f6c2867fddd0d67948bfdc0292451f82aec9fcb1075b08d37c1a439028984c11e2100f1a2cff7ddd8e223e0da8dfb11ae511085bec9fa9b5c1486a
data/.hound.yml CHANGED
@@ -4,3 +4,6 @@ LineLength:
4
4
 
5
5
  StringLiterals:
6
6
  Enabled: false
7
+
8
+ TrailingBlankLines:
9
+ Enabled: true
data/.travis.yml CHANGED
@@ -1,18 +1,46 @@
1
1
  language: ruby
2
+ sudo: false
3
+ cache: bundler
4
+
2
5
  rvm:
3
6
  - 1.9.3
4
7
  - 2.0
5
8
  - 2.1
9
+
6
10
  env:
7
- - rails=3.1.12
8
- - rails=3.2.18
9
- - rails=4.0.5
10
- - rails=4.1.1
11
- - orm=mongoid2
12
- - orm=mongoid3
13
- - orm=mongoid4
14
- - orm=mongo_mapper
15
- - table_name_prefix=h_
16
- - table_name_suffix=_h
11
+ # - rails=3.1 # Don't need it in the CI matrix
12
+ - rails=3.2.0
13
+ - rails=4.0.0
14
+ - rails=4.1.0
15
+ - rails=4.2.0.rc2
16
+
17
+ gemfile:
18
+ - Gemfile
19
+ - gemfiles/Gemfile.mongoid2.rb
20
+ - gemfiles/Gemfile.mongoid3.rb
21
+ - gemfiles/Gemfile.mongoid4.rb
22
+ - gemfiles/Gemfile.mongo_mapper.rb
23
+
17
24
  services:
18
25
  - mongodb
26
+
27
+ matrix:
28
+ exclude:
29
+ - gemfile: gemfiles/Gemfile.mongoid2.rb
30
+ env: rails=4.0.0
31
+ - gemfile: gemfiles/Gemfile.mongoid2.rb
32
+ env: rails=4.1.0
33
+ - gemfile: gemfiles/Gemfile.mongoid2.rb
34
+ env: rails=4.2.0.rc2
35
+
36
+ - gemfile: gemfiles/Gemfile.mongoid3.rb
37
+ env: rails=4.0.0
38
+ - gemfile: gemfiles/Gemfile.mongoid3.rb
39
+ env: rails=4.1.0
40
+ - gemfile: gemfiles/Gemfile.mongoid3.rb
41
+ env: rails=4.2.0.rc2
42
+
43
+ - gemfile: gemfiles/Gemfile.mongoid4.rb
44
+ env: rails=3.1.0
45
+ - gemfile: gemfiles/Gemfile.mongoid4.rb
46
+ env: rails=3.2.0
data/CHANGELOG.md CHANGED
@@ -1,6 +1,48 @@
1
1
  # Changelog
2
2
 
3
- ## master
3
+ ## 2.0.0
4
+
5
+ ### Backward incompatible changes
6
+
7
+ - [#448] Removes `doorkeeper_for` helper. Now we use
8
+ `before_action :doorkeeper_authorize!`.
9
+ - [#469] Allow client applications to restrict the set of allowable scopes.
10
+ Fixes #317. `oauth_applications` relation needs a new `scopes` string column,
11
+ non nullable, which defaults to an empty string. To add the column run:
12
+
13
+ ```
14
+ rails generate doorkeeper:application_scopes
15
+ ```
16
+
17
+ If you’d rather do it by hand, your ActiveRecord migration should contain:
18
+
19
+ ```ruby
20
+ add_column :oauth_applications, :scopes, :string, null: false, default: ‘’
21
+ ```
22
+
23
+ ### Removed deprecations
24
+
25
+ - Removes `test_redirect_uri` option. It is now called `native_redirect_uri`.
26
+ - [#446] Removes `mount Doorkeeper::Engine`. Now we use `use_doorkeeper`.
27
+
28
+ ### Other changes/enhancements
29
+
30
+ - [#484] Performance improvement - avoid performing order_by when not required.
31
+ - [#450] When password is invalid in Password Credentials Grant, Doorkeeper
32
+ returned 'invalid_resource_owner' instead of 'invalid_grant', as the spec
33
+ declares. Fixes #444.
34
+ - [#452] Allows `revoked_at` to be set in the future, for future expiry.
35
+ Rationale: https://github.com/doorkeeper-gem/doorkeeper/pull/452#issuecomment-51431459
36
+ - [#480] For Implicit grant flow, access tokens can now be reused. Fixes #421.
37
+ - [#491] Reworks of @jasl's #454 and #478. ORM refactor that allows doorkeeper
38
+ to be extended more easily with unsupported ORMs. It also marks the boundaries
39
+ between shared model code and ORM specifics inside of the gem.
40
+ - [#496] Tests with Rails 4.2.
41
+ - [#489] Adds `force_ssl_in_redirect_uri` to force the usage of the HTTPS
42
+ protocol in non-native redirect uris.
43
+ - [#516] Adds `protect_from_forgery` to `Doorkeeper::ApplicationController`
44
+ - [#518] Fix random failures in mongodb.
45
+
4
46
 
5
47
  ## 1.4.0
6
48
 
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,35 @@
1
+ # Contributing
2
+
3
+ We love pull requests. Here's a quick guide.
4
+
5
+ Fork, then clone the repo:
6
+
7
+ git clone git@github.com:your-username/doorkeeper.git
8
+
9
+ Set up Ruby dependencies via Bundler
10
+
11
+ bundle install
12
+
13
+ Make sure the tests pass:
14
+
15
+ rake
16
+
17
+ Make your change. Add tests for your change. Make the tests pass:
18
+
19
+ rake
20
+
21
+ Push to your fork and submit a pull request.
22
+
23
+ At this point you're waiting on us. We like to at least comment on pull requests
24
+ within three business days (and, typically, one business day). We may suggest
25
+ some changes or improvements or alternatives.
26
+
27
+ Some things that will increase the chance that your pull request is accepted:
28
+
29
+ * Write tests.
30
+ * Follow our [style guide][style]. Address Hound CI comments unless you have a
31
+ good reason not to.
32
+ * Write a [good commit message][commit].
33
+
34
+ [style]: https://github.com/thoughtbot/guides/tree/master/style
35
+ [commit]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
data/Gemfile CHANGED
@@ -1,33 +1,11 @@
1
- # Defaults. For supported versions check .travis.yml
2
- ENV['rails'] ||= ENV['orm'] == "mongoid4" ? '4.0.2' : '3.2.13'
3
- ENV['orm'] ||= 'active_record'
1
+ ENV['rails'] ||= '4.2.0.rc2'
4
2
 
5
3
  source 'https://rubygems.org'
6
4
 
7
- # Define Rails version
8
- gem 'rails', ENV['rails']
9
-
10
- gem 'database_cleaner', '~> 1.0.0.RC1' if ENV['rails'][0] == '4'
11
-
12
- case ENV['orm']
13
- when 'active_record'
14
- gem 'activerecord'
15
-
16
- when 'mongoid2'
17
- gem 'mongoid', '2.5.1'
18
- gem 'bson_ext', '~> 1.7'
19
-
20
- when 'mongoid3'
21
- gem 'mongoid', '3.0.10'
22
-
23
- when 'mongoid4'
24
- gem 'mongoid', '4.0.0.beta1'
25
- gem 'moped'
26
-
27
- when 'mongo_mapper'
28
- gem 'mongo_mapper', '0.12.0'
29
- gem 'bson_ext', '~> 1.7'
5
+ gem 'rails', "~> #{ENV['rails']}"
30
6
 
7
+ if ENV['rails'][0] == '4'
8
+ gem 'database_cleaner'
31
9
  end
32
10
 
33
11
  gemspec
data/README.md CHANGED
@@ -1,12 +1,17 @@
1
1
  # Doorkeeper - awesome oauth provider for your Rails app.
2
2
 
3
- [![Build Status](https://travis-ci.org/doorkeeper-gem/doorkeeper.png?branch=master)](https://travis-ci.org/doorkeeper-gem/doorkeeper)
4
- [![Dependency Status](https://gemnasium.com/applicake/doorkeeper.png?travis)](https://gemnasium.com/applicake/doorkeeper)
5
- [![Code Climate](https://codeclimate.com/github/applicake/doorkeeper.png)](https://codeclimate.com/github/applicake/doorkeeper)
6
- [![Gem Version](https://badge.fury.io/rb/doorkeeper.png)](https://rubygems.org/gems/doorkeeper)
3
+ [![Build Status](https://travis-ci.org/doorkeeper-gem/doorkeeper.svg?branch=master)](https://travis-ci.org/doorkeeper-gem/doorkeeper)
4
+ [![Dependency Status](https://gemnasium.com/applicake/doorkeeper.svg?travis)](https://gemnasium.com/applicake/doorkeeper)
5
+ [![Code Climate](https://codeclimate.com/github/applicake/doorkeeper.svg)](https://codeclimate.com/github/applicake/doorkeeper)
6
+ [![Gem Version](https://badge.fury.io/rb/doorkeeper.svg)](https://rubygems.org/gems/doorkeeper)
7
7
 
8
8
  Doorkeeper is a gem that makes it easy to introduce OAuth 2 provider functionality to your application.
9
9
 
10
+ ## Documentation valid for `master` branch
11
+
12
+ Please check the documentation for the version of doorkeeper you are using in:
13
+ https://github.com/doorkeeper-gem/doorkeeper/releases.
14
+
10
15
  ## Table of Contents
11
16
 
12
17
  - [Useful links](#useful-links)
@@ -146,66 +151,25 @@ models, session or routes helpers. However, since this code is not run in the
146
151
  context of your application's `ApplicationController` it doesn't have access to
147
152
  the methods defined over there.
148
153
 
149
- If you use [devise](https://github.com/plataformatec/devise), you may want to
150
- use warden to authenticate the block:
151
-
152
- ``` ruby
153
- resource_owner_authenticator do
154
- current_user || warden.authenticate!(:scope => :user)
155
- end
156
- ```
157
-
158
- Side note: when using devise you have access to `current_user` as devise extends
159
- entire `ActionController::Base` with the `current_#{mapping}`.
160
-
161
- If you are not using devise, you may want to check other ways of
162
- authentication
154
+ You may want to check other ways of authentication
163
155
  [here](https://github.com/doorkeeper-gem/doorkeeper/wiki/Authenticating-using-Clearance-or-DIY).
164
156
 
165
157
  ## Protecting resources with OAuth (a.k.a your API endpoint)
166
158
 
167
- To protect your API with OAuth, doorkeeper only requires you to call
168
- `doorkeeper_for` helper, specifying the actions you want to protect.
169
-
170
- For example, if you have a products controller under api/v1, you can require
171
- the OAuth authentication with:
159
+ To protect your API with OAuth, you just need to setup `before_action`s
160
+ specifying the actions you want to protect. For example:
172
161
 
173
162
  ``` ruby
174
163
  class Api::V1::ProductsController < Api::V1::ApiController
175
- doorkeeper_for :all # Require access token for all actions
176
- doorkeeper_for :all, except: :index # All actions except index
177
- doorkeeper_for :index, :show # Only for index and show action
164
+ before_action :doorkeeper_authorize! # Require access token for all actions
178
165
 
179
166
  # your actions
180
167
  end
181
168
  ```
182
169
 
183
- You don't need to setup any before filter, `doorkeeper_for` will handle that
184
- for you.
185
-
186
- You can pass `if` or `unless` blocks that would specify when doorkeeper has to
187
- guard the access.
188
-
189
- ``` ruby
190
- class Api::V1::ProductsController < Api::V1::ApiController
191
- doorkeeper_for :all, :if => lambda { request.xhr? }
192
- end
193
- ```
194
-
195
- ### ActionController::Metal integration
170
+ You can pass any option `before_action` accepts, such as `if`, `only`,
171
+ `except`, and others.
196
172
 
197
- The `doorkeeper_for` filter is intended to work with ActionController::Metal
198
- too. You only need to include the required `ActionController` modules:
199
-
200
- ```ruby
201
- class MetalController < ActionController::Metal
202
- include AbstractController::Callbacks
203
- include ActionController::Head
204
- include Doorkeeper::Helpers::Filter
205
-
206
- doorkeeper_for :all
207
- end
208
- ```
209
173
 
210
174
  ### Route Constraints and other integrations
211
175
 
@@ -248,8 +212,10 @@ And in your controllers:
248
212
 
249
213
  ```ruby
250
214
  class Api::V1::ProductsController < Api::V1::ApiController
251
- doorkeeper_for :index, :show, :scopes => [:public]
252
- doorkeeper_for :update, :create, :scopes => [:admin, :write]
215
+ before_action -> { doorkeeper_authorize! :public }, only: :index
216
+ before_action only: [:create, :update, :destroy] do
217
+ doorkeeper_authorize! :admin, :write
218
+ end
253
219
  end
254
220
  ```
255
221
 
@@ -265,8 +231,8 @@ controller that returns the resource owner instance:
265
231
 
266
232
  ``` ruby
267
233
  class Api::V1::CredentialsController < Api::V1::ApiController
268
- doorkeeper_for :all
269
- respond_to :json
234
+ before_action :doorkeeper_authorize!
235
+ respond_to :json
270
236
 
271
237
  # GET /me.json
272
238
  def me
data/Rakefile CHANGED
@@ -5,7 +5,9 @@ desc 'Default: run specs.'
5
5
  task :default => :spec
6
6
 
7
7
  desc "Run all specs"
8
- RSpec::Core::RakeTask.new(:spec)
8
+ RSpec::Core::RakeTask.new(:spec) do |config|
9
+ config.verbose = false
10
+ end
9
11
 
10
12
  namespace :doorkeeper do
11
13
  desc "Install doorkeeper in dummy app"
@@ -2,12 +2,12 @@ module Doorkeeper
2
2
  class ApplicationController < ActionController::Base
3
3
  include Helpers::Controller
4
4
 
5
- helper 'doorkeeper/form_errors'
6
-
7
5
  if ::Rails.version.to_i < 4
8
6
  protect_from_forgery
9
7
  else
10
8
  protect_from_forgery with: :exception
11
9
  end
10
+
11
+ helper 'doorkeeper/dashboard'
12
12
  end
13
13
  end
@@ -1,7 +1,6 @@
1
1
  module Doorkeeper
2
2
  class ApplicationsController < Doorkeeper::ApplicationController
3
3
  layout 'doorkeeper/admin'
4
- respond_to :html
5
4
 
6
5
  before_filter :authenticate_admin!
7
6
  before_filter :set_application, only: [:show, :edit, :update, :destroy]
@@ -18,7 +17,7 @@ module Doorkeeper
18
17
  @application = Application.new(application_params)
19
18
  if @application.save
20
19
  flash[:notice] = I18n.t(:notice, scope: [:doorkeeper, :flash, :applications, :create])
21
- respond_with [:oauth, @application]
20
+ redirect_to oauth_application_url(@application)
22
21
  else
23
22
  render :new
24
23
  end
@@ -27,7 +26,7 @@ module Doorkeeper
27
26
  def update
28
27
  if @application.update_attributes(application_params)
29
28
  flash[:notice] = I18n.t(:notice, scope: [:doorkeeper, :flash, :applications, :update])
30
- respond_with [:oauth, @application]
29
+ redirect_to oauth_application_url(@application)
31
30
  else
32
31
  render :edit
33
32
  end
@@ -46,9 +45,9 @@ module Doorkeeper
46
45
 
47
46
  def application_params
48
47
  if params.respond_to?(:permit)
49
- params.require(:application).permit(:name, :redirect_uri)
48
+ params.require(:doorkeeper_application).permit(:name, :redirect_uri)
50
49
  else
51
- params[:application].slice(:name, :redirect_uri) rescue nil
50
+ params[:doorkeeper_application].slice(:name, :redirect_uri) rescue nil
52
51
  end
53
52
  end
54
53
  end
@@ -4,7 +4,7 @@ module Doorkeeper
4
4
 
5
5
  def new
6
6
  if pre_auth.authorizable?
7
- if matching_token? || skip_authorization?
7
+ if skip_authorization? || matching_token?
8
8
  auth = authorization.authorize
9
9
  redirect_to auth.redirect_uri
10
10
  else
@@ -41,7 +41,9 @@ module Doorkeeper
41
41
  end
42
42
 
43
43
  def pre_auth
44
- @pre_auth ||= OAuth::PreAuthorization.new(Doorkeeper.configuration, server.client_via_uid, params)
44
+ @pre_auth ||= OAuth::PreAuthorization.new(Doorkeeper.configuration,
45
+ server.client_via_uid,
46
+ params)
45
47
  end
46
48
 
47
49
  def authorization
@@ -18,14 +18,14 @@ module Doorkeeper
18
18
  revoke_token(request.POST['token']) if request.POST['token']
19
19
  end
20
20
  # The authorization server responds with HTTP status code 200 if the
21
- # token has been revoked sucessfully or if the client submitted an invalid token
21
+ # token has been revoked successfully or if the client submitted an invalid token
22
22
  render json: {}, status: 200
23
23
  end
24
24
 
25
25
  private
26
26
 
27
27
  def revoke_token(token)
28
- token = AccessToken.authenticate(token) || AccessToken.by_refresh_token(token)
28
+ token = AccessToken.by_token(token) || AccessToken.by_refresh_token(token)
29
29
  if token && doorkeeper_token.same_credential?(token)
30
30
  token.revoke
31
31
  true
@@ -1,4 +1,4 @@
1
- module Doorkeeper::FormErrorsHelper
1
+ module Doorkeeper::DashboardHelper
2
2
  def doorkeeper_errors_for(object, method)
3
3
  if object.errors[method].present?
4
4
  object.errors[method].map do |msg|
@@ -8,4 +8,8 @@ module Doorkeeper::FormErrorsHelper
8
8
  end.reduce(&:join).html_safe
9
9
  end
10
10
  end
11
+
12
+ def doorkeeper_submit_path(application)
13
+ application.persisted? ? oauth_application_path(application) : oauth_applications_path
14
+ end
11
15
  end
@@ -14,6 +14,7 @@ class RedirectUriValidator < ActiveModel::EachValidator
14
14
  return if native_redirect_uri?(uri)
15
15
  record.errors.add(attribute, :fragment_present) unless uri.fragment.nil?
16
16
  record.errors.add(attribute, :relative_uri) if uri.scheme.nil? || uri.host.nil?
17
+ record.errors.add(attribute, :secured_uri) if invalid_ssl_uri?(uri)
17
18
  end
18
19
  end
19
20
  rescue URI::InvalidURIError
@@ -25,4 +26,9 @@ class RedirectUriValidator < ActiveModel::EachValidator
25
26
  def native_redirect_uri?(uri)
26
27
  self.class.native_redirect_uri.present? && uri.to_s == self.class.native_redirect_uri.to_s
27
28
  end
29
+
30
+ def invalid_ssl_uri?(uri)
31
+ forces_ssl = Doorkeeper.configuration.force_ssl_in_redirect_uri
32
+ forces_ssl && uri.try(:scheme) != 'https'
33
+ end
28
34
  end
@@ -1,5 +1,5 @@
1
1
  <%- submit_btn_css ||= 'btn btn-link' %>
2
- <%= form_tag [:oauth, application] do %>
2
+ <%= form_tag oauth_application_path(application) do %>
3
3
  <input type="hidden" name="_method" value="delete">
4
4
  <%= submit_tag 'Destroy', onclick: "return confirm('Are you sure?')", class: submit_btn_css %>
5
5
  <% end %>
@@ -1,10 +1,10 @@
1
- <%= form_for [:oauth, application], html: {class: 'form-horizontal', role: 'form'} do |f| %>
1
+ <%= form_for application, url: doorkeeper_submit_path(application), html: {class: 'form-horizontal', role: 'form'} do |f| %>
2
2
  <% if application.errors.any? %>
3
3
  <div class="alert alert-danger" data-alert><p>Whoops! Check your form for possible errors</p></div>
4
4
  <% end %>
5
5
 
6
6
  <%= content_tag :div, class: "form-group#{' has-error' if application.errors[:name].present?}" do %>
7
- <%= f.label :name, class: 'col-sm-2 control-label', for: 'application_name' %>
7
+ <%= f.label :name, class: 'col-sm-2 control-label' %>
8
8
  <div class="col-sm-10">
9
9
  <%= f.text_field :name, class: 'form-control' %>
10
10
  <%= doorkeeper_errors_for application, :name %>
@@ -12,7 +12,7 @@
12
12
  <% end %>
13
13
 
14
14
  <%= content_tag :div, class: "form-group#{' has-error' if application.errors[:redirect_uri].present?}" do %>
15
- <%= f.label :redirect_uri, class: 'col-sm-2 control-label', for: 'application_redirect_uri' %>
15
+ <%= f.label :redirect_uri, class: 'col-sm-2 control-label' %>
16
16
  <div class="col-sm-10">
17
17
  <%= f.text_area :redirect_uri, class: 'form-control' %>
18
18
  <%= doorkeeper_errors_for application, :redirect_uri %>
@@ -16,7 +16,7 @@
16
16
  <tbody>
17
17
  <% @applications.each do |application| %>
18
18
  <tr id="application_<%= application.id %>">
19
- <td><%= link_to application.name, [:oauth, application] %></td>
19
+ <td><%= link_to application.name, oauth_application_path(application) %></td>
20
20
  <td><%= application.redirect_uri %></td>
21
21
  <td><%= link_to 'Edit', edit_oauth_application_path(application), class: 'btn btn-link' %></td>
22
22
  <td><%= render 'delete_form', application: application %></td>
@@ -2,30 +2,33 @@ en:
2
2
  activerecord:
3
3
  errors:
4
4
  models:
5
- application:
5
+ doorkeeper/application:
6
6
  attributes:
7
7
  redirect_uri:
8
8
  fragment_present: 'cannot contain a fragment.'
9
9
  invalid_uri: 'must be a valid URI.'
10
10
  relative_uri: 'must be an absolute URI.'
11
+ secured_uri: 'must be an HTTPS/SSL URI.'
11
12
  mongoid:
12
13
  errors:
13
14
  models:
14
- application:
15
+ doorkeeper/application:
15
16
  attributes:
16
17
  redirect_uri:
17
18
  fragment_present: 'cannot contain a fragment.'
18
19
  invalid_uri: 'must be a valid URI.'
19
20
  relative_uri: 'must be an absolute URI.'
21
+ secured_uri: 'must be an HTTPS/SSL URI.'
20
22
  mongo_mapper:
21
23
  errors:
22
24
  models:
23
- application:
25
+ doorkeeper/application:
24
26
  attributes:
25
27
  redirect_uri:
26
28
  fragment_present: 'cannot contain a fragment.'
27
29
  invalid_uri: 'must be a valid URI.'
28
30
  relative_uri: 'must be an absolute URI.'
31
+ secured_uri: 'must be an HTTPS/SSL URI.'
29
32
  doorkeeper:
30
33
  errors:
31
34
  messages:
data/doorkeeper.gemspec CHANGED
@@ -5,8 +5,8 @@ require "doorkeeper/version"
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "doorkeeper"
7
7
  s.version = Doorkeeper::VERSION
8
- s.authors = ["Felipe Elias Philipp", "Piotr Jakubowski"]
9
- s.email = ["felipe@applicake.com", "piotr.jakubowski@applicake.com"]
8
+ s.authors = ["Felipe Elias Philipp", "Tute Costa"]
9
+ s.email = %w(tutecosta@gmail.com)
10
10
  s.homepage = "https://github.com/doorkeeper-gem/doorkeeper"
11
11
  s.summary = "Doorkeeper is an OAuth 2 provider for Rails."
12
12
  s.description = "Doorkeeper is an OAuth 2 provider for Rails."
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
22
22
  s.add_development_dependency "rspec-rails", "~> 2.99.0"
23
23
  s.add_development_dependency "capybara", "~> 2.3.0"
24
24
  s.add_development_dependency "generator_spec", "~> 0.9.0"
25
- s.add_development_dependency "factory_girl", "~> 4.4.0"
25
+ s.add_development_dependency "factory_girl", "~> 4.5.0"
26
26
  s.add_development_dependency "timecop", "~> 0.7.0"
27
27
  s.add_development_dependency "database_cleaner", "~> 1.3.0"
28
28
  s.add_development_dependency "rspec-activemodel-mocks", "~> 1.0.0"
@@ -0,0 +1,11 @@
1
+ ENV['rails'] ||= '4.2.0.rc2'
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gem 'rails', "~> #{ENV['rails']}"
6
+
7
+ if ENV['rails'][0] == '4'
8
+ gem 'database_cleaner'
9
+ end
10
+
11
+ gemspec path: '../'
@@ -0,0 +1,5 @@
1
+ gemfile = 'gemfiles/Gemfile.common.rb'
2
+ instance_eval IO.read(gemfile), gemfile
3
+
4
+ gem 'mongo_mapper', '~> 0.12'
5
+ gem 'bson_ext', '~> 1.7'
@@ -0,0 +1,5 @@
1
+ gemfile = 'gemfiles/Gemfile.common.rb'
2
+ instance_eval IO.read(gemfile), gemfile
3
+
4
+ gem 'mongoid', '~> 2'
5
+ gem 'bson_ext', '~> 1.7'
@@ -0,0 +1,4 @@
1
+ gemfile = 'gemfiles/Gemfile.common.rb'
2
+ instance_eval IO.read(gemfile), gemfile
3
+
4
+ gem 'mongoid', '~> 3'
@@ -0,0 +1,5 @@
1
+ gemfile = 'gemfiles/Gemfile.common.rb'
2
+ instance_eval IO.read(gemfile), gemfile
3
+
4
+ gem 'mongoid', '~> 4'
5
+ gem 'moped'