doorkeeper 0.4.2 → 0.5.0.rc1
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.
- data/.gitignore +2 -0
- data/.travis.yml +5 -1
- data/CHANGELOG.md +29 -0
- data/Gemfile +12 -4
- data/README.md +76 -7
- data/Rakefile +1 -25
- data/app/assets/javascripts/doorkeeper/application.js +0 -7
- data/app/controllers/doorkeeper/application_controller.rb +1 -27
- data/app/controllers/doorkeeper/applications_controller.rb +14 -6
- data/app/controllers/doorkeeper/authorized_applications_controller.rb +1 -1
- data/app/controllers/doorkeeper/token_info_controller.rb +11 -0
- data/app/controllers/doorkeeper/tokens_controller.rb +11 -8
- data/app/validators/redirect_uri_validator.rb +12 -0
- data/app/views/doorkeeper/applications/_form.html.erb +3 -3
- data/app/views/doorkeeper/applications/edit.html.erb +1 -1
- data/app/views/doorkeeper/applications/index.html.erb +4 -4
- data/app/views/doorkeeper/applications/new.html.erb +1 -1
- data/app/views/doorkeeper/applications/show.html.erb +3 -3
- data/app/views/doorkeeper/authorizations/new.html.erb +2 -2
- data/app/views/doorkeeper/authorized_applications/index.html.erb +1 -1
- data/config/locales/en.yml +35 -0
- data/doorkeeper.gemspec +3 -3
- data/gemfiles/gemfile.rails-3.1.x +10 -0
- data/gemfiles/gemfile.rails-3.2.x +10 -0
- data/lib/doorkeeper.rb +10 -3
- data/lib/doorkeeper/config.rb +56 -38
- data/lib/doorkeeper/doorkeeper_for.rb +2 -0
- data/lib/doorkeeper/engine.rb +3 -32
- data/lib/doorkeeper/helpers/controller.rb +29 -0
- data/lib/doorkeeper/helpers/filter.rb +4 -18
- data/{app/models/doorkeeper → lib/doorkeeper/models}/access_grant.rb +7 -7
- data/{app/models/doorkeeper → lib/doorkeeper/models}/access_token.rb +27 -24
- data/lib/doorkeeper/models/accessible.rb +9 -0
- data/lib/doorkeeper/models/active_record/access_grant.rb +5 -0
- data/lib/doorkeeper/models/active_record/access_token.rb +15 -0
- data/lib/doorkeeper/models/active_record/application.rb +18 -0
- data/lib/doorkeeper/models/application.rb +38 -0
- data/lib/doorkeeper/models/expirable.rb +6 -4
- data/lib/doorkeeper/models/mongoid/access_grant.rb +22 -0
- data/lib/doorkeeper/models/mongoid/access_token.rb +35 -0
- data/lib/doorkeeper/models/mongoid/application.rb +22 -0
- data/lib/doorkeeper/models/mongoid/revocable.rb +15 -0
- data/lib/doorkeeper/models/mongoid/scopes.rb +15 -0
- data/lib/doorkeeper/models/ownership.rb +16 -0
- data/lib/doorkeeper/models/revocable.rb +1 -1
- data/lib/doorkeeper/models/scopes.rb +9 -5
- data/lib/doorkeeper/oauth/access_token_request.rb +2 -2
- data/lib/doorkeeper/oauth/authorization.rb +1 -0
- data/lib/doorkeeper/oauth/authorization/code.rb +5 -3
- data/lib/doorkeeper/oauth/client.rb +2 -2
- data/lib/doorkeeper/oauth/client_credentials_request.rb +4 -1
- data/lib/doorkeeper/oauth/helpers/unique_token.rb +2 -5
- data/lib/doorkeeper/oauth/password_access_token_request.rb +2 -5
- data/lib/doorkeeper/oauth/token.rb +36 -0
- data/lib/doorkeeper/rails/routes.rb +77 -0
- data/lib/doorkeeper/rails/routes/mapper.rb +28 -0
- data/lib/doorkeeper/rails/routes/mapping.rb +39 -0
- data/lib/doorkeeper/version.rb +1 -1
- data/lib/generators/doorkeeper/application_owner_generator.rb +15 -0
- data/lib/generators/doorkeeper/install_generator.rb +2 -9
- data/lib/generators/doorkeeper/migration_generator.rb +15 -0
- data/lib/generators/doorkeeper/templates/README +15 -1
- data/lib/generators/doorkeeper/templates/add_owner_to_application_migration.rb +7 -0
- data/lib/generators/doorkeeper/templates/initializer.rb +31 -15
- data/lib/generators/doorkeeper/templates/migration.rb +7 -4
- data/lib/generators/doorkeeper/views_generator.rb +1 -1
- data/script/run_all +3 -0
- data/spec/controllers/applications_controller_spec.rb +1 -1
- data/spec/controllers/authorizations_controller_spec.rb +4 -4
- data/spec/controllers/protected_resources_controller_spec.rb +7 -7
- data/spec/controllers/token_info_controller_spec.rb +54 -0
- data/spec/controllers/tokens_controller_spec.rb +3 -2
- data/spec/dummy/app/controllers/custom_authorizations_controller.rb +7 -0
- data/spec/dummy/app/models/user.rb +16 -5
- data/spec/dummy/config/application.rb +4 -7
- data/spec/dummy/config/boot.rb +3 -7
- data/spec/dummy/config/initializers/doorkeeper.rb +13 -0
- data/spec/dummy/config/mongoid.yml +7 -0
- data/spec/dummy/config/routes.rb +29 -1
- data/spec/dummy/db/migrate/20120312140401_add_password_to_users.rb +1 -1
- data/spec/dummy/db/migrate/20120524202412_create_doorkeeper_tables.rb +6 -4
- data/spec/dummy/db/schema.rb +5 -3
- data/spec/generators/application_owner_generator_spec.rb +23 -0
- data/spec/generators/install_generator_spec.rb +1 -6
- data/spec/generators/migration_generator_spec.rb +20 -0
- data/spec/lib/config_spec.rb +72 -4
- data/spec/lib/models/expirable_spec.rb +8 -11
- data/spec/lib/models/revocable_spec.rb +1 -1
- data/spec/lib/oauth/access_token_request_spec.rb +15 -9
- data/spec/lib/oauth/authorization_request_spec.rb +1 -0
- data/spec/lib/oauth/client_credentials_request_spec.rb +15 -9
- data/spec/lib/oauth/client_spec.rb +5 -8
- data/spec/lib/oauth/helpers/unique_token_spec.rb +2 -20
- data/spec/lib/oauth/password_access_token_request_spec.rb +16 -9
- data/spec/lib/oauth/token_spec.rb +83 -0
- data/spec/models/doorkeeper/access_token_spec.rb +41 -1
- data/spec/models/doorkeeper/application_spec.rb +53 -20
- data/spec/requests/flows/authorization_code_spec.rb +1 -1
- data/spec/requests/flows/client_credentials_spec.rb +2 -0
- data/spec/requests/flows/password_spec.rb +25 -0
- data/spec/requests/flows/refresh_token_spec.rb +5 -2
- data/spec/requests/protected_resources/private_api_spec.rb +10 -3
- data/spec/routing/custom_controller_routes_spec.rb +44 -0
- data/spec/routing/default_routes_spec.rb +32 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/spec_helper_integration.rb +18 -8
- data/spec/support/dependencies/factory_girl.rb +0 -3
- data/spec/support/orm/active_record.rb +11 -0
- data/spec/support/orm/mongoid.rb +26 -0
- data/spec/support/shared/controllers_shared_context.rb +2 -2
- data/spec/support/shared/models_shared_examples.rb +16 -0
- data/spec/validators/redirect_uri_validator_spec.rb +40 -0
- metadata +61 -37
- data/app/helpers/doorkeeper/application_helper.rb +0 -4
- data/app/models/doorkeeper/application.rb +0 -54
- data/config/routes.rb +0 -9
- data/lib/tasks/doorkeeper_tasks.rake +0 -4
- data/spec/support/dependencies/database_cleaner.rb +0 -16
@@ -17,7 +17,7 @@
|
|
17
17
|
|
18
18
|
<div class="span6">
|
19
19
|
<h3>Actions</h3>
|
20
|
-
<p><%= link_to 'List all',
|
21
|
-
<p><%= link_to 'Edit',
|
22
|
-
<p><%= link_to 'Remove', @application, :method => :delete, :confirm => "Are you sure?" %></p>
|
20
|
+
<p><%= link_to 'List all', oauth_applications_path %></p>
|
21
|
+
<p><%= link_to 'Edit', edit_oauth_application_path(@application) %></p>
|
22
|
+
<p><%= link_to 'Remove', [:oauth, @application], :method => :delete, :data => { :confirm => "Are you sure?" } %></p>
|
23
23
|
</div>
|
@@ -15,7 +15,7 @@
|
|
15
15
|
<% end %>
|
16
16
|
|
17
17
|
<div class="inline_block">
|
18
|
-
<%= form_for @authorization, :as => :authorization, :url =>
|
18
|
+
<%= form_for @authorization, :as => :authorization, :url => oauth_authorization_path, :method => :post do |f| %>
|
19
19
|
<%= f.hidden_field :client_id %>
|
20
20
|
<%= f.hidden_field :redirect_uri %>
|
21
21
|
<%= f.hidden_field :state %>
|
@@ -25,7 +25,7 @@
|
|
25
25
|
<% end %>
|
26
26
|
</div>
|
27
27
|
<div class="inline_block">
|
28
|
-
<%= form_for @authorization, :as => :authorization, :url =>
|
28
|
+
<%= form_for @authorization, :as => :authorization, :url => oauth_authorization_path, :method => :delete do |f| %>
|
29
29
|
<%= f.hidden_field :client_id %>
|
30
30
|
<%= f.hidden_field :redirect_uri %>
|
31
31
|
<%= f.hidden_field :state %>
|
@@ -17,7 +17,7 @@
|
|
17
17
|
<tr>
|
18
18
|
<td><%= application.name %></td>
|
19
19
|
<td><%= application.created_at %></td>
|
20
|
-
<td><%= link_to 'Revoke',
|
20
|
+
<td><%= link_to 'Revoke', oauth_authorized_application_path(application), :data => { :confirm => 'Are you sure?' }, :method => :delete, :class => 'btn danger' %></td>
|
21
21
|
</tr>
|
22
22
|
<% end %>
|
23
23
|
</tbody>
|
data/config/locales/en.yml
CHANGED
@@ -1,4 +1,24 @@
|
|
1
1
|
en:
|
2
|
+
activerecord:
|
3
|
+
errors:
|
4
|
+
models:
|
5
|
+
application:
|
6
|
+
attributes:
|
7
|
+
redirect_uri:
|
8
|
+
fragment_present: 'cannot contain a fragment.'
|
9
|
+
has_query_parameter: 'cannot contain a query parameter.'
|
10
|
+
invalid_uri: 'must be a valid URI.'
|
11
|
+
relative_uri: 'must be an absolute URI.'
|
12
|
+
mongoid:
|
13
|
+
errors:
|
14
|
+
models:
|
15
|
+
application:
|
16
|
+
attributes:
|
17
|
+
redirect_uri:
|
18
|
+
fragment_present: 'cannot contain a fragment.'
|
19
|
+
has_query_parameter: 'cannot contain a query parameter.'
|
20
|
+
invalid_uri: 'must be a valid URI.'
|
21
|
+
relative_uri: 'must be an absolute URI.'
|
2
22
|
doorkeeper:
|
3
23
|
errors:
|
4
24
|
messages:
|
@@ -11,6 +31,10 @@ en:
|
|
11
31
|
server_error: 'The authorization server encountered an unexpected condition which prevented it from fulfilling the request.'
|
12
32
|
temporarily_unavailable: 'The authorization server is currently unable to handle the request due to a temporary overloading or maintenance of the server.'
|
13
33
|
|
34
|
+
#configuration error messages
|
35
|
+
credential_flow_not_configured: 'Resource Owner Password Credentials flow failed due to Doorkeeper.configure.resource_owner_from_credentials being unconfigured.'
|
36
|
+
resource_owner_authenticator_not_configured: 'Resource Owner find failed due to Doorkeeper.configure.resource_owner_authenticator being unconfiged.'
|
37
|
+
|
14
38
|
# Access grant errors
|
15
39
|
unsupported_response_type: 'The authorization server does not support this response type.'
|
16
40
|
|
@@ -21,3 +45,14 @@ en:
|
|
21
45
|
|
22
46
|
# Password Access token errors
|
23
47
|
invalid_resource_owner: 'The provided resource owner credentials are not valid, or resource owner cannot be found'
|
48
|
+
flash:
|
49
|
+
applications:
|
50
|
+
create:
|
51
|
+
notice: 'Application created.'
|
52
|
+
destroy:
|
53
|
+
notice: 'Application deleted.'
|
54
|
+
update:
|
55
|
+
notice: 'Application updated.'
|
56
|
+
authorized_applications:
|
57
|
+
destroy:
|
58
|
+
notice: 'Application revoked.'
|
data/doorkeeper.gemspec
CHANGED
@@ -18,11 +18,11 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.add_dependency "railties", "~> 3.1"
|
19
19
|
|
20
20
|
s.add_development_dependency "sqlite3", "~> 1.3.5"
|
21
|
-
s.add_development_dependency "rspec-rails", "~> 2.
|
21
|
+
s.add_development_dependency "rspec-rails", "~> 2.11.0"
|
22
22
|
s.add_development_dependency "capybara", "~> 1.1.2"
|
23
23
|
s.add_development_dependency "generator_spec", "~> 0.8.5"
|
24
24
|
s.add_development_dependency "factory_girl", "~> 2.6.4"
|
25
|
-
s.add_development_dependency "timecop", "~> 0.3
|
26
|
-
s.add_development_dependency "database_cleaner", "~> 0.
|
25
|
+
s.add_development_dependency "timecop", "~> 0.4.3"
|
26
|
+
s.add_development_dependency "database_cleaner", "~> 0.8"
|
27
27
|
s.add_development_dependency "bcrypt-ruby", "~> 3.0.1"
|
28
28
|
end
|
@@ -2,6 +2,16 @@ source 'http://rubygems.org'
|
|
2
2
|
|
3
3
|
gem 'rails', '~> 3.1.0'
|
4
4
|
gem 'jquery-rails'
|
5
|
+
|
6
|
+
group :mongoid do
|
7
|
+
gem 'mongoid', '~> 2.4'
|
8
|
+
gem 'bson_ext', '~> 1.6.0'
|
9
|
+
end
|
10
|
+
|
11
|
+
group :active_record do
|
12
|
+
gem 'activerecord', '~> 3.1'
|
13
|
+
end
|
14
|
+
|
5
15
|
gem 'doorkeeper', :path => '../'
|
6
16
|
|
7
17
|
gemspec :path => '../'
|
@@ -2,6 +2,16 @@ source 'http://rubygems.org'
|
|
2
2
|
|
3
3
|
gem 'rails', '~> 3.2.0'
|
4
4
|
gem 'jquery-rails'
|
5
|
+
|
6
|
+
group :mongoid do
|
7
|
+
gem 'mongoid', '~> 2.4'
|
8
|
+
gem 'bson_ext', '~> 1.6.0'
|
9
|
+
end
|
10
|
+
|
11
|
+
group :active_record do
|
12
|
+
gem 'activerecord', '~> 3.1'
|
13
|
+
end
|
14
|
+
|
5
15
|
gem 'doorkeeper', :path => '../'
|
6
16
|
|
7
17
|
gemspec :path => '../'
|
data/lib/doorkeeper.rb
CHANGED
@@ -16,6 +16,7 @@ module Doorkeeper
|
|
16
16
|
autoload :ClientCredentialsRequest, "doorkeeper/oauth/client_credentials_request"
|
17
17
|
autoload :Authorization, "doorkeeper/oauth/authorization"
|
18
18
|
autoload :Client, "doorkeeper/oauth/client"
|
19
|
+
autoload :Token, "doorkeeper/oauth/token"
|
19
20
|
|
20
21
|
module Helpers
|
21
22
|
autoload :ScopeChecker, "doorkeeper/oauth/helpers/scope_checker"
|
@@ -25,13 +26,19 @@ module Doorkeeper
|
|
25
26
|
end
|
26
27
|
|
27
28
|
module Models
|
28
|
-
autoload :
|
29
|
-
autoload :
|
30
|
-
autoload :
|
29
|
+
autoload :Scopes, 'doorkeeper/models/scopes'
|
30
|
+
autoload :Expirable, 'doorkeeper/models/expirable'
|
31
|
+
autoload :Revocable, 'doorkeeper/models/revocable'
|
32
|
+
autoload :Accessible, 'doorkeeper/models/accessible'
|
31
33
|
end
|
32
34
|
|
33
35
|
module Helpers
|
34
36
|
autoload :Filter, "doorkeeper/helpers/filter"
|
37
|
+
autoload :Controller, "doorkeeper/helpers/controller"
|
38
|
+
end
|
39
|
+
|
40
|
+
module Rails
|
41
|
+
autoload :Routes, "doorkeeper/rails/routes"
|
35
42
|
end
|
36
43
|
|
37
44
|
def self.configured?
|
data/lib/doorkeeper/config.rb
CHANGED
@@ -1,37 +1,30 @@
|
|
1
1
|
module Doorkeeper
|
2
2
|
def self.configure(&block)
|
3
3
|
@config = Config::Builder.new(&block).build
|
4
|
+
enable_orm
|
5
|
+
setup_application_owner if @config.enable_application_owner?
|
4
6
|
end
|
5
7
|
|
6
8
|
def self.configuration
|
7
9
|
@config
|
8
10
|
end
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
@default_scopes, @optional_scopes, @translations = [], [], {}
|
19
|
-
end
|
20
|
-
|
21
|
-
def scope(scope, options = {})
|
22
|
-
if options[:default]
|
23
|
-
@optional_scopes << scope
|
24
|
-
else
|
25
|
-
@default_scopes << scope
|
26
|
-
end
|
27
|
-
@translations[scope] = options[:description]
|
28
|
-
end
|
12
|
+
def self.enable_orm
|
13
|
+
require "doorkeeper/models/#{@config.orm}/access_grant"
|
14
|
+
require "doorkeeper/models/#{@config.orm}/access_token"
|
15
|
+
require "doorkeeper/models/#{@config.orm}/application"
|
16
|
+
require 'doorkeeper/models/access_grant'
|
17
|
+
require 'doorkeeper/models/access_token'
|
18
|
+
require 'doorkeeper/models/application'
|
19
|
+
end
|
29
20
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
21
|
+
def self.setup_application_owner
|
22
|
+
require File.join(File.dirname(__FILE__), 'models', 'ownership')
|
23
|
+
Doorkeeper::Application.send :include, Doorkeeper::Models::Ownership
|
24
|
+
end
|
34
25
|
|
26
|
+
class Config
|
27
|
+
class Builder
|
35
28
|
def initialize(&block)
|
36
29
|
@config = Config.new
|
37
30
|
instance_eval(&block)
|
@@ -41,6 +34,15 @@ module Doorkeeper
|
|
41
34
|
@config
|
42
35
|
end
|
43
36
|
|
37
|
+
def enable_application_owner(opts={})
|
38
|
+
@config.instance_variable_set("@enable_application_owner", true)
|
39
|
+
confirm_application_owner if opts[:confirmation].present? && opts[:confirmation]
|
40
|
+
end
|
41
|
+
|
42
|
+
def confirm_application_owner
|
43
|
+
@config.instance_variable_set("@confirm_application_owner", true)
|
44
|
+
end
|
45
|
+
|
44
46
|
def default_scopes(*scopes)
|
45
47
|
@config.instance_variable_set("@default_scopes", Doorkeeper::OAuth::Scopes.from_array(scopes))
|
46
48
|
end
|
@@ -53,17 +55,12 @@ module Doorkeeper
|
|
53
55
|
@config.instance_variable_set("@client_credentials", methods)
|
54
56
|
end
|
55
57
|
|
56
|
-
def
|
57
|
-
@config.instance_variable_set("@
|
58
|
+
def access_token_methods(*methods)
|
59
|
+
@config.instance_variable_set("@access_token_methods", methods)
|
58
60
|
end
|
59
61
|
|
60
|
-
|
61
|
-
|
62
|
-
migrator = ScopesMigrator.new
|
63
|
-
migrator.migrate(&block)
|
64
|
-
self.default_scopes *migrator.default_scopes
|
65
|
-
self.optional_scopes *migrator.optional_scopes
|
66
|
-
@config.instance_variable_set("@authorization_scopes", migrator)
|
62
|
+
def use_refresh_token
|
63
|
+
@config.instance_variable_set("@refresh_token_enabled", true)
|
67
64
|
end
|
68
65
|
end
|
69
66
|
|
@@ -102,6 +99,7 @@ module Doorkeeper
|
|
102
99
|
|
103
100
|
Builder.instance_eval do
|
104
101
|
define_method name do |*args, &block|
|
102
|
+
# TODO: is builder_class option being used?
|
105
103
|
value = unless attribute_builder
|
106
104
|
block ? block : args.first
|
107
105
|
else
|
@@ -130,15 +128,36 @@ module Doorkeeper
|
|
130
128
|
|
131
129
|
extend Option
|
132
130
|
|
133
|
-
option :resource_owner_authenticator,
|
134
|
-
|
135
|
-
|
131
|
+
option :resource_owner_authenticator,
|
132
|
+
:as => :authenticate_resource_owner,
|
133
|
+
:default => lambda{|routes|
|
134
|
+
logger.warn(I18n.translate('doorkeeper.errors.messages.resource_owner_authenticator_not_configured'))
|
135
|
+
nil
|
136
|
+
}
|
137
|
+
option :admin_authenticator,
|
138
|
+
:as => :authenticate_admin,
|
139
|
+
:default => lambda{|routes| }
|
140
|
+
option :resource_owner_from_credentials,
|
141
|
+
:default => lambda{|routes|
|
142
|
+
logger.warn(I18n.translate('doorkeeper.errors.messages.credential_flow_not_configured'))
|
143
|
+
nil
|
144
|
+
}
|
136
145
|
option :access_token_expires_in, :default => 7200
|
146
|
+
option :authorization_code_expires_in,:default => 600
|
147
|
+
option :orm, :default => :active_record
|
137
148
|
|
138
149
|
def refresh_token_enabled?
|
139
150
|
!!@refresh_token_enabled
|
140
151
|
end
|
141
152
|
|
153
|
+
def enable_application_owner?
|
154
|
+
!!@enable_application_owner
|
155
|
+
end
|
156
|
+
|
157
|
+
def confirm_application_owner?
|
158
|
+
!!@confirm_application_owner
|
159
|
+
end
|
160
|
+
|
142
161
|
def default_scopes
|
143
162
|
@default_scopes ||= Doorkeeper::OAuth::Scopes.new
|
144
163
|
end
|
@@ -155,9 +174,8 @@ module Doorkeeper
|
|
155
174
|
@client_credentials ||= [:from_basic, :from_params]
|
156
175
|
end
|
157
176
|
|
158
|
-
|
159
|
-
|
160
|
-
@authorization_scopes
|
177
|
+
def access_token_methods
|
178
|
+
@access_token_methods ||= [:from_bearer_authorization, :from_access_token_param, :from_bearer_param]
|
161
179
|
end
|
162
180
|
end
|
163
181
|
end
|
@@ -11,6 +11,7 @@ module Doorkeeper
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
+
# TODO: move this to Token class
|
14
15
|
def validate_token(token)
|
15
16
|
return false unless token
|
16
17
|
token.accessible? and validate_token_scopes(token)
|
@@ -33,6 +34,7 @@ module Doorkeeper
|
|
33
34
|
@filter_options[:unless] = unless_block
|
34
35
|
end
|
35
36
|
|
37
|
+
# TODO: move this to Token class
|
36
38
|
def validate_token_scopes(token)
|
37
39
|
return true if @scopes.blank?
|
38
40
|
token.scopes.any? { |scope| @scopes.include? scope}
|
data/lib/doorkeeper/engine.rb
CHANGED
@@ -1,37 +1,8 @@
|
|
1
1
|
module Doorkeeper
|
2
2
|
class Engine < Rails::Engine
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
g.test_framework :rspec, :view_specs => false
|
7
|
-
end
|
8
|
-
|
9
|
-
initializer "doorkeeper.deprecations" do
|
10
|
-
if Doorkeeper.installed?
|
11
|
-
if Doorkeeper.configuration.authorization_scopes.present?
|
12
|
-
warning = <<-WARN
|
13
|
-
[DOORKEEPER]
|
14
|
-
Configuration for `authorization_scopes` will no longer be supported. Use default_scopes/optional_scopes instead.
|
15
|
-
ATTENTION: The :description option could not be migrated because doorkeeper now uses localization files.
|
16
|
-
Place this in your config/locales/en.yml
|
17
|
-
en:
|
18
|
-
doorkeeper:
|
19
|
-
scopes:
|
20
|
-
WARN
|
21
|
-
puts warning
|
22
|
-
Doorkeeper.configuration.authorization_scopes.translations.each do |scope, translation|
|
23
|
-
puts " #{scope}: #{translation}"
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
if Doorkeeper::AccessToken.columns_hash["resource_owner_id"].null == false
|
28
|
-
warn <<-WARN
|
29
|
-
[DOORKEEPER]
|
30
|
-
In order to use the Client Credentials flow, you have to migrate the oauth_access_tokens table:
|
31
|
-
change_column :oauth_access_tokens, :resource_owner_id, :integer, :null => true
|
32
|
-
WARN
|
33
|
-
end
|
34
|
-
end
|
3
|
+
initializer "doorkeeper.routes" do
|
4
|
+
Doorkeeper::Rails::Routes.warn_if_using_mount_method!
|
5
|
+
Doorkeeper::Rails::Routes.install!
|
35
6
|
end
|
36
7
|
|
37
8
|
initializer "doorkeeper.helpers" do
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Doorkeeper
|
2
|
+
module Helpers
|
3
|
+
module Controller
|
4
|
+
def self.included(base)
|
5
|
+
base.send :private,
|
6
|
+
:authenticate_resource_owner!,
|
7
|
+
:authenticate_admin!,
|
8
|
+
:current_resource_owner,
|
9
|
+
:resource_owner_from_credentials
|
10
|
+
end
|
11
|
+
|
12
|
+
def authenticate_resource_owner!
|
13
|
+
current_resource_owner
|
14
|
+
end
|
15
|
+
|
16
|
+
def current_resource_owner
|
17
|
+
instance_eval &Doorkeeper.configuration.authenticate_resource_owner
|
18
|
+
end
|
19
|
+
|
20
|
+
def resource_owner_from_credentials
|
21
|
+
instance_eval &Doorkeeper.configuration.resource_owner_from_credentials
|
22
|
+
end
|
23
|
+
|
24
|
+
def authenticate_admin!
|
25
|
+
instance_eval &Doorkeeper.configuration.authenticate_admin
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -7,6 +7,7 @@ module Doorkeeper
|
|
7
7
|
|
8
8
|
before_filter doorkeeper_for.filter_options do
|
9
9
|
return if doorkeeper_for.validate_token(doorkeeper_token)
|
10
|
+
# TODO: use ErrorRespose class for this
|
10
11
|
render_options = doorkeeper_unauthorized_render_options
|
11
12
|
if render_options.nil? || render_options.empty?
|
12
13
|
head :unauthorized
|
@@ -21,27 +22,12 @@ module Doorkeeper
|
|
21
22
|
|
22
23
|
def self.included(base)
|
23
24
|
base.extend ClassMethods
|
24
|
-
base.send :private,
|
25
|
-
:doorkeeper_token,
|
26
|
-
:get_doorkeeper_token,
|
27
|
-
:authorization_bearer_token,
|
28
|
-
:doorkeeper_unauthorized_render_options
|
25
|
+
base.send :private, :doorkeeper_token, :doorkeeper_unauthorized_render_options
|
29
26
|
end
|
30
27
|
|
31
28
|
def doorkeeper_token
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
def get_doorkeeper_token
|
36
|
-
token = params[:access_token] || params[:bearer_token] || authorization_bearer_token
|
37
|
-
if token
|
38
|
-
AccessToken.find_by_token(token)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def authorization_bearer_token
|
43
|
-
header = request.env['HTTP_AUTHORIZATION']
|
44
|
-
header.gsub(/^Bearer /, '') if header && header.match(/^Bearer /)
|
29
|
+
methods = Doorkeeper.configuration.access_token_methods
|
30
|
+
@token ||= OAuth::Token.authenticate request, *methods
|
45
31
|
end
|
46
32
|
|
47
33
|
def doorkeeper_unauthorized_render_options
|