doorkeeper 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of doorkeeper might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.travis.yml +2 -2
- data/CHANGELOG.md +14 -2
- data/README.md +93 -42
- data/app/controllers/doorkeeper/application_controller.rb +1 -1
- data/app/controllers/doorkeeper/applications_controller.rb +4 -4
- data/app/controllers/doorkeeper/authorizations_controller.rb +3 -3
- data/app/controllers/doorkeeper/authorized_applications_controller.rb +1 -1
- data/app/controllers/doorkeeper/token_info_controller.rb +3 -3
- data/app/controllers/doorkeeper/tokens_controller.rb +29 -2
- data/app/helpers/doorkeeper/form_errors_helper.rb +2 -2
- data/app/validators/redirect_uri_validator.rb +1 -1
- 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/new.html.erb +1 -1
- data/app/views/doorkeeper/applications/show.html.erb +1 -1
- data/app/views/doorkeeper/authorizations/new.html.erb +5 -5
- data/doorkeeper.gemspec +1 -1
- data/lib/doorkeeper.rb +31 -31
- data/lib/doorkeeper/config.rb +66 -37
- data/lib/doorkeeper/doorkeeper_for.rb +6 -3
- data/lib/doorkeeper/engine.rb +2 -2
- data/lib/doorkeeper/helpers/controller.rb +9 -9
- data/lib/doorkeeper/helpers/filter.rb +1 -1
- data/lib/doorkeeper/models/access_grant.rb +5 -5
- data/lib/doorkeeper/models/access_token.rb +22 -18
- data/lib/doorkeeper/models/active_record/access_token.rb +8 -8
- data/lib/doorkeeper/models/active_record/application.rb +5 -5
- data/lib/doorkeeper/models/application.rb +8 -9
- data/lib/doorkeeper/models/expirable.rb +1 -1
- data/lib/doorkeeper/models/mongo_mapper/access_grant.rb +2 -2
- data/lib/doorkeeper/models/mongo_mapper/access_token.rb +11 -11
- data/lib/doorkeeper/models/mongo_mapper/application.rb +4 -4
- data/lib/doorkeeper/models/mongoid/version.rb +2 -2
- data/lib/doorkeeper/models/mongoid2/access_grant.rb +7 -7
- data/lib/doorkeeper/models/mongoid2/access_token.rb +14 -14
- data/lib/doorkeeper/models/mongoid2/application.rb +7 -7
- data/lib/doorkeeper/models/mongoid3_4/access_grant.rb +7 -7
- data/lib/doorkeeper/models/mongoid3_4/access_token.rb +13 -13
- data/lib/doorkeeper/models/mongoid3_4/application.rb +6 -6
- data/lib/doorkeeper/models/ownership.rb +5 -5
- data/lib/doorkeeper/oauth/authorization/code.rb +5 -5
- data/lib/doorkeeper/oauth/authorization/token.rb +7 -7
- data/lib/doorkeeper/oauth/authorization_code_request.rb +18 -19
- data/lib/doorkeeper/oauth/client.rb +1 -1
- data/lib/doorkeeper/oauth/client_credentials/creator.rb +4 -4
- data/lib/doorkeeper/oauth/client_credentials/issuer.rb +6 -4
- data/lib/doorkeeper/oauth/client_credentials/validation.rb +2 -2
- data/lib/doorkeeper/oauth/client_credentials_request.rb +11 -15
- data/lib/doorkeeper/oauth/code_request.rb +5 -4
- data/lib/doorkeeper/oauth/code_response.rb +8 -7
- data/lib/doorkeeper/oauth/error.rb +1 -1
- data/lib/doorkeeper/oauth/error_response.rb +5 -5
- data/lib/doorkeeper/oauth/helpers/uri_checker.rb +1 -1
- data/lib/doorkeeper/oauth/invalid_token_response.rb +10 -10
- data/lib/doorkeeper/oauth/password_access_token_request.rb +57 -54
- data/lib/doorkeeper/oauth/pre_authorization.rb +7 -7
- data/lib/doorkeeper/oauth/refresh_token_request.rb +27 -24
- data/lib/doorkeeper/oauth/scopes.rb +3 -3
- data/lib/doorkeeper/oauth/token.rb +27 -1
- data/lib/doorkeeper/oauth/token_request.rb +14 -4
- data/lib/doorkeeper/rails/routes.rb +31 -22
- data/lib/doorkeeper/rails/routes/mapping.rb +11 -12
- data/lib/doorkeeper/request.rb +5 -5
- data/lib/doorkeeper/version.rb +1 -1
- data/lib/generators/doorkeeper/application_owner_generator.rb +1 -1
- data/lib/generators/doorkeeper/install_generator.rb +5 -5
- data/lib/generators/doorkeeper/migration_generator.rb +1 -1
- data/lib/generators/doorkeeper/mongo_mapper/indexes_generator.rb +2 -2
- data/lib/generators/doorkeeper/templates/add_owner_to_application_migration.rb +2 -2
- data/lib/generators/doorkeeper/templates/initializer.rb +16 -3
- data/lib/generators/doorkeeper/templates/migration.rb +16 -17
- data/lib/generators/doorkeeper/views_generator.rb +1 -1
- data/spec/controllers/applications_controller_spec.rb +7 -7
- data/spec/controllers/authorizations_controller_spec.rb +48 -48
- data/spec/controllers/protected_resources_controller_spec.rb +108 -107
- data/spec/controllers/token_info_controller_spec.rb +11 -11
- data/spec/controllers/tokens_controller_spec.rb +8 -8
- data/spec/dummy/app/controllers/custom_authorizations_controller.rb +2 -2
- data/spec/dummy/app/controllers/full_protected_resources_controller.rb +3 -3
- data/spec/dummy/app/controllers/home_controller.rb +5 -5
- data/spec/dummy/app/controllers/metal_controller.rb +1 -1
- data/spec/dummy/app/controllers/semi_protected_resources_controller.rb +2 -2
- data/spec/dummy/app/models/user.rb +3 -3
- data/spec/dummy/config/application.rb +8 -9
- data/spec/dummy/config/boot.rb +1 -1
- data/spec/dummy/config/environments/test.rb +1 -1
- data/spec/dummy/config/initializers/doorkeeper.rb +5 -5
- data/spec/dummy/config/initializers/session_store.rb +1 -1
- data/spec/dummy/config/initializers/wrap_parameters.rb +1 -1
- data/spec/dummy/config/routes.rb +27 -27
- data/spec/dummy/db/migrate/20130902165751_create_doorkeeper_tables.rb +16 -17
- data/spec/dummy/db/migrate/20130902175349_add_owner_to_application.rb +3 -3
- data/spec/dummy/db/schema.rb +39 -39
- data/spec/factories/access_grant.rb +3 -3
- data/spec/factories/access_token.rb +1 -1
- data/spec/factories/application.rb +3 -3
- data/spec/generators/application_owner_generator_spec.rb +6 -7
- data/spec/generators/install_generator_spec.rb +9 -9
- data/spec/generators/migration_generator_spec.rb +4 -4
- data/spec/lib/config_spec.rb +136 -44
- data/spec/lib/models/expirable_spec.rb +9 -9
- data/spec/lib/models/revocable_spec.rb +4 -4
- data/spec/lib/oauth/authorization/uri_builder_spec.rb +4 -4
- data/spec/lib/oauth/authorization_code_request_spec.rb +2 -2
- data/spec/lib/oauth/client/credentials_spec.rb +4 -4
- data/spec/lib/oauth/client/methods_spec.rb +10 -10
- data/spec/lib/oauth/client_credentials/issuer_spec.rb +9 -7
- data/spec/lib/oauth/client_credentials/validation_spec.rb +2 -2
- data/spec/lib/oauth/client_credentials_request_spec.rb +6 -6
- data/spec/lib/oauth/client_spec.rb +4 -4
- data/spec/lib/oauth/code_request_spec.rb +10 -9
- data/spec/lib/oauth/error_response_spec.rb +8 -8
- data/spec/lib/oauth/error_spec.rb +1 -1
- data/spec/lib/oauth/helpers/scope_checker_spec.rb +17 -17
- data/spec/lib/oauth/helpers/unique_token_spec.rb +7 -7
- data/spec/lib/oauth/helpers/uri_checker_spec.rb +33 -33
- data/spec/lib/oauth/invalid_token_response_spec.rb +4 -4
- data/spec/lib/oauth/password_access_token_request_spec.rb +13 -13
- data/spec/lib/oauth/pre_authorization_spec.rb +47 -7
- data/spec/lib/oauth/refresh_token_request_spec.rb +11 -21
- data/spec/lib/oauth/scopes_spec.rb +32 -32
- data/spec/lib/oauth/token_request_spec.rb +10 -9
- data/spec/lib/oauth/token_response_spec.rb +13 -15
- data/spec/lib/oauth/token_spec.rb +24 -10
- data/spec/lib/server_spec.rb +24 -2
- data/spec/models/doorkeeper/access_grant_spec.rb +8 -8
- data/spec/models/doorkeeper/access_token_spec.rb +79 -33
- data/spec/models/doorkeeper/application_spec.rb +29 -29
- data/spec/requests/applications/applications_request_spec.rb +15 -15
- data/spec/requests/applications/authorized_applications_spec.rb +7 -7
- data/spec/requests/endpoints/authorization_spec.rb +19 -12
- data/spec/requests/endpoints/token_spec.rb +26 -8
- data/spec/requests/flows/authorization_code_errors_spec.rb +17 -17
- data/spec/requests/flows/authorization_code_spec.rb +28 -28
- data/spec/requests/flows/client_credentials_spec.rb +3 -3
- data/spec/requests/flows/implicit_grant_errors_spec.rb +5 -5
- data/spec/requests/flows/implicit_grant_spec.rb +2 -2
- data/spec/requests/flows/password_spec.rb +32 -32
- data/spec/requests/flows/refresh_token_spec.rb +23 -23
- data/spec/requests/flows/revoke_token_spec.rb +165 -0
- data/spec/requests/flows/skip_authorization_spec.rb +10 -10
- data/spec/requests/protected_resources/metal_spec.rb +1 -1
- data/spec/requests/protected_resources/private_api_spec.rb +5 -5
- data/spec/routing/custom_controller_routes_spec.rb +4 -0
- data/spec/routing/default_routes_spec.rb +5 -1
- data/spec/spec_helper.rb +2 -2
- data/spec/spec_helper_integration.rb +8 -10
- data/spec/support/helpers/access_token_request_helper.rb +3 -3
- data/spec/support/helpers/authorization_request_helper.rb +3 -3
- data/spec/support/helpers/config_helper.rb +1 -1
- data/spec/support/helpers/model_helper.rb +2 -2
- data/spec/support/helpers/request_spec_helper.rb +3 -3
- data/spec/support/helpers/url_helper.rb +25 -21
- data/spec/support/orm/active_record.rb +4 -4
- data/spec/support/orm/mongo_mapper.rb +2 -3
- data/spec/support/orm/mongoid.rb +5 -6
- data/spec/support/shared/controllers_shared_context.rb +15 -15
- data/spec/support/shared/models_shared_examples.rb +13 -13
- data/spec/validators/redirect_uri_validator_spec.rb +9 -9
- metadata +5 -4
@@ -1,8 +1,8 @@
|
|
1
1
|
module Doorkeeper::FormErrorsHelper
|
2
|
-
def
|
2
|
+
def doorkeeper_errors_for(object, method)
|
3
3
|
if object.errors[method].present?
|
4
4
|
object.errors[method].map do |msg|
|
5
|
-
content_tag(:span, :
|
5
|
+
content_tag(:span, class: 'help-block') do
|
6
6
|
msg.capitalize
|
7
7
|
end
|
8
8
|
end.reduce(&:join).html_safe
|
@@ -7,7 +7,7 @@
|
|
7
7
|
<%= f.label :name, class: 'col-sm-2 control-label', for: 'application_name' %>
|
8
8
|
<div class="col-sm-10">
|
9
9
|
<%= f.text_field :name, class: 'form-control' %>
|
10
|
-
<%=
|
10
|
+
<%= doorkeeper_errors_for application, :name %>
|
11
11
|
</div>
|
12
12
|
<% end %>
|
13
13
|
|
@@ -15,7 +15,7 @@
|
|
15
15
|
<%= f.label :redirect_uri, class: 'col-sm-2 control-label', for: 'application_redirect_uri' %>
|
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 %>
|
19
19
|
<span class="help-block">
|
20
20
|
Use one line per URI
|
21
21
|
</span>
|
@@ -29,7 +29,7 @@
|
|
29
29
|
|
30
30
|
<div class="form-group">
|
31
31
|
<div class="col-sm-offset-2 col-sm-10">
|
32
|
-
<%= f.submit 'Submit', :
|
32
|
+
<%= f.submit 'Submit', class: "btn btn-primary" %>
|
33
33
|
<%= link_to "Cancel", oauth_applications_path, :class => "btn btn-default" %>
|
34
34
|
</div>
|
35
35
|
</div>
|
@@ -21,7 +21,7 @@
|
|
21
21
|
<code><%= uri %></code>
|
22
22
|
</td>
|
23
23
|
<td>
|
24
|
-
<%= link_to 'Authorize', oauth_authorization_path(:
|
24
|
+
<%= link_to 'Authorize', oauth_authorization_path(client_id: @application.uid, redirect_uri: uri, response_type: 'code'), class: 'btn btn-success', target: '_blank' %>
|
25
25
|
</td>
|
26
26
|
</tr>
|
27
27
|
<% end %>
|
@@ -13,28 +13,28 @@
|
|
13
13
|
|
14
14
|
<ul class="text-info">
|
15
15
|
<% @pre_auth.scopes.each do |scope| %>
|
16
|
-
<li><%= t scope, :
|
16
|
+
<li><%= t scope, scope: [:doorkeeper, :scopes] %></li>
|
17
17
|
<% end %>
|
18
18
|
</ul>
|
19
19
|
</div>
|
20
20
|
<% end %>
|
21
21
|
|
22
22
|
<div class="actions">
|
23
|
-
<%= form_tag oauth_authorization_path, :
|
23
|
+
<%= form_tag oauth_authorization_path, method: :post do %>
|
24
24
|
<%= hidden_field_tag :client_id, @pre_auth.client.uid %>
|
25
25
|
<%= hidden_field_tag :redirect_uri, @pre_auth.redirect_uri %>
|
26
26
|
<%= hidden_field_tag :state, @pre_auth.state %>
|
27
27
|
<%= hidden_field_tag :response_type, @pre_auth.response_type %>
|
28
28
|
<%= hidden_field_tag :scope, @pre_auth.scope %>
|
29
|
-
<%= submit_tag "Authorize", :
|
29
|
+
<%= submit_tag "Authorize", class: "btn btn-success btn-lg btn-block" %>
|
30
30
|
<% end %>
|
31
|
-
<%= form_tag oauth_authorization_path, :
|
31
|
+
<%= form_tag oauth_authorization_path, method: :delete do %>
|
32
32
|
<%= hidden_field_tag :client_id, @pre_auth.client.uid %>
|
33
33
|
<%= hidden_field_tag :redirect_uri, @pre_auth.redirect_uri %>
|
34
34
|
<%= hidden_field_tag :state, @pre_auth.state %>
|
35
35
|
<%= hidden_field_tag :response_type, @pre_auth.response_type %>
|
36
36
|
<%= hidden_field_tag :scope, @pre_auth.scope %>
|
37
|
-
<%= submit_tag "Deny", :
|
37
|
+
<%= submit_tag "Deny", class: "btn btn-danger btn-lg btn-block" %>
|
38
38
|
<% end %>
|
39
39
|
</div>
|
40
40
|
</main>
|
data/doorkeeper.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.version = Doorkeeper::VERSION
|
8
8
|
s.authors = ["Felipe Elias Philipp", "Piotr Jakubowski"]
|
9
9
|
s.email = ["felipe@applicake.com", "piotr.jakubowski@applicake.com"]
|
10
|
-
s.homepage = "https://github.com/
|
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."
|
13
13
|
s.license = 'MIT'
|
data/lib/doorkeeper.rb
CHANGED
@@ -1,45 +1,45 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require 'doorkeeper/version'
|
2
|
+
require 'doorkeeper/engine'
|
3
|
+
require 'doorkeeper/config'
|
4
|
+
require 'doorkeeper/doorkeeper_for'
|
5
5
|
|
6
6
|
require 'doorkeeper/errors'
|
7
7
|
require 'doorkeeper/server'
|
8
8
|
require 'doorkeeper/request'
|
9
|
-
require
|
10
|
-
|
11
|
-
require
|
12
|
-
require
|
13
|
-
require
|
14
|
-
require
|
15
|
-
require
|
16
|
-
require
|
17
|
-
|
18
|
-
require
|
19
|
-
require
|
20
|
-
require
|
21
|
-
require
|
22
|
-
require
|
23
|
-
require
|
24
|
-
require
|
25
|
-
require
|
26
|
-
require
|
27
|
-
require
|
28
|
-
require
|
29
|
-
require
|
30
|
-
require
|
31
|
-
require
|
32
|
-
require
|
9
|
+
require 'doorkeeper/validations'
|
10
|
+
|
11
|
+
require 'doorkeeper/oauth/authorization/code'
|
12
|
+
require 'doorkeeper/oauth/authorization/token'
|
13
|
+
require 'doorkeeper/oauth/authorization/uri_builder'
|
14
|
+
require 'doorkeeper/oauth/helpers/scope_checker'
|
15
|
+
require 'doorkeeper/oauth/helpers/uri_checker'
|
16
|
+
require 'doorkeeper/oauth/helpers/unique_token'
|
17
|
+
|
18
|
+
require 'doorkeeper/oauth/scopes'
|
19
|
+
require 'doorkeeper/oauth/error'
|
20
|
+
require 'doorkeeper/oauth/code_response'
|
21
|
+
require 'doorkeeper/oauth/token_response'
|
22
|
+
require 'doorkeeper/oauth/error_response'
|
23
|
+
require 'doorkeeper/oauth/pre_authorization'
|
24
|
+
require 'doorkeeper/oauth/authorization_code_request'
|
25
|
+
require 'doorkeeper/oauth/refresh_token_request'
|
26
|
+
require 'doorkeeper/oauth/password_access_token_request'
|
27
|
+
require 'doorkeeper/oauth/client_credentials_request'
|
28
|
+
require 'doorkeeper/oauth/code_request'
|
29
|
+
require 'doorkeeper/oauth/token_request'
|
30
|
+
require 'doorkeeper/oauth/client'
|
31
|
+
require 'doorkeeper/oauth/token'
|
32
|
+
require 'doorkeeper/oauth/invalid_token_response'
|
33
33
|
|
34
34
|
require 'doorkeeper/models/scopes'
|
35
35
|
require 'doorkeeper/models/expirable'
|
36
36
|
require 'doorkeeper/models/revocable'
|
37
37
|
require 'doorkeeper/models/accessible'
|
38
38
|
|
39
|
-
require
|
40
|
-
require
|
39
|
+
require 'doorkeeper/helpers/filter'
|
40
|
+
require 'doorkeeper/helpers/controller'
|
41
41
|
|
42
|
-
require
|
42
|
+
require 'doorkeeper/rails/routes'
|
43
43
|
|
44
44
|
module Doorkeeper
|
45
45
|
def self.configured?
|
data/lib/doorkeeper/config.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Doorkeeper
|
2
2
|
class MissingConfiguration < StandardError
|
3
3
|
def initialize
|
4
|
-
super(
|
4
|
+
super('Configuration for doorkeeper missing. Do you have doorkeeper initializer?')
|
5
5
|
end
|
6
6
|
end
|
7
7
|
|
@@ -12,17 +12,16 @@ module Doorkeeper
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def self.configuration
|
15
|
-
@config || (
|
15
|
+
@config || (fail MissingConfiguration.new)
|
16
16
|
end
|
17
17
|
|
18
18
|
def self.orm_model_dir
|
19
19
|
case configuration.orm
|
20
20
|
when :mongoid3, :mongoid4
|
21
|
-
|
21
|
+
'mongoid3_4'
|
22
22
|
else
|
23
23
|
configuration.orm
|
24
24
|
end
|
25
|
-
|
26
25
|
end
|
27
26
|
|
28
27
|
def self.enable_orm
|
@@ -50,42 +49,41 @@ module Doorkeeper
|
|
50
49
|
@config
|
51
50
|
end
|
52
51
|
|
53
|
-
def enable_application_owner(opts={})
|
54
|
-
@config.instance_variable_set(
|
52
|
+
def enable_application_owner(opts = {})
|
53
|
+
@config.instance_variable_set('@enable_application_owner', true)
|
55
54
|
confirm_application_owner if opts[:confirmation].present? && opts[:confirmation]
|
56
55
|
end
|
57
56
|
|
58
57
|
def confirm_application_owner
|
59
|
-
@config.instance_variable_set(
|
58
|
+
@config.instance_variable_set('@confirm_application_owner', true)
|
60
59
|
end
|
61
60
|
|
62
61
|
def default_scopes(*scopes)
|
63
|
-
@config.instance_variable_set(
|
62
|
+
@config.instance_variable_set('@default_scopes', Doorkeeper::OAuth::Scopes.from_array(scopes))
|
64
63
|
end
|
65
64
|
|
66
65
|
def optional_scopes(*scopes)
|
67
|
-
@config.instance_variable_set(
|
66
|
+
@config.instance_variable_set('@optional_scopes', Doorkeeper::OAuth::Scopes.from_array(scopes))
|
68
67
|
end
|
69
68
|
|
70
69
|
def client_credentials(*methods)
|
71
|
-
@config.instance_variable_set(
|
70
|
+
@config.instance_variable_set('@client_credentials', methods)
|
72
71
|
end
|
73
72
|
|
74
73
|
def access_token_methods(*methods)
|
75
|
-
@config.instance_variable_set(
|
74
|
+
@config.instance_variable_set('@access_token_methods', methods)
|
76
75
|
end
|
77
76
|
|
78
77
|
def use_refresh_token
|
79
|
-
@config.instance_variable_set(
|
78
|
+
@config.instance_variable_set('@refresh_token_enabled', true)
|
80
79
|
end
|
81
80
|
|
82
81
|
def realm(realm)
|
83
|
-
@config.instance_variable_set(
|
82
|
+
@config.instance_variable_set('@realm', realm)
|
84
83
|
end
|
85
84
|
end
|
86
85
|
|
87
86
|
module Option
|
88
|
-
|
89
87
|
# Defines configuration option
|
90
88
|
#
|
91
89
|
# When you call option, it defines two methods. One method will take place
|
@@ -109,9 +107,9 @@ module Doorkeeper
|
|
109
107
|
# ==== Examples
|
110
108
|
#
|
111
109
|
# option :name
|
112
|
-
# option :name, :
|
113
|
-
# option :name, :
|
114
|
-
# option :scopes :
|
110
|
+
# option :name, as: :set_name
|
111
|
+
# option :name, default: 'My Name'
|
112
|
+
# option :scopes builder_class: ScopesBuilder
|
115
113
|
#
|
116
114
|
def option(name, options = {})
|
117
115
|
attribute = options[:as] || name
|
@@ -121,10 +119,10 @@ module Doorkeeper
|
|
121
119
|
define_method name do |*args, &block|
|
122
120
|
# TODO: is builder_class option being used?
|
123
121
|
value = unless attribute_builder
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
122
|
+
block ? block : args.first
|
123
|
+
else
|
124
|
+
attribute_builder.new(&block).build
|
125
|
+
end
|
128
126
|
|
129
127
|
@config.instance_variable_set(:"@#{attribute}", value)
|
130
128
|
end
|
@@ -149,27 +147,29 @@ module Doorkeeper
|
|
149
147
|
extend Option
|
150
148
|
|
151
149
|
option :resource_owner_authenticator,
|
152
|
-
:
|
153
|
-
:
|
150
|
+
as: :authenticate_resource_owner,
|
151
|
+
default: (lambda do |routes|
|
154
152
|
logger.warn(I18n.translate('doorkeeper.errors.messages.resource_owner_authenticator_not_configured'))
|
155
153
|
nil
|
156
|
-
|
154
|
+
end)
|
157
155
|
option :admin_authenticator,
|
158
|
-
:
|
159
|
-
:
|
156
|
+
as: :authenticate_admin,
|
157
|
+
default: ->(routes) {}
|
160
158
|
option :resource_owner_from_credentials,
|
161
|
-
:
|
159
|
+
default: (lambda do |routes|
|
162
160
|
warn(I18n.translate('doorkeeper.errors.messages.credential_flow_not_configured'))
|
163
161
|
nil
|
164
|
-
|
165
|
-
option :skip_authorization,
|
166
|
-
option :access_token_expires_in,
|
167
|
-
option :authorization_code_expires_in
|
168
|
-
option :orm,
|
169
|
-
option :test_redirect_uri,
|
170
|
-
option :active_record_options,
|
171
|
-
option :realm,
|
172
|
-
option :wildcard_redirect_uri,
|
162
|
+
end)
|
163
|
+
option :skip_authorization, default: ->(routes) {}
|
164
|
+
option :access_token_expires_in, default: 7200
|
165
|
+
option :authorization_code_expires_in, default: 600
|
166
|
+
option :orm, default: :active_record
|
167
|
+
option :test_redirect_uri, default: 'urn:ietf:wg:oauth:2.0:oob'
|
168
|
+
option :active_record_options, default: {}
|
169
|
+
option :realm, default: 'Doorkeeper'
|
170
|
+
option :wildcard_redirect_uri, default: false
|
171
|
+
option :grant_flows,
|
172
|
+
default: %w(authorization_code implicit password client_credentials)
|
173
173
|
|
174
174
|
def refresh_token_enabled?
|
175
175
|
!!@refresh_token_enabled
|
@@ -208,7 +208,36 @@ module Doorkeeper
|
|
208
208
|
end
|
209
209
|
|
210
210
|
def realm
|
211
|
-
@realm ||=
|
211
|
+
@realm ||= 'Doorkeeper'
|
212
|
+
end
|
213
|
+
|
214
|
+
def authorization_response_types
|
215
|
+
@authorization_response_types ||= calculate_authorization_response_types
|
216
|
+
end
|
217
|
+
|
218
|
+
def token_grant_types
|
219
|
+
@token_grant_types ||= calculate_token_grant_types
|
220
|
+
end
|
221
|
+
|
222
|
+
private
|
223
|
+
|
224
|
+
# Determines what values are acceptable for 'response_type' param in
|
225
|
+
# authorization request endpoint, and return them as an array of strings.
|
226
|
+
#
|
227
|
+
def calculate_authorization_response_types
|
228
|
+
types = []
|
229
|
+
types << 'code' if grant_flows.include? 'authorization_code'
|
230
|
+
types << 'token' if grant_flows.include? 'implicit'
|
231
|
+
types
|
232
|
+
end
|
233
|
+
|
234
|
+
# Determines what values are acceptable for 'grant_type' param token
|
235
|
+
# request endpoint, and return them in array.
|
236
|
+
#
|
237
|
+
def calculate_token_grant_types
|
238
|
+
types = grant_flows - ['implicit']
|
239
|
+
types << 'refresh_token' if refresh_token_enabled?
|
240
|
+
types
|
212
241
|
end
|
213
242
|
end
|
214
243
|
end
|
@@ -3,7 +3,7 @@ module Doorkeeper
|
|
3
3
|
class DoorkeeperFor
|
4
4
|
def initialize(options)
|
5
5
|
options ||= {}
|
6
|
-
|
6
|
+
fail InvalidSyntax unless options.is_a? Hash
|
7
7
|
@filter_options = {}
|
8
8
|
|
9
9
|
options.each do |k, v|
|
@@ -14,7 +14,7 @@ module Doorkeeper
|
|
14
14
|
# TODO: move this to Token class
|
15
15
|
def validate_token(token)
|
16
16
|
return false unless token
|
17
|
-
token.accessible?
|
17
|
+
token.accessible? && validate_token_scopes(token)
|
18
18
|
end
|
19
19
|
|
20
20
|
def filter_options
|
@@ -22,6 +22,7 @@ module Doorkeeper
|
|
22
22
|
end
|
23
23
|
|
24
24
|
private
|
25
|
+
|
25
26
|
def scopes(scopes)
|
26
27
|
@scopes = scopes.map(&:to_s)
|
27
28
|
end
|
@@ -43,6 +44,7 @@ module Doorkeeper
|
|
43
44
|
|
44
45
|
class AllDoorkeeperFor < DoorkeeperFor
|
45
46
|
private
|
47
|
+
|
46
48
|
def except(actions)
|
47
49
|
@filter_options[:except] = actions
|
48
50
|
end
|
@@ -56,6 +58,7 @@ module Doorkeeper
|
|
56
58
|
end
|
57
59
|
|
58
60
|
private
|
61
|
+
|
59
62
|
def only(actions)
|
60
63
|
@filter_options[:only] = actions
|
61
64
|
end
|
@@ -67,7 +70,7 @@ module Doorkeeper
|
|
67
70
|
when :all
|
68
71
|
AllDoorkeeperFor.new(args[1] || {})
|
69
72
|
when Hash, nil
|
70
|
-
|
73
|
+
fail InvalidSyntax
|
71
74
|
else
|
72
75
|
SelectedDoorkeeperFor.new(*args)
|
73
76
|
end
|
data/lib/doorkeeper/engine.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module Doorkeeper
|
2
2
|
class Engine < Rails::Engine
|
3
|
-
initializer
|
3
|
+
initializer 'doorkeeper.routes' do
|
4
4
|
Doorkeeper::Rails::Routes.warn_if_using_mount_method!
|
5
5
|
Doorkeeper::Rails::Routes.install!
|
6
6
|
end
|
7
7
|
|
8
|
-
initializer
|
8
|
+
initializer 'doorkeeper.helpers' do
|
9
9
|
ActiveSupport.on_load(:action_controller) do
|
10
10
|
include Doorkeeper::Helpers::Filter
|
11
11
|
end
|