doorkeeper 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -6,32 +6,31 @@ module Doorkeeper
|
|
6
6
|
|
7
7
|
def initialize
|
8
8
|
@controllers = {
|
9
|
-
:
|
10
|
-
:
|
11
|
-
:
|
12
|
-
:
|
13
|
-
:
|
9
|
+
authorizations: 'doorkeeper/authorizations',
|
10
|
+
applications: 'doorkeeper/applications',
|
11
|
+
authorized_applications: 'doorkeeper/authorized_applications',
|
12
|
+
tokens: 'doorkeeper/tokens',
|
13
|
+
token_info: 'doorkeeper/token_info'
|
14
14
|
}
|
15
15
|
|
16
16
|
@as = {
|
17
|
-
:
|
18
|
-
:
|
19
|
-
:
|
17
|
+
authorizations: :authorization,
|
18
|
+
tokens: :token,
|
19
|
+
token_info: :token_info
|
20
20
|
}
|
21
21
|
|
22
22
|
@skips = []
|
23
|
-
|
24
23
|
end
|
25
24
|
|
26
25
|
def [](routes)
|
27
26
|
{
|
28
|
-
:
|
29
|
-
:
|
27
|
+
controllers: @controllers[routes],
|
28
|
+
as: @as[routes]
|
30
29
|
}
|
31
30
|
end
|
32
31
|
|
33
32
|
def skipped?(controller)
|
34
|
-
|
33
|
+
@skips.include?(controller)
|
35
34
|
end
|
36
35
|
end
|
37
36
|
end
|
data/lib/doorkeeper/request.rb
CHANGED
@@ -7,23 +7,23 @@ require 'doorkeeper/request/token'
|
|
7
7
|
|
8
8
|
module Doorkeeper
|
9
9
|
module Request
|
10
|
-
|
10
|
+
module_function
|
11
11
|
|
12
12
|
def authorization_strategy(strategy)
|
13
|
-
get_strategy strategy,
|
13
|
+
get_strategy strategy, Doorkeeper.configuration.authorization_response_types
|
14
14
|
rescue NameError
|
15
15
|
raise Errors::InvalidAuthorizationStrategy
|
16
16
|
end
|
17
17
|
|
18
18
|
def token_strategy(strategy)
|
19
|
-
get_strategy strategy,
|
19
|
+
get_strategy strategy, Doorkeeper.configuration.token_grant_types
|
20
20
|
rescue NameError
|
21
21
|
raise Errors::InvalidTokenStrategy
|
22
22
|
end
|
23
23
|
|
24
24
|
def get_strategy(strategy, available)
|
25
|
-
|
26
|
-
|
25
|
+
fail Errors::MissingRequestStrategy unless strategy.present?
|
26
|
+
fail NameError unless available.include?(strategy.to_s)
|
27
27
|
"Doorkeeper::Request::#{strategy.to_s.camelize}".constantize
|
28
28
|
end
|
29
29
|
end
|
data/lib/doorkeeper/version.rb
CHANGED
@@ -3,7 +3,7 @@ require 'rails/generators/active_record'
|
|
3
3
|
class Doorkeeper::ApplicationOwnerGenerator < Rails::Generators::Base
|
4
4
|
include Rails::Generators::Migration
|
5
5
|
source_root File.expand_path('../templates', __FILE__)
|
6
|
-
desc
|
6
|
+
desc 'Provide support for client application ownership.'
|
7
7
|
|
8
8
|
def application_owner
|
9
9
|
migration_template 'add_owner_to_application_migration.rb', 'db/migrate/add_owner_to_application.rb'
|
@@ -1,12 +1,12 @@
|
|
1
1
|
class Doorkeeper::InstallGenerator < ::Rails::Generators::Base
|
2
2
|
include Rails::Generators::Migration
|
3
3
|
source_root File.expand_path('../templates', __FILE__)
|
4
|
-
desc
|
4
|
+
desc 'Installs Doorkeeper.'
|
5
5
|
|
6
6
|
def install
|
7
|
-
template
|
8
|
-
copy_file
|
9
|
-
route
|
10
|
-
readme
|
7
|
+
template 'initializer.rb', 'config/initializers/doorkeeper.rb'
|
8
|
+
copy_file File.expand_path('../../../../config/locales/en.yml', __FILE__), 'config/locales/doorkeeper.en.yml'
|
9
|
+
route 'use_doorkeeper'
|
10
|
+
readme 'README'
|
11
11
|
end
|
12
12
|
end
|
@@ -3,7 +3,7 @@ require 'rails/generators/active_record'
|
|
3
3
|
class Doorkeeper::MigrationGenerator < ::Rails::Generators::Base
|
4
4
|
include Rails::Generators::Migration
|
5
5
|
source_root File.expand_path('../templates', __FILE__)
|
6
|
-
desc
|
6
|
+
desc 'Installs Doorkeeper migration file.'
|
7
7
|
|
8
8
|
def install
|
9
9
|
migration_template 'migration.rb', 'db/migrate/create_doorkeeper_tables.rb'
|
@@ -2,10 +2,10 @@ module Doorkeeper
|
|
2
2
|
module MongoMapper
|
3
3
|
class IndexesGenerator < ::Rails::Generators::Base
|
4
4
|
source_root File.expand_path('../../templates', __FILE__)
|
5
|
-
desc
|
5
|
+
desc 'Creates an indexes file for use with MongoMapper\'s rake db:index'
|
6
6
|
|
7
7
|
def install
|
8
|
-
template
|
8
|
+
template 'indexes.rb' 'db/indexes.rb'
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class AddOwnerToApplication < ActiveRecord::Migration
|
2
2
|
def change
|
3
|
-
add_column :oauth_applications, :owner_id, :integer, :
|
4
|
-
add_column :oauth_applications, :owner_type, :string, :
|
3
|
+
add_column :oauth_applications, :owner_id, :integer, null: true
|
4
|
+
add_column :oauth_applications, :owner_type, :string, null: true
|
5
5
|
add_index :oauth_applications, [:owner_id, :owner_type]
|
6
6
|
end
|
7
7
|
end
|
@@ -5,7 +5,7 @@ Doorkeeper.configure do
|
|
5
5
|
|
6
6
|
# This block will be called to check whether the resource owner is authenticated or not.
|
7
7
|
resource_owner_authenticator do
|
8
|
-
|
8
|
+
fail "Please configure doorkeeper resource_owner_authenticator block located in #{__FILE__}"
|
9
9
|
# Put your resource owner authentication logic here.
|
10
10
|
# Example implementation:
|
11
11
|
# User.find_by_id(session[:user_id]) || redirect_to(new_user_session_url)
|
@@ -35,7 +35,8 @@ Doorkeeper.configure do
|
|
35
35
|
# enable_application_owner :confirmation => false
|
36
36
|
|
37
37
|
# Define access token scopes for your provider
|
38
|
-
# For more information go to
|
38
|
+
# For more information go to
|
39
|
+
# https://github.com/doorkeeper-gem/doorkeeper/wiki/Using-Scopes
|
39
40
|
# default_scopes :public
|
40
41
|
# optional_scopes :write, :update
|
41
42
|
|
@@ -58,6 +59,18 @@ Doorkeeper.configure do
|
|
58
59
|
#
|
59
60
|
# test_redirect_uri 'urn:ietf:wg:oauth:2.0:oob'
|
60
61
|
|
62
|
+
# Specify what grant flows are enabled in array of Strings. The valid
|
63
|
+
# strings and the flows they enable are:
|
64
|
+
#
|
65
|
+
# "authorization_code" => Authorization Code Grant Flow
|
66
|
+
# "implicit" => Implicit Grant Flow
|
67
|
+
# "password" => Resource Owner Password Credentials Grant Flow
|
68
|
+
# "client_credentials" => Client Credentials Grant Flow
|
69
|
+
#
|
70
|
+
# If not specified, Doorkeeper enables all the four grant flows.
|
71
|
+
#
|
72
|
+
# grant_flows %w(authorization_code implicit password client_credentials)
|
73
|
+
|
61
74
|
# Under some circumstances you might want to have applications auto-approved,
|
62
75
|
# so that the user skips the authorization step.
|
63
76
|
# For example if dealing with trusted a application.
|
@@ -65,7 +78,7 @@ Doorkeeper.configure do
|
|
65
78
|
# client.superapp? or resource_owner.admin?
|
66
79
|
# end
|
67
80
|
|
68
|
-
#
|
81
|
+
# WWW-Authenticate Realm (default "Doorkeeper").
|
69
82
|
# realm "Doorkeeper"
|
70
83
|
|
71
84
|
# Allow dynamic query parameters (disabled by default)
|
@@ -1,42 +1,41 @@
|
|
1
1
|
class CreateDoorkeeperTables < ActiveRecord::Migration
|
2
2
|
def change
|
3
3
|
create_table :oauth_applications do |t|
|
4
|
-
t.string :name, :
|
5
|
-
t.string :uid, :
|
6
|
-
t.string :secret, :
|
7
|
-
t.text :redirect_uri, :
|
4
|
+
t.string :name, null: false
|
5
|
+
t.string :uid, null: false
|
6
|
+
t.string :secret, null: false
|
7
|
+
t.text :redirect_uri, null: false
|
8
8
|
t.timestamps
|
9
9
|
end
|
10
10
|
|
11
|
-
add_index :oauth_applications, :uid, :
|
11
|
+
add_index :oauth_applications, :uid, unique: true
|
12
12
|
|
13
13
|
create_table :oauth_access_grants do |t|
|
14
|
-
t.integer :resource_owner_id, :
|
15
|
-
t.integer :application_id, :
|
16
|
-
t.string :token, :
|
17
|
-
t.integer :expires_in, :
|
18
|
-
t.text :redirect_uri, :
|
19
|
-
t.datetime :created_at, :
|
14
|
+
t.integer :resource_owner_id, null: false
|
15
|
+
t.integer :application_id, null: false
|
16
|
+
t.string :token, null: false
|
17
|
+
t.integer :expires_in, null: false
|
18
|
+
t.text :redirect_uri, null: false
|
19
|
+
t.datetime :created_at, null: false
|
20
20
|
t.datetime :revoked_at
|
21
21
|
t.string :scopes
|
22
22
|
end
|
23
23
|
|
24
|
-
add_index :oauth_access_grants, :token, :
|
24
|
+
add_index :oauth_access_grants, :token, unique: true
|
25
25
|
|
26
26
|
create_table :oauth_access_tokens do |t|
|
27
27
|
t.integer :resource_owner_id
|
28
28
|
t.integer :application_id
|
29
|
-
t.string :token, :
|
29
|
+
t.string :token, null: false
|
30
30
|
t.string :refresh_token
|
31
31
|
t.integer :expires_in
|
32
32
|
t.datetime :revoked_at
|
33
|
-
t.datetime :created_at, :
|
33
|
+
t.datetime :created_at, null: false
|
34
34
|
t.string :scopes
|
35
35
|
end
|
36
36
|
|
37
|
-
add_index :oauth_access_tokens, :token, :
|
37
|
+
add_index :oauth_access_tokens, :token, unique: true
|
38
38
|
add_index :oauth_access_tokens, :resource_owner_id
|
39
|
-
add_index :oauth_access_tokens, :refresh_token, :
|
40
|
-
|
39
|
+
add_index :oauth_access_tokens, :refresh_token, unique: true
|
41
40
|
end
|
42
41
|
end
|
@@ -3,7 +3,7 @@ module Doorkeeper
|
|
3
3
|
class ViewsGenerator < ::Rails::Generators::Base
|
4
4
|
source_root File.expand_path('../../../../app/views/doorkeeper', __FILE__)
|
5
5
|
|
6
|
-
desc
|
6
|
+
desc 'Copies default Doorkeeper views to your application.'
|
7
7
|
|
8
8
|
def manifest
|
9
9
|
directory 'applications', 'app/views/doorkeeper/applications'
|
@@ -2,19 +2,19 @@ require 'spec_helper_integration'
|
|
2
2
|
|
3
3
|
module Doorkeeper
|
4
4
|
describe ApplicationsController do
|
5
|
-
context
|
5
|
+
context 'when admin is not authenticated' do
|
6
6
|
before do
|
7
7
|
allow(Doorkeeper.configuration).to receive(:authenticate_admin).and_return(proc do
|
8
8
|
redirect_to main_app.root_url
|
9
9
|
end)
|
10
10
|
end
|
11
11
|
|
12
|
-
it
|
12
|
+
it 'redirects as set in Doorkeeper.authenticate_admin' do
|
13
13
|
get :index
|
14
14
|
expect(response).to redirect_to(controller.main_app.root_url)
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
17
|
+
it 'does not create application' do
|
18
18
|
expect do
|
19
19
|
post :create, application: {
|
20
20
|
name: 'Example',
|
@@ -23,12 +23,12 @@ module Doorkeeper
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
context
|
26
|
+
context 'when admin is authenticated' do
|
27
27
|
before do
|
28
28
|
allow(Doorkeeper.configuration).to receive(:authenticate_admin).and_return(->(arg) { true })
|
29
29
|
end
|
30
30
|
|
31
|
-
it
|
31
|
+
it 'creates application' do
|
32
32
|
expect do
|
33
33
|
post :create, application: {
|
34
34
|
name: 'Example',
|
@@ -37,7 +37,7 @@ module Doorkeeper
|
|
37
37
|
expect(response).to be_redirect
|
38
38
|
end
|
39
39
|
|
40
|
-
it
|
40
|
+
it 'does not allow mass assignment of uid or secret' do
|
41
41
|
application = FactoryGirl.create(:application)
|
42
42
|
put :update, id: application.id, application: {
|
43
43
|
uid: '1A2B3C4D',
|
@@ -46,7 +46,7 @@ module Doorkeeper
|
|
46
46
|
expect(application.reload.uid).not_to eq '1A2B3C4D'
|
47
47
|
end
|
48
48
|
|
49
|
-
it
|
49
|
+
it 'updates application' do
|
50
50
|
application = FactoryGirl.create(:application)
|
51
51
|
put :update, id: application.id, application: {
|
52
52
|
name: 'Example',
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper_integration'
|
2
2
|
|
3
|
-
describe Doorkeeper::AuthorizationsController,
|
3
|
+
describe Doorkeeper::AuthorizationsController, 'implicit grant flow' do
|
4
4
|
include AuthorizationRequestHelper
|
5
5
|
|
6
6
|
def fragments(param)
|
@@ -9,88 +9,88 @@ describe Doorkeeper::AuthorizationsController, "implicit grant flow" do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def translated_error_message(key)
|
12
|
-
I18n.translate key, :
|
12
|
+
I18n.translate key, scope: [:doorkeeper, :errors, :messages]
|
13
13
|
end
|
14
14
|
|
15
15
|
let(:client) { FactoryGirl.create :application }
|
16
|
-
let(:user) { User.create!(:
|
16
|
+
let(:user) { User.create!(name: 'Joe', password: 'sekret') }
|
17
17
|
|
18
18
|
before do
|
19
19
|
allow(controller).to receive(:current_resource_owner).and_return(user)
|
20
20
|
end
|
21
21
|
|
22
|
-
describe
|
22
|
+
describe 'POST #create' do
|
23
23
|
before do
|
24
|
-
post :create, :
|
24
|
+
post :create, client_id: client.uid, response_type: 'token', redirect_uri: client.redirect_uri
|
25
25
|
end
|
26
26
|
|
27
|
-
it
|
27
|
+
it 'redirects after authorization' do
|
28
28
|
expect(response).to be_redirect
|
29
29
|
end
|
30
30
|
|
31
|
-
it
|
32
|
-
expect(response.location).to match(%r
|
31
|
+
it 'redirects to client redirect uri' do
|
32
|
+
expect(response.location).to match(%r{^#{client.redirect_uri}})
|
33
33
|
end
|
34
34
|
|
35
|
-
it
|
36
|
-
expect(fragments(
|
35
|
+
it 'includes access token in fragment' do
|
36
|
+
expect(fragments('access_token')).to eq(Doorkeeper::AccessToken.first.token)
|
37
37
|
end
|
38
38
|
|
39
|
-
it
|
40
|
-
expect(fragments(
|
39
|
+
it 'includes token type in fragment' do
|
40
|
+
expect(fragments('token_type')).to eq('bearer')
|
41
41
|
end
|
42
42
|
|
43
|
-
it
|
44
|
-
expect(fragments(
|
43
|
+
it 'includes token expiration in fragment' do
|
44
|
+
expect(fragments('expires_in').to_i).to eq(2.hours.to_i)
|
45
45
|
end
|
46
46
|
|
47
|
-
it
|
47
|
+
it 'issues the token for the current client' do
|
48
48
|
expect(Doorkeeper::AccessToken.first.application_id).to eq(client.id)
|
49
49
|
end
|
50
50
|
|
51
|
-
it
|
51
|
+
it 'issues the token for the current resource owner' do
|
52
52
|
expect(Doorkeeper::AccessToken.first.resource_owner_id).to eq(user.id)
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
-
describe
|
56
|
+
describe 'POST #create with errors' do
|
57
57
|
before do
|
58
58
|
default_scopes_exist :public
|
59
|
-
post :create, :
|
59
|
+
post :create, client_id: client.uid, response_type: 'token', scope: 'invalid', redirect_uri: client.redirect_uri
|
60
60
|
end
|
61
61
|
|
62
|
-
it
|
62
|
+
it 'redirects after authorization' do
|
63
63
|
expect(response).to be_redirect
|
64
64
|
end
|
65
65
|
|
66
|
-
it
|
67
|
-
expect(response.location).to match(%r
|
66
|
+
it 'redirects to client redirect uri' do
|
67
|
+
expect(response.location).to match(%r{^#{client.redirect_uri}})
|
68
68
|
end
|
69
69
|
|
70
|
-
it
|
71
|
-
expect(fragments(
|
70
|
+
it 'does not include access token in fragment' do
|
71
|
+
expect(fragments('access_token')).to be_nil
|
72
72
|
end
|
73
73
|
|
74
|
-
it
|
75
|
-
expect(fragments(
|
74
|
+
it 'includes error in fragment' do
|
75
|
+
expect(fragments('error')).to eq('invalid_scope')
|
76
76
|
end
|
77
77
|
|
78
|
-
it
|
79
|
-
expect(fragments(
|
78
|
+
it 'includes error description in fragment' do
|
79
|
+
expect(fragments('error_description')).to eq(translated_error_message(:invalid_scope))
|
80
80
|
end
|
81
81
|
|
82
|
-
it
|
82
|
+
it 'does not issue any access token' do
|
83
83
|
expect(Doorkeeper::AccessToken.all).to be_empty
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
87
|
-
describe
|
88
|
-
it
|
87
|
+
describe 'POST #create with application already authorized' do
|
88
|
+
it 'returns the existing access token in a fragment'
|
89
89
|
end
|
90
90
|
|
91
|
-
describe
|
91
|
+
describe 'GET #new' do
|
92
92
|
before do
|
93
|
-
get :new, :
|
93
|
+
get :new, client_id: client.uid, response_type: 'token', redirect_uri: client.redirect_uri
|
94
94
|
end
|
95
95
|
|
96
96
|
it 'renders new template' do
|
@@ -98,47 +98,47 @@ describe Doorkeeper::AuthorizationsController, "implicit grant flow" do
|
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
101
|
-
describe
|
101
|
+
describe 'GET #new with skip_authorization true' do
|
102
102
|
before do
|
103
103
|
allow(Doorkeeper.configuration).to receive(:skip_authorization).and_return(proc do
|
104
|
-
|
105
|
-
|
106
|
-
get :new, :
|
104
|
+
true
|
105
|
+
end)
|
106
|
+
get :new, client_id: client.uid, response_type: 'token', redirect_uri: client.redirect_uri
|
107
107
|
end
|
108
108
|
|
109
|
-
it
|
109
|
+
it 'should redirect immediately' do
|
110
110
|
expect(response).to be_redirect
|
111
|
-
expect(response.location).to match(%r
|
111
|
+
expect(response.location).to match(%r{^#{client.redirect_uri}})
|
112
112
|
end
|
113
113
|
|
114
|
-
it
|
114
|
+
it 'should issue a token' do
|
115
115
|
expect(Doorkeeper::AccessToken.count).to be 1
|
116
116
|
end
|
117
117
|
|
118
|
-
it
|
119
|
-
expect(fragments(
|
118
|
+
it 'includes token type in fragment' do
|
119
|
+
expect(fragments('token_type')).to eq('bearer')
|
120
120
|
end
|
121
121
|
|
122
|
-
it
|
123
|
-
expect(fragments(
|
122
|
+
it 'includes token expiration in fragment' do
|
123
|
+
expect(fragments('expires_in').to_i).to eq(2.hours.to_i)
|
124
124
|
end
|
125
125
|
|
126
|
-
it
|
126
|
+
it 'issues the token for the current client' do
|
127
127
|
expect(Doorkeeper::AccessToken.first.application_id).to eq(client.id)
|
128
128
|
end
|
129
129
|
|
130
|
-
it
|
130
|
+
it 'issues the token for the current resource owner' do
|
131
131
|
expect(Doorkeeper::AccessToken.first.resource_owner_id).to eq(user.id)
|
132
132
|
end
|
133
133
|
end
|
134
134
|
|
135
|
-
describe
|
135
|
+
describe 'GET #new with errors' do
|
136
136
|
before do
|
137
137
|
default_scopes_exist :public
|
138
|
-
get :new, :
|
138
|
+
get :new, an_invalid: 'request'
|
139
139
|
end
|
140
140
|
|
141
|
-
it
|
141
|
+
it 'does not redirect' do
|
142
142
|
expect(response).to_not be_redirect
|
143
143
|
end
|
144
144
|
|