doorkeeper 5.1.0 → 5.5.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of doorkeeper might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/{NEWS.md → CHANGELOG.md} +242 -25
- data/README.md +21 -11
- data/app/controllers/doorkeeper/application_controller.rb +3 -2
- data/app/controllers/doorkeeper/application_metal_controller.rb +3 -2
- data/app/controllers/doorkeeper/applications_controller.rb +8 -7
- data/app/controllers/doorkeeper/authorizations_controller.rb +56 -19
- data/app/controllers/doorkeeper/authorized_applications_controller.rb +6 -6
- data/app/controllers/doorkeeper/token_info_controller.rb +12 -2
- data/app/controllers/doorkeeper/tokens_controller.rb +93 -25
- data/app/views/doorkeeper/applications/_form.html.erb +1 -7
- data/app/views/doorkeeper/applications/show.html.erb +35 -14
- data/app/views/doorkeeper/authorizations/form_post.html.erb +11 -0
- data/config/locales/en.yml +13 -3
- data/lib/doorkeeper/config/abstract_builder.rb +28 -0
- data/lib/doorkeeper/config/option.rb +20 -2
- data/lib/doorkeeper/config/validations.rb +53 -0
- data/lib/doorkeeper/config.rb +295 -121
- data/lib/doorkeeper/engine.rb +1 -1
- data/lib/doorkeeper/errors.rb +13 -18
- data/lib/doorkeeper/grant_flow/fallback_flow.rb +15 -0
- data/lib/doorkeeper/grant_flow/flow.rb +44 -0
- data/lib/doorkeeper/grant_flow/registry.rb +50 -0
- data/lib/doorkeeper/grant_flow.rb +45 -0
- data/lib/doorkeeper/grape/helpers.rb +7 -3
- data/lib/doorkeeper/helpers/controller.rb +36 -11
- data/lib/doorkeeper/models/access_grant_mixin.rb +22 -18
- data/lib/doorkeeper/models/access_token_mixin.rb +194 -51
- data/lib/doorkeeper/models/application_mixin.rb +8 -7
- data/lib/doorkeeper/models/concerns/ownership.rb +1 -1
- data/lib/doorkeeper/models/concerns/resource_ownerable.rb +47 -0
- data/lib/doorkeeper/models/concerns/reusable.rb +1 -1
- data/lib/doorkeeper/models/concerns/revocable.rb +1 -28
- data/lib/doorkeeper/models/concerns/scopes.rb +5 -1
- data/lib/doorkeeper/models/concerns/secret_storable.rb +1 -3
- data/lib/doorkeeper/oauth/authorization/code.rb +25 -14
- data/lib/doorkeeper/oauth/authorization/context.rb +5 -5
- data/lib/doorkeeper/oauth/authorization/token.rb +24 -19
- data/lib/doorkeeper/oauth/authorization/uri_builder.rb +4 -4
- data/lib/doorkeeper/oauth/authorization_code_request.rb +40 -21
- data/lib/doorkeeper/oauth/base_request.rb +21 -23
- data/lib/doorkeeper/oauth/client/credentials.rb +2 -4
- data/lib/doorkeeper/oauth/client.rb +8 -9
- data/lib/doorkeeper/oauth/client_credentials/creator.rb +45 -5
- data/lib/doorkeeper/oauth/client_credentials/issuer.rb +10 -8
- data/lib/doorkeeper/oauth/client_credentials/{validation.rb → validator.rb} +13 -3
- data/lib/doorkeeper/oauth/client_credentials_request.rb +8 -7
- data/lib/doorkeeper/oauth/code_request.rb +6 -12
- data/lib/doorkeeper/oauth/code_response.rb +24 -14
- data/lib/doorkeeper/oauth/error.rb +1 -1
- data/lib/doorkeeper/oauth/error_response.rb +10 -11
- data/lib/doorkeeper/oauth/helpers/scope_checker.rb +8 -12
- data/lib/doorkeeper/oauth/helpers/unique_token.rb +8 -5
- data/lib/doorkeeper/oauth/helpers/uri_checker.rb +19 -5
- data/lib/doorkeeper/oauth/hooks/context.rb +21 -0
- data/lib/doorkeeper/oauth/invalid_request_response.rb +43 -0
- data/lib/doorkeeper/oauth/invalid_token_response.rb +7 -4
- data/lib/doorkeeper/oauth/nonstandard.rb +39 -0
- data/lib/doorkeeper/oauth/password_access_token_request.rb +34 -11
- data/lib/doorkeeper/oauth/pre_authorization.rb +111 -42
- data/lib/doorkeeper/oauth/refresh_token_request.rb +45 -33
- data/lib/doorkeeper/oauth/token.rb +6 -7
- data/lib/doorkeeper/oauth/token_introspection.rb +24 -18
- data/lib/doorkeeper/oauth/token_request.rb +6 -20
- data/lib/doorkeeper/oauth/token_response.rb +1 -1
- data/lib/doorkeeper/orm/active_record/access_grant.rb +4 -43
- data/lib/doorkeeper/orm/active_record/access_token.rb +4 -35
- data/lib/doorkeeper/orm/active_record/application.rb +5 -83
- data/lib/doorkeeper/orm/active_record/mixins/access_grant.rb +68 -0
- data/lib/doorkeeper/orm/active_record/mixins/access_token.rb +59 -0
- data/lib/doorkeeper/orm/active_record/mixins/application.rb +198 -0
- data/lib/doorkeeper/orm/active_record/redirect_uri_validator.rb +66 -0
- data/lib/doorkeeper/orm/active_record.rb +20 -6
- data/lib/doorkeeper/rails/helpers.rb +4 -4
- data/lib/doorkeeper/rails/routes/abstract_router.rb +35 -0
- data/lib/doorkeeper/rails/routes/mapper.rb +2 -2
- data/lib/doorkeeper/rails/routes/registry.rb +45 -0
- data/lib/doorkeeper/rails/routes.rb +17 -25
- data/lib/doorkeeper/rake/db.rake +6 -6
- data/lib/doorkeeper/rake/setup.rake +5 -0
- data/lib/doorkeeper/request/authorization_code.rb +5 -3
- data/lib/doorkeeper/request/client_credentials.rb +2 -2
- data/lib/doorkeeper/request/password.rb +3 -2
- data/lib/doorkeeper/request/refresh_token.rb +5 -4
- data/lib/doorkeeper/request/strategy.rb +2 -2
- data/lib/doorkeeper/request.rb +49 -17
- data/lib/doorkeeper/server.rb +7 -11
- data/lib/doorkeeper/stale_records_cleaner.rb +6 -2
- data/lib/doorkeeper/version.rb +2 -6
- data/lib/doorkeeper.rb +114 -79
- data/lib/generators/doorkeeper/application_owner_generator.rb +1 -1
- data/lib/generators/doorkeeper/confidential_applications_generator.rb +2 -2
- data/lib/generators/doorkeeper/enable_polymorphic_resource_owner_generator.rb +39 -0
- data/lib/generators/doorkeeper/migration_generator.rb +1 -1
- data/lib/generators/doorkeeper/pkce_generator.rb +1 -1
- data/lib/generators/doorkeeper/previous_refresh_token_generator.rb +7 -7
- data/lib/generators/doorkeeper/templates/add_owner_to_application_migration.rb.erb +3 -1
- data/lib/generators/doorkeeper/templates/add_previous_refresh_token_to_access_tokens.rb.erb +2 -0
- data/lib/generators/doorkeeper/templates/enable_pkce_migration.rb.erb +2 -0
- data/lib/generators/doorkeeper/templates/enable_polymorphic_resource_owner_migration.rb.erb +17 -0
- data/lib/generators/doorkeeper/templates/initializer.rb +205 -43
- data/lib/generators/doorkeeper/templates/migration.rb.erb +18 -6
- metadata +45 -312
- data/.coveralls.yml +0 -1
- data/.github/ISSUE_TEMPLATE.md +0 -25
- data/.github/PULL_REQUEST_TEMPLATE.md +0 -17
- data/.gitignore +0 -20
- data/.gitlab-ci.yml +0 -16
- data/.hound.yml +0 -3
- data/.rspec +0 -1
- data/.rubocop.yml +0 -50
- data/.travis.yml +0 -35
- data/Appraisals +0 -40
- data/CODE_OF_CONDUCT.md +0 -46
- data/CONTRIBUTING.md +0 -47
- data/Dangerfile +0 -67
- data/Gemfile +0 -24
- data/RELEASING.md +0 -10
- data/Rakefile +0 -28
- data/SECURITY.md +0 -15
- data/UPGRADE.md +0 -2
- data/app/validators/redirect_uri_validator.rb +0 -50
- data/bin/console +0 -16
- data/doorkeeper.gemspec +0 -34
- data/gemfiles/rails_5_0.gemfile +0 -17
- data/gemfiles/rails_5_1.gemfile +0 -17
- data/gemfiles/rails_5_2.gemfile +0 -17
- data/gemfiles/rails_6_0.gemfile +0 -17
- data/gemfiles/rails_master.gemfile +0 -17
- data/spec/controllers/application_metal_controller_spec.rb +0 -64
- data/spec/controllers/applications_controller_spec.rb +0 -180
- data/spec/controllers/authorizations_controller_spec.rb +0 -527
- data/spec/controllers/protected_resources_controller_spec.rb +0 -353
- data/spec/controllers/token_info_controller_spec.rb +0 -50
- data/spec/controllers/tokens_controller_spec.rb +0 -330
- data/spec/dummy/Rakefile +0 -9
- data/spec/dummy/app/assets/config/manifest.js +0 -2
- data/spec/dummy/app/controllers/application_controller.rb +0 -5
- data/spec/dummy/app/controllers/custom_authorizations_controller.rb +0 -9
- data/spec/dummy/app/controllers/full_protected_resources_controller.rb +0 -14
- data/spec/dummy/app/controllers/home_controller.rb +0 -18
- data/spec/dummy/app/controllers/metal_controller.rb +0 -13
- data/spec/dummy/app/controllers/semi_protected_resources_controller.rb +0 -13
- data/spec/dummy/app/helpers/application_helper.rb +0 -7
- data/spec/dummy/app/models/user.rb +0 -7
- data/spec/dummy/app/views/home/index.html.erb +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +0 -14
- data/spec/dummy/config/application.rb +0 -47
- data/spec/dummy/config/boot.rb +0 -7
- data/spec/dummy/config/database.yml +0 -15
- data/spec/dummy/config/environment.rb +0 -5
- data/spec/dummy/config/environments/development.rb +0 -31
- data/spec/dummy/config/environments/production.rb +0 -64
- data/spec/dummy/config/environments/test.rb +0 -45
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -9
- data/spec/dummy/config/initializers/doorkeeper.rb +0 -121
- data/spec/dummy/config/initializers/secret_token.rb +0 -10
- data/spec/dummy/config/initializers/session_store.rb +0 -10
- data/spec/dummy/config/initializers/wrap_parameters.rb +0 -16
- data/spec/dummy/config/locales/doorkeeper.en.yml +0 -5
- data/spec/dummy/config/routes.rb +0 -13
- data/spec/dummy/config.ru +0 -6
- data/spec/dummy/db/migrate/20111122132257_create_users.rb +0 -11
- data/spec/dummy/db/migrate/20120312140401_add_password_to_users.rb +0 -7
- data/spec/dummy/db/migrate/20151223192035_create_doorkeeper_tables.rb +0 -69
- data/spec/dummy/db/migrate/20151223200000_add_owner_to_application.rb +0 -9
- data/spec/dummy/db/migrate/20160320211015_add_previous_refresh_token_to_access_tokens.rb +0 -13
- data/spec/dummy/db/migrate/20170822064514_enable_pkce.rb +0 -8
- data/spec/dummy/db/migrate/20180210183654_add_confidential_to_applications.rb +0 -13
- data/spec/dummy/db/schema.rb +0 -68
- data/spec/dummy/public/404.html +0 -26
- data/spec/dummy/public/422.html +0 -26
- data/spec/dummy/public/500.html +0 -26
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +0 -9
- data/spec/factories.rb +0 -30
- data/spec/generators/application_owner_generator_spec.rb +0 -28
- data/spec/generators/confidential_applications_generator_spec.rb +0 -29
- data/spec/generators/install_generator_spec.rb +0 -36
- data/spec/generators/migration_generator_spec.rb +0 -28
- data/spec/generators/pkce_generator_spec.rb +0 -28
- data/spec/generators/previous_refresh_token_generator_spec.rb +0 -44
- data/spec/generators/templates/routes.rb +0 -4
- data/spec/generators/views_generator_spec.rb +0 -29
- data/spec/grape/grape_integration_spec.rb +0 -137
- data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +0 -26
- data/spec/lib/config_spec.rb +0 -697
- data/spec/lib/doorkeeper_spec.rb +0 -27
- data/spec/lib/models/expirable_spec.rb +0 -61
- data/spec/lib/models/reusable_spec.rb +0 -40
- data/spec/lib/models/revocable_spec.rb +0 -59
- data/spec/lib/models/scopes_spec.rb +0 -53
- data/spec/lib/models/secret_storable_spec.rb +0 -135
- data/spec/lib/oauth/authorization/uri_builder_spec.rb +0 -39
- data/spec/lib/oauth/authorization_code_request_spec.rb +0 -156
- data/spec/lib/oauth/base_request_spec.rb +0 -205
- data/spec/lib/oauth/base_response_spec.rb +0 -47
- data/spec/lib/oauth/client/credentials_spec.rb +0 -90
- data/spec/lib/oauth/client_credentials/creator_spec.rb +0 -94
- data/spec/lib/oauth/client_credentials/issuer_spec.rb +0 -112
- data/spec/lib/oauth/client_credentials/validation_spec.rb +0 -59
- data/spec/lib/oauth/client_credentials_integration_spec.rb +0 -29
- data/spec/lib/oauth/client_credentials_request_spec.rb +0 -109
- data/spec/lib/oauth/client_spec.rb +0 -38
- data/spec/lib/oauth/code_request_spec.rb +0 -47
- data/spec/lib/oauth/code_response_spec.rb +0 -36
- data/spec/lib/oauth/error_response_spec.rb +0 -66
- data/spec/lib/oauth/error_spec.rb +0 -23
- data/spec/lib/oauth/forbidden_token_response_spec.rb +0 -22
- data/spec/lib/oauth/helpers/scope_checker_spec.rb +0 -98
- data/spec/lib/oauth/helpers/unique_token_spec.rb +0 -21
- data/spec/lib/oauth/helpers/uri_checker_spec.rb +0 -247
- data/spec/lib/oauth/invalid_token_response_spec.rb +0 -55
- data/spec/lib/oauth/password_access_token_request_spec.rb +0 -192
- data/spec/lib/oauth/pre_authorization_spec.rb +0 -215
- data/spec/lib/oauth/refresh_token_request_spec.rb +0 -177
- data/spec/lib/oauth/scopes_spec.rb +0 -148
- data/spec/lib/oauth/token_request_spec.rb +0 -150
- data/spec/lib/oauth/token_response_spec.rb +0 -86
- data/spec/lib/oauth/token_spec.rb +0 -158
- data/spec/lib/request/strategy_spec.rb +0 -54
- data/spec/lib/secret_storing/base_spec.rb +0 -60
- data/spec/lib/secret_storing/bcrypt_spec.rb +0 -49
- data/spec/lib/secret_storing/plain_spec.rb +0 -44
- data/spec/lib/secret_storing/sha256_hash_spec.rb +0 -48
- data/spec/lib/server_spec.rb +0 -61
- data/spec/lib/stale_records_cleaner_spec.rb +0 -89
- data/spec/models/doorkeeper/access_grant_spec.rb +0 -144
- data/spec/models/doorkeeper/access_token_spec.rb +0 -591
- data/spec/models/doorkeeper/application_spec.rb +0 -367
- data/spec/requests/applications/applications_request_spec.rb +0 -259
- data/spec/requests/applications/authorized_applications_spec.rb +0 -32
- data/spec/requests/endpoints/authorization_spec.rb +0 -73
- data/spec/requests/endpoints/token_spec.rb +0 -75
- data/spec/requests/flows/authorization_code_errors_spec.rb +0 -78
- data/spec/requests/flows/authorization_code_spec.rb +0 -447
- data/spec/requests/flows/client_credentials_spec.rb +0 -128
- data/spec/requests/flows/implicit_grant_errors_spec.rb +0 -34
- data/spec/requests/flows/implicit_grant_spec.rb +0 -90
- data/spec/requests/flows/password_spec.rb +0 -259
- data/spec/requests/flows/refresh_token_spec.rb +0 -233
- data/spec/requests/flows/revoke_token_spec.rb +0 -143
- data/spec/requests/flows/skip_authorization_spec.rb +0 -66
- data/spec/requests/protected_resources/metal_spec.rb +0 -16
- data/spec/requests/protected_resources/private_api_spec.rb +0 -83
- data/spec/routing/custom_controller_routes_spec.rb +0 -133
- data/spec/routing/default_routes_spec.rb +0 -41
- data/spec/routing/scoped_routes_spec.rb +0 -47
- data/spec/spec_helper.rb +0 -57
- data/spec/spec_helper_integration.rb +0 -4
- data/spec/support/dependencies/factory_bot.rb +0 -4
- data/spec/support/doorkeeper_rspec.rb +0 -22
- data/spec/support/helpers/access_token_request_helper.rb +0 -13
- data/spec/support/helpers/authorization_request_helper.rb +0 -43
- data/spec/support/helpers/config_helper.rb +0 -11
- data/spec/support/helpers/model_helper.rb +0 -78
- data/spec/support/helpers/request_spec_helper.rb +0 -98
- data/spec/support/helpers/url_helper.rb +0 -62
- data/spec/support/http_method_shim.rb +0 -29
- data/spec/support/orm/active_record.rb +0 -5
- data/spec/support/shared/controllers_shared_context.rb +0 -123
- data/spec/support/shared/hashing_shared_context.rb +0 -36
- data/spec/support/shared/models_shared_examples.rb +0 -54
- data/spec/validators/redirect_uri_validator_spec.rb +0 -158
- data/spec/version/version_spec.rb +0 -17
@@ -1,330 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
|
-
describe Doorkeeper::TokensController do
|
6
|
-
describe "when authorization has succeeded" do
|
7
|
-
let(:token) { double(:token, authorize: true) }
|
8
|
-
|
9
|
-
it "returns the authorization" do
|
10
|
-
skip "verify need of these specs"
|
11
|
-
|
12
|
-
expect(token).to receive(:authorization)
|
13
|
-
|
14
|
-
post :create
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe "when authorization has failed" do
|
19
|
-
it "returns the error response" do
|
20
|
-
token = double(:token, authorize: false)
|
21
|
-
allow(controller).to receive(:token) { token }
|
22
|
-
|
23
|
-
post :create
|
24
|
-
|
25
|
-
expect(response.status).to eq 400
|
26
|
-
expect(response.headers["WWW-Authenticate"]).to match(/Bearer/)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe "when there is a failure due to a custom error" do
|
31
|
-
it "returns the error response with a custom message" do
|
32
|
-
# I18n looks for `doorkeeper.errors.messages.custom_message` in locale files
|
33
|
-
custom_message = "my_message"
|
34
|
-
allow(I18n).to receive(:translate)
|
35
|
-
.with(
|
36
|
-
custom_message,
|
37
|
-
hash_including(scope: %i[doorkeeper errors messages])
|
38
|
-
)
|
39
|
-
.and_return("Authorization custom message")
|
40
|
-
|
41
|
-
doorkeeper_error = Doorkeeper::Errors::DoorkeeperError.new(custom_message)
|
42
|
-
|
43
|
-
strategy = double(:strategy)
|
44
|
-
request = double(token_request: strategy)
|
45
|
-
allow(strategy).to receive(:authorize).and_raise(doorkeeper_error)
|
46
|
-
allow(controller).to receive(:server).and_return(request)
|
47
|
-
|
48
|
-
post :create
|
49
|
-
|
50
|
-
expected_response_body = {
|
51
|
-
"error" => custom_message,
|
52
|
-
"error_description" => "Authorization custom message",
|
53
|
-
}
|
54
|
-
expect(response.status).to eq 400
|
55
|
-
expect(response.headers["WWW-Authenticate"]).to match(/Bearer/)
|
56
|
-
expect(JSON.parse(response.body)).to eq expected_response_body
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
# http://tools.ietf.org/html/rfc7009#section-2.2
|
61
|
-
describe "revoking tokens" do
|
62
|
-
let(:client) { FactoryBot.create(:application) }
|
63
|
-
let(:access_token) { FactoryBot.create(:access_token, application: client) }
|
64
|
-
|
65
|
-
context "when associated app is public" do
|
66
|
-
let(:client) { FactoryBot.create(:application, confidential: false) }
|
67
|
-
|
68
|
-
it "returns 200" do
|
69
|
-
post :revoke, params: { token: access_token.token }
|
70
|
-
|
71
|
-
expect(response.status).to eq 200
|
72
|
-
end
|
73
|
-
|
74
|
-
it "revokes the access token" do
|
75
|
-
post :revoke, params: { token: access_token.token }
|
76
|
-
|
77
|
-
expect(access_token.reload).to have_attributes(revoked?: true)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
context "when associated app is confidential" do
|
82
|
-
let(:client) { FactoryBot.create(:application, confidential: true) }
|
83
|
-
let(:oauth_client) { Doorkeeper::OAuth::Client.new(client) }
|
84
|
-
|
85
|
-
before(:each) do
|
86
|
-
allow_any_instance_of(Doorkeeper::Server).to receive(:client) { oauth_client }
|
87
|
-
end
|
88
|
-
|
89
|
-
it "returns 200" do
|
90
|
-
post :revoke, params: { token: access_token.token }
|
91
|
-
|
92
|
-
expect(response.status).to eq 200
|
93
|
-
end
|
94
|
-
|
95
|
-
it "revokes the access token" do
|
96
|
-
post :revoke, params: { token: access_token.token }
|
97
|
-
|
98
|
-
expect(access_token.reload).to have_attributes(revoked?: true)
|
99
|
-
end
|
100
|
-
|
101
|
-
context "when authorization fails" do
|
102
|
-
let(:some_other_client) { FactoryBot.create(:application, confidential: true) }
|
103
|
-
let(:oauth_client) { Doorkeeper::OAuth::Client.new(some_other_client) }
|
104
|
-
|
105
|
-
it "returns 200" do
|
106
|
-
post :revoke, params: { token: access_token.token }
|
107
|
-
|
108
|
-
expect(response.status).to eq 200
|
109
|
-
end
|
110
|
-
|
111
|
-
it "does not revoke the access token" do
|
112
|
-
post :revoke, params: { token: access_token.token }
|
113
|
-
|
114
|
-
expect(access_token.reload).to have_attributes(revoked?: false)
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
describe "authorize response memoization" do
|
121
|
-
it "memoizes the result of the authorization" do
|
122
|
-
strategy = double(:strategy, authorize: true)
|
123
|
-
expect(strategy).to receive(:authorize).once
|
124
|
-
allow(controller).to receive(:strategy) { strategy }
|
125
|
-
allow(controller).to receive(:create) do
|
126
|
-
2.times { controller.send :authorize_response }
|
127
|
-
controller.render json: {}, status: :ok
|
128
|
-
end
|
129
|
-
|
130
|
-
post :create
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
describe "when requested token introspection" do
|
135
|
-
let(:client) { FactoryBot.create(:application) }
|
136
|
-
let(:access_token) { FactoryBot.create(:access_token, application: client) }
|
137
|
-
let(:token_for_introspection) { FactoryBot.create(:access_token, application: client) }
|
138
|
-
|
139
|
-
context "authorized using valid Bearer token" do
|
140
|
-
it "responds with full token introspection" do
|
141
|
-
request.headers["Authorization"] = "Bearer #{access_token.token}"
|
142
|
-
|
143
|
-
post :introspect, params: { token: token_for_introspection.token }
|
144
|
-
|
145
|
-
should_have_json "active", true
|
146
|
-
expect(json_response).to include("client_id", "token_type", "exp", "iat")
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
context "authorized using valid Client Authentication" do
|
151
|
-
it "responds with full token introspection" do
|
152
|
-
request.headers["Authorization"] = basic_auth_header_for_client(client)
|
153
|
-
|
154
|
-
post :introspect, params: { token: token_for_introspection.token }
|
155
|
-
|
156
|
-
should_have_json "active", true
|
157
|
-
expect(json_response).to include("client_id", "token_type", "exp", "iat")
|
158
|
-
should_have_json "client_id", client.uid
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
context "using custom introspection response" do
|
163
|
-
before do
|
164
|
-
Doorkeeper.configure do
|
165
|
-
orm DOORKEEPER_ORM
|
166
|
-
custom_introspection_response do |_token, _context|
|
167
|
-
{
|
168
|
-
sub: "Z5O3upPC88QrAjx00dis",
|
169
|
-
aud: "https://protected.example.net/resource",
|
170
|
-
}
|
171
|
-
end
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
it "responds with full token introspection" do
|
176
|
-
request.headers["Authorization"] = "Bearer #{access_token.token}"
|
177
|
-
|
178
|
-
post :introspect, params: { token: token_for_introspection.token }
|
179
|
-
|
180
|
-
expect(json_response).to include("client_id", "token_type", "exp", "iat", "sub", "aud")
|
181
|
-
should_have_json "sub", "Z5O3upPC88QrAjx00dis"
|
182
|
-
should_have_json "aud", "https://protected.example.net/resource"
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
context "public access token" do
|
187
|
-
let(:token_for_introspection) { FactoryBot.create(:access_token, application: nil) }
|
188
|
-
|
189
|
-
it "responds with full token introspection" do
|
190
|
-
request.headers["Authorization"] = basic_auth_header_for_client(client)
|
191
|
-
|
192
|
-
post :introspect, params: { token: token_for_introspection.token }
|
193
|
-
|
194
|
-
should_have_json "active", true
|
195
|
-
expect(json_response).to include("client_id", "token_type", "exp", "iat")
|
196
|
-
should_have_json "client_id", nil
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
context "token was issued to a different client than is making this request" do
|
201
|
-
let(:different_client) { FactoryBot.create(:application) }
|
202
|
-
|
203
|
-
it "responds with only active state" do
|
204
|
-
request.headers["Authorization"] = basic_auth_header_for_client(different_client)
|
205
|
-
|
206
|
-
post :introspect, params: { token: token_for_introspection.token }
|
207
|
-
|
208
|
-
expect(response).to be_successful
|
209
|
-
|
210
|
-
should_have_json "active", false
|
211
|
-
expect(json_response).not_to include("client_id", "token_type", "exp", "iat")
|
212
|
-
end
|
213
|
-
end
|
214
|
-
|
215
|
-
context "authorized using invalid Bearer token" do
|
216
|
-
let(:access_token) do
|
217
|
-
FactoryBot.create(:access_token, application: client, revoked_at: 1.day.ago)
|
218
|
-
end
|
219
|
-
|
220
|
-
it "responds with invalid token error" do
|
221
|
-
request.headers["Authorization"] = "Bearer #{access_token.token}"
|
222
|
-
|
223
|
-
post :introspect, params: { token: token_for_introspection.token }
|
224
|
-
|
225
|
-
response_status_should_be 401
|
226
|
-
|
227
|
-
should_not_have_json "active"
|
228
|
-
should_have_json "error", "invalid_token"
|
229
|
-
end
|
230
|
-
end
|
231
|
-
|
232
|
-
context "authorized using the Bearer token that need to be introspected" do
|
233
|
-
it "responds with invalid token error" do
|
234
|
-
request.headers["Authorization"] = "Bearer #{access_token.token}"
|
235
|
-
|
236
|
-
post :introspect, params: { token: access_token.token }
|
237
|
-
|
238
|
-
response_status_should_be 401
|
239
|
-
|
240
|
-
should_not_have_json "active"
|
241
|
-
should_have_json "error", "invalid_token"
|
242
|
-
end
|
243
|
-
end
|
244
|
-
|
245
|
-
context "using invalid credentials to authorize" do
|
246
|
-
let(:client) { double(uid: "123123", secret: "666999") }
|
247
|
-
let(:access_token) { FactoryBot.create(:access_token) }
|
248
|
-
|
249
|
-
it "responds with invalid_client error" do
|
250
|
-
request.headers["Authorization"] = basic_auth_header_for_client(client)
|
251
|
-
|
252
|
-
post :introspect, params: { token: access_token.token }
|
253
|
-
|
254
|
-
expect(response).not_to be_successful
|
255
|
-
response_status_should_be 401
|
256
|
-
|
257
|
-
should_not_have_json "active"
|
258
|
-
should_have_json "error", "invalid_client"
|
259
|
-
end
|
260
|
-
end
|
261
|
-
|
262
|
-
context "using wrong token value" do
|
263
|
-
context "authorized using client credentials" do
|
264
|
-
it "responds with only active state" do
|
265
|
-
request.headers["Authorization"] = basic_auth_header_for_client(client)
|
266
|
-
|
267
|
-
post :introspect, params: { token: SecureRandom.hex(16) }
|
268
|
-
|
269
|
-
should_have_json "active", false
|
270
|
-
expect(json_response).not_to include("client_id", "token_type", "exp", "iat")
|
271
|
-
end
|
272
|
-
end
|
273
|
-
|
274
|
-
context "authorized using valid Bearer token" do
|
275
|
-
it "responds with only active state" do
|
276
|
-
request.headers["Authorization"] = "Bearer #{access_token.token}"
|
277
|
-
|
278
|
-
post :introspect, params: { token: SecureRandom.hex(16) }
|
279
|
-
|
280
|
-
should_have_json "active", false
|
281
|
-
expect(json_response).not_to include("client_id", "token_type", "exp", "iat")
|
282
|
-
end
|
283
|
-
end
|
284
|
-
end
|
285
|
-
|
286
|
-
context "when requested access token expired" do
|
287
|
-
let(:token_for_introspection) do
|
288
|
-
FactoryBot.create(:access_token, application: client, created_at: 1.year.ago)
|
289
|
-
end
|
290
|
-
|
291
|
-
it "responds with only active state" do
|
292
|
-
request.headers["Authorization"] = basic_auth_header_for_client(client)
|
293
|
-
|
294
|
-
post :introspect, params: { token: token_for_introspection.token }
|
295
|
-
|
296
|
-
should_have_json "active", false
|
297
|
-
expect(json_response).not_to include("client_id", "token_type", "exp", "iat")
|
298
|
-
end
|
299
|
-
end
|
300
|
-
|
301
|
-
context "when requested Access Token revoked" do
|
302
|
-
let(:token_for_introspection) do
|
303
|
-
FactoryBot.create(:access_token, application: client, revoked_at: 1.year.ago)
|
304
|
-
end
|
305
|
-
|
306
|
-
it "responds with only active state" do
|
307
|
-
request.headers["Authorization"] = basic_auth_header_for_client(client)
|
308
|
-
|
309
|
-
post :introspect, params: { token: token_for_introspection.token }
|
310
|
-
|
311
|
-
should_have_json "active", false
|
312
|
-
expect(json_response).not_to include("client_id", "token_type", "exp", "iat")
|
313
|
-
end
|
314
|
-
end
|
315
|
-
|
316
|
-
context "unauthorized (no bearer token or client credentials)" do
|
317
|
-
let(:token_for_introspection) { FactoryBot.create(:access_token) }
|
318
|
-
|
319
|
-
it "responds with invalid_request error" do
|
320
|
-
post :introspect, params: { token: token_for_introspection.token }
|
321
|
-
|
322
|
-
expect(response).not_to be_successful
|
323
|
-
response_status_should_be 400
|
324
|
-
|
325
|
-
should_not_have_json "active"
|
326
|
-
should_have_json "error", "invalid_request"
|
327
|
-
end
|
328
|
-
end
|
329
|
-
end
|
330
|
-
end
|
data/spec/dummy/Rakefile
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
#!/usr/bin/env rake
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
5
|
-
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
6
|
-
|
7
|
-
require File.expand_path("config/application", __dir__)
|
8
|
-
|
9
|
-
Dummy::Application.load_tasks
|
@@ -1,14 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class FullProtectedResourcesController < ApplicationController
|
4
|
-
before_action -> { doorkeeper_authorize! :write, :admin }, only: :show
|
5
|
-
before_action :doorkeeper_authorize!, only: :index
|
6
|
-
|
7
|
-
def index
|
8
|
-
render plain: "index"
|
9
|
-
end
|
10
|
-
|
11
|
-
def show
|
12
|
-
render plain: "show"
|
13
|
-
end
|
14
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class HomeController < ApplicationController
|
4
|
-
def index; end
|
5
|
-
|
6
|
-
def sign_in
|
7
|
-
session[:user_id] = if Rails.env.development?
|
8
|
-
User.first || User.create!(name: "Joe", password: "sekret")
|
9
|
-
else
|
10
|
-
User.first
|
11
|
-
end
|
12
|
-
redirect_to "/"
|
13
|
-
end
|
14
|
-
|
15
|
-
def callback
|
16
|
-
render plain: "ok"
|
17
|
-
end
|
18
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class MetalController < ActionController::Metal
|
4
|
-
include AbstractController::Callbacks
|
5
|
-
include ActionController::Head
|
6
|
-
include Doorkeeper::Rails::Helpers
|
7
|
-
|
8
|
-
before_action :doorkeeper_authorize!
|
9
|
-
|
10
|
-
def index
|
11
|
-
self.response_body = { ok: true }.to_json
|
12
|
-
end
|
13
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class SemiProtectedResourcesController < ApplicationController
|
4
|
-
before_action :doorkeeper_authorize!, only: :index
|
5
|
-
|
6
|
-
def index
|
7
|
-
render plain: "protected index"
|
8
|
-
end
|
9
|
-
|
10
|
-
def show
|
11
|
-
render plain: "non protected show"
|
12
|
-
end
|
13
|
-
end
|
File without changes
|
@@ -1,47 +0,0 @@
|
|
1
|
-
require File.expand_path('boot', __dir__)
|
2
|
-
|
3
|
-
require "rails"
|
4
|
-
|
5
|
-
%w[
|
6
|
-
action_controller/railtie
|
7
|
-
action_view/railtie
|
8
|
-
sprockets/railtie
|
9
|
-
].each do |railtie|
|
10
|
-
begin
|
11
|
-
require railtie
|
12
|
-
rescue LoadError
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
Bundler.require(*Rails.groups)
|
17
|
-
|
18
|
-
require 'yaml'
|
19
|
-
|
20
|
-
orm = if DOORKEEPER_ORM =~ /mongoid/
|
21
|
-
Mongoid.load!(File.join(File.dirname(File.expand_path(__FILE__)), "#{DOORKEEPER_ORM}.yml"))
|
22
|
-
:mongoid
|
23
|
-
else
|
24
|
-
DOORKEEPER_ORM
|
25
|
-
end
|
26
|
-
require "#{orm}/railtie"
|
27
|
-
|
28
|
-
module Dummy
|
29
|
-
class Application < Rails::Application
|
30
|
-
if Rails.gem_version < Gem::Version.new('5.1')
|
31
|
-
config.action_controller.per_form_csrf_tokens = true
|
32
|
-
config.action_controller.forgery_protection_origin_check = true
|
33
|
-
|
34
|
-
ActiveSupport.to_time_preserves_timezone = true
|
35
|
-
|
36
|
-
config.active_record.belongs_to_required_by_default = true
|
37
|
-
|
38
|
-
config.ssl_options = { hsts: { subdomains: true } }
|
39
|
-
else
|
40
|
-
config.load_defaults "#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}"
|
41
|
-
end
|
42
|
-
|
43
|
-
# Settings in config/environments/* take precedence over those specified here.
|
44
|
-
# Application configuration should go into files in config/initializers
|
45
|
-
# -- all .rb files in that directory are automatically loaded.
|
46
|
-
end
|
47
|
-
end
|
data/spec/dummy/config/boot.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
Dummy::Application.configure do
|
4
|
-
# Settings specified here will take precedence over those in config/application.rb
|
5
|
-
|
6
|
-
# In the development environment your application's code is reloaded on
|
7
|
-
# every request. This slows down response time but is perfect for development
|
8
|
-
# since you don't have to restart the web server when you make code changes.
|
9
|
-
config.cache_classes = false
|
10
|
-
|
11
|
-
# Show full error reports and disable caching
|
12
|
-
config.consider_all_requests_local = true
|
13
|
-
config.action_controller.perform_caching = false
|
14
|
-
|
15
|
-
# Don't care if the mailer can't send
|
16
|
-
# config.action_mailer.raise_delivery_errors = false
|
17
|
-
|
18
|
-
# Print deprecation notices to the Rails logger
|
19
|
-
config.active_support.deprecation = :log
|
20
|
-
|
21
|
-
# Only use best-standards-support built into browsers
|
22
|
-
config.action_dispatch.best_standards_support = :builtin
|
23
|
-
|
24
|
-
# Do not compress assets
|
25
|
-
config.assets.compress = false
|
26
|
-
|
27
|
-
# Expands the lines which load the assets
|
28
|
-
config.assets.debug = true
|
29
|
-
|
30
|
-
config.eager_load = false
|
31
|
-
end
|
@@ -1,64 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
Dummy::Application.configure do
|
4
|
-
# Settings specified here will take precedence over those in config/application.rb
|
5
|
-
|
6
|
-
# Code is not reloaded between requests
|
7
|
-
config.cache_classes = true
|
8
|
-
|
9
|
-
# Full error reports are disabled and caching is turned on
|
10
|
-
config.consider_all_requests_local = false
|
11
|
-
config.action_controller.perform_caching = true
|
12
|
-
|
13
|
-
# Disable Rails's static asset server (Apache or nginx will already do this)
|
14
|
-
config.serve_static_assets = false
|
15
|
-
|
16
|
-
# Compress JavaScripts and CSS
|
17
|
-
config.assets.compress = true
|
18
|
-
|
19
|
-
# Don't fallback to assets pipeline if a precompiled asset is missed
|
20
|
-
config.assets.compile = false
|
21
|
-
|
22
|
-
# Generate digests for assets URLs
|
23
|
-
config.assets.digest = true
|
24
|
-
|
25
|
-
# Defaults to Rails.root.join("public/assets")
|
26
|
-
# config.assets.manifest = YOUR_PATH
|
27
|
-
|
28
|
-
# Specifies the header that your server uses for sending files
|
29
|
-
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
|
30
|
-
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
|
31
|
-
|
32
|
-
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
|
33
|
-
# config.force_ssl = true
|
34
|
-
|
35
|
-
# See everything in the log (default is :info)
|
36
|
-
# config.log_level = :debug
|
37
|
-
|
38
|
-
# Use a different logger for distributed setups
|
39
|
-
# config.logger = SyslogLogger.new
|
40
|
-
|
41
|
-
# Use a different cache store in production
|
42
|
-
# config.cache_store = :mem_cache_store
|
43
|
-
|
44
|
-
# Enable serving of images, stylesheets, and JavaScripts from an asset server
|
45
|
-
# config.action_controller.asset_host = "http://assets.example.com"
|
46
|
-
|
47
|
-
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
|
48
|
-
# config.assets.precompile += %w( search.js )
|
49
|
-
|
50
|
-
# Disable delivery errors, bad email addresses will be ignored
|
51
|
-
# config.action_mailer.raise_delivery_errors = false
|
52
|
-
|
53
|
-
# Enable threaded mode
|
54
|
-
# config.threadsafe!
|
55
|
-
|
56
|
-
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
|
57
|
-
# the I18n.default_locale when a translation can not be found)
|
58
|
-
config.i18n.fallbacks = true
|
59
|
-
|
60
|
-
# Send deprecation notices to registered listeners
|
61
|
-
config.active_support.deprecation = :notify
|
62
|
-
|
63
|
-
config.eager_load = true
|
64
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
Dummy::Application.configure do
|
4
|
-
# Settings specified here will take precedence over those in config/application.rb
|
5
|
-
|
6
|
-
# The test environment is used exclusively to run your application's
|
7
|
-
# test suite. You never need to work with it otherwise. Remember that
|
8
|
-
# your test database is "scratch space" for the test suite and is wiped
|
9
|
-
# and recreated between test runs. Don't rely on the data there!
|
10
|
-
config.cache_classes = true
|
11
|
-
|
12
|
-
config.assets.enabled = true
|
13
|
-
config.assets.version = "1.0"
|
14
|
-
config.assets.digest = false
|
15
|
-
|
16
|
-
# Do not eager load code on boot. This avoids loading your whole application
|
17
|
-
# just for the purpose of running a single test. If you are using a tool that
|
18
|
-
# preloads Rails for running tests, you may have to set it to true.
|
19
|
-
config.eager_load = false
|
20
|
-
|
21
|
-
# Show full error reports and disable caching
|
22
|
-
config.consider_all_requests_local = true
|
23
|
-
config.action_controller.perform_caching = false
|
24
|
-
|
25
|
-
# Raise exceptions instead of rendering exception templates
|
26
|
-
config.action_dispatch.show_exceptions = false
|
27
|
-
|
28
|
-
# Disable request forgery protection in test environment
|
29
|
-
config.action_controller.allow_forgery_protection = false
|
30
|
-
|
31
|
-
# Tell Action Mailer not to deliver emails to the real world.
|
32
|
-
# The :test delivery method accumulates sent emails in the
|
33
|
-
# ActionMailer::Base.deliveries array.
|
34
|
-
# config.action_mailer.delivery_method = :test
|
35
|
-
|
36
|
-
# Use SQL instead of Active Record's schema dumper when creating the test database.
|
37
|
-
# This is necessary if your schema can't be completely dumped by the schema dumper,
|
38
|
-
# like if you have constraints or database-specific column types
|
39
|
-
# config.active_record.schema_format = :sql
|
40
|
-
|
41
|
-
# Print deprecation notices to the stderr
|
42
|
-
config.active_support.deprecation = :stderr
|
43
|
-
|
44
|
-
config.eager_load = true
|
45
|
-
end
|