couchkeeper 0.6.7
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.
- data/.gitignore +14 -0
- data/.rspec +1 -0
- data/.travis.yml +28 -0
- data/CHANGELOG.md +198 -0
- data/Gemfile +32 -0
- data/MIT-LICENSE +20 -0
- data/README.md +290 -0
- data/Rakefile +18 -0
- data/app/assets/javascripts/doorkeeper/application.js +2 -0
- data/app/assets/stylesheets/doorkeeper/application.css +18 -0
- data/app/assets/stylesheets/doorkeeper/form.css +13 -0
- data/app/controllers/doorkeeper/application_controller.rb +7 -0
- data/app/controllers/doorkeeper/applications_controller.rb +60 -0
- data/app/controllers/doorkeeper/authorizations_controller.rb +57 -0
- data/app/controllers/doorkeeper/authorized_applications_controller.rb +12 -0
- data/app/controllers/doorkeeper/token_info_controller.rb +12 -0
- data/app/controllers/doorkeeper/tokens_controller.rb +20 -0
- data/app/helpers/doorkeeper/form_errors_helper.rb +9 -0
- data/app/validators/redirect_uri_validator.rb +23 -0
- data/app/views/doorkeeper/applications/_form.html.erb +34 -0
- data/app/views/doorkeeper/applications/edit.html.erb +13 -0
- data/app/views/doorkeeper/applications/index.html.erb +29 -0
- data/app/views/doorkeeper/applications/new.html.erb +13 -0
- data/app/views/doorkeeper/applications/show.html.erb +26 -0
- data/app/views/doorkeeper/authorizations/error.html.erb +6 -0
- data/app/views/doorkeeper/authorizations/new.html.erb +37 -0
- data/app/views/doorkeeper/authorizations/show.html.erb +4 -0
- data/app/views/doorkeeper/authorized_applications/index.html.erb +25 -0
- data/app/views/layouts/doorkeeper/application.html.erb +33 -0
- data/config/locales/en.yml +68 -0
- data/doorkeeper.gemspec +28 -0
- data/lib/doorkeeper.rb +64 -0
- data/lib/doorkeeper/config.rb +194 -0
- data/lib/doorkeeper/doorkeeper_for.rb +76 -0
- data/lib/doorkeeper/engine.rb +19 -0
- data/lib/doorkeeper/errors.rb +15 -0
- data/lib/doorkeeper/helpers/controller.rb +58 -0
- data/lib/doorkeeper/helpers/filter.rb +38 -0
- data/lib/doorkeeper/models/access_grant.rb +24 -0
- data/lib/doorkeeper/models/access_token.rb +95 -0
- 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 +21 -0
- data/lib/doorkeeper/models/active_record/application.rb +20 -0
- data/lib/doorkeeper/models/application.rb +33 -0
- data/lib/doorkeeper/models/couchbase/access_grant.rb +10 -0
- data/lib/doorkeeper/models/couchbase/access_token.rb +7 -0
- data/lib/doorkeeper/models/couchbase/application.rb +35 -0
- data/lib/doorkeeper/models/doorkeeper_access_grant/by_token/map.js +5 -0
- data/lib/doorkeeper/models/doorkeeper_access_token/by_application_id/map.js +5 -0
- data/lib/doorkeeper/models/doorkeeper_access_token/by_application_id_and_resource_owner_id/map.js +5 -0
- data/lib/doorkeeper/models/doorkeeper_access_token/by_refresh_token/map.js +5 -0
- data/lib/doorkeeper/models/doorkeeper_access_token/by_resource_owner_id/map.js +5 -0
- data/lib/doorkeeper/models/doorkeeper_access_token/by_token/map.js +5 -0
- data/lib/doorkeeper/models/doorkeeper_application/by_uid/map.js +5 -0
- data/lib/doorkeeper/models/doorkeeper_application/by_uid_and_secret/map.js +5 -0
- data/lib/doorkeeper/models/doorkeeper_application/show_all/map.js +6 -0
- data/lib/doorkeeper/models/expirable.rb +21 -0
- data/lib/doorkeeper/models/mongo_mapper/access_grant.rb +28 -0
- data/lib/doorkeeper/models/mongo_mapper/access_token.rb +51 -0
- data/lib/doorkeeper/models/mongo_mapper/application.rb +30 -0
- data/lib/doorkeeper/models/mongo_mapper/revocable.rb +15 -0
- data/lib/doorkeeper/models/mongoid/revocable.rb +15 -0
- data/lib/doorkeeper/models/mongoid/scopes.rb +15 -0
- data/lib/doorkeeper/models/mongoid2/access_grant.rb +22 -0
- data/lib/doorkeeper/models/mongoid2/access_token.rb +41 -0
- data/lib/doorkeeper/models/mongoid2/application.rb +22 -0
- data/lib/doorkeeper/models/mongoid3/access_grant.rb +22 -0
- data/lib/doorkeeper/models/mongoid3/access_token.rb +41 -0
- data/lib/doorkeeper/models/mongoid3/application.rb +22 -0
- data/lib/doorkeeper/models/ownership.rb +16 -0
- data/lib/doorkeeper/models/scopes.rb +17 -0
- data/lib/doorkeeper/oauth/authorization.rb +10 -0
- data/lib/doorkeeper/oauth/authorization/code.rb +32 -0
- data/lib/doorkeeper/oauth/authorization/token.rb +28 -0
- data/lib/doorkeeper/oauth/authorization/uri_builder.rb +29 -0
- data/lib/doorkeeper/oauth/authorization_code_request.rb +82 -0
- data/lib/doorkeeper/oauth/client.rb +29 -0
- data/lib/doorkeeper/oauth/client/credentials.rb +21 -0
- data/lib/doorkeeper/oauth/client/methods.rb +18 -0
- data/lib/doorkeeper/oauth/client_credentials/creator.rb +29 -0
- data/lib/doorkeeper/oauth/client_credentials/issuer.rb +35 -0
- data/lib/doorkeeper/oauth/client_credentials/validation.rb +33 -0
- data/lib/doorkeeper/oauth/client_credentials_request.rb +47 -0
- data/lib/doorkeeper/oauth/code_request.rb +28 -0
- data/lib/doorkeeper/oauth/code_response.rb +37 -0
- data/lib/doorkeeper/oauth/error.rb +9 -0
- data/lib/doorkeeper/oauth/error_response.rb +44 -0
- data/lib/doorkeeper/oauth/helpers/scope_checker.rb +18 -0
- data/lib/doorkeeper/oauth/helpers/unique_token.rb +13 -0
- data/lib/doorkeeper/oauth/helpers/uri_checker.rb +32 -0
- data/lib/doorkeeper/oauth/password_access_token_request.rb +84 -0
- data/lib/doorkeeper/oauth/pre_authorization.rb +62 -0
- data/lib/doorkeeper/oauth/refresh_token_request.rb +58 -0
- data/lib/doorkeeper/oauth/scopes.rb +60 -0
- data/lib/doorkeeper/oauth/token.rb +36 -0
- data/lib/doorkeeper/oauth/token_request.rb +28 -0
- data/lib/doorkeeper/oauth/token_response.rb +29 -0
- data/lib/doorkeeper/rails/routes.rb +90 -0
- data/lib/doorkeeper/rails/routes/mapper.rb +28 -0
- data/lib/doorkeeper/rails/routes/mapping.rb +39 -0
- data/lib/doorkeeper/request.rb +33 -0
- data/lib/doorkeeper/request/authorization_code.rb +23 -0
- data/lib/doorkeeper/request/client_credentials.rb +23 -0
- data/lib/doorkeeper/request/code.rb +24 -0
- data/lib/doorkeeper/request/password.rb +23 -0
- data/lib/doorkeeper/request/refresh_token.rb +23 -0
- data/lib/doorkeeper/request/token.rb +24 -0
- data/lib/doorkeeper/server.rb +54 -0
- data/lib/doorkeeper/validations.rb +30 -0
- data/lib/doorkeeper/version.rb +3 -0
- data/lib/generators/doorkeeper/application_owner_generator.rb +15 -0
- data/lib/generators/doorkeeper/install_generator.rb +12 -0
- data/lib/generators/doorkeeper/migration_generator.rb +15 -0
- data/lib/generators/doorkeeper/mongo_mapper/indexes_generator.rb +12 -0
- data/lib/generators/doorkeeper/templates/README +44 -0
- data/lib/generators/doorkeeper/templates/add_owner_to_application_migration.rb +7 -0
- data/lib/generators/doorkeeper/templates/indexes.rb +3 -0
- data/lib/generators/doorkeeper/templates/initializer.rb +67 -0
- data/lib/generators/doorkeeper/templates/migration.rb +42 -0
- data/lib/generators/doorkeeper/views_generator.rb +15 -0
- data/script/rails +6 -0
- data/script/run_all +14 -0
- data/spec/controllers/applications_controller_spec.rb +18 -0
- data/spec/controllers/authorizations_controller_spec.rb +154 -0
- data/spec/controllers/protected_resources_controller_spec.rb +304 -0
- data/spec/controllers/token_info_controller_spec.rb +54 -0
- data/spec/controllers/tokens_controller_spec.rb +36 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +9 -0
- data/spec/dummy/app/assets/stylesheets/application.css +7 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/controllers/custom_authorizations_controller.rb +7 -0
- data/spec/dummy/app/controllers/full_protected_resources_controller.rb +12 -0
- data/spec/dummy/app/controllers/home_controller.rb +17 -0
- data/spec/dummy/app/controllers/metal_controller.rb +11 -0
- data/spec/dummy/app/controllers/semi_protected_resources_controller.rb +11 -0
- data/spec/dummy/app/helpers/application_helper.rb +5 -0
- data/spec/dummy/app/models/user.rb +27 -0
- data/spec/dummy/app/views/home/index.html.erb +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +16 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +54 -0
- data/spec/dummy/config/boot.rb +6 -0
- data/spec/dummy/config/database.yml +15 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +30 -0
- data/spec/dummy/config/environments/production.rb +60 -0
- data/spec/dummy/config/environments/test.rb +39 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/doorkeeper.rb +56 -0
- data/spec/dummy/config/initializers/secret_token.rb +9 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/doorkeeper.en.yml +5 -0
- data/spec/dummy/config/mongo.yml +11 -0
- data/spec/dummy/config/mongoid2.yml +9 -0
- data/spec/dummy/config/mongoid3.yml +18 -0
- data/spec/dummy/config/routes.rb +38 -0
- data/spec/dummy/db/migrate/20111122132257_create_users.rb +9 -0
- data/spec/dummy/db/migrate/20120312140401_add_password_to_users.rb +5 -0
- data/spec/dummy/db/migrate/20120524202412_create_doorkeeper_tables.rb +44 -0
- data/spec/dummy/db/schema.rb +64 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/factories/access_grant.rb +9 -0
- data/spec/factories/access_token.rb +7 -0
- data/spec/factories/application.rb +6 -0
- data/spec/generators/application_owner_generator_spec.rb +23 -0
- data/spec/generators/install_generator_spec.rb +31 -0
- data/spec/generators/migration_generator_spec.rb +20 -0
- data/spec/generators/templates/routes.rb +3 -0
- data/spec/generators/views_generator_spec.rb +27 -0
- data/spec/lib/config_spec.rb +170 -0
- data/spec/lib/models/expirable_spec.rb +51 -0
- data/spec/lib/models/revocable_spec.rb +31 -0
- data/spec/lib/models/scopes_spec.rb +32 -0
- data/spec/lib/oauth/authorization/uri_builder_spec.rb +37 -0
- data/spec/lib/oauth/authorization_code_request_spec.rb +80 -0
- data/spec/lib/oauth/client/credentials_spec.rb +47 -0
- data/spec/lib/oauth/client/methods_spec.rb +54 -0
- data/spec/lib/oauth/client_credentials/creator_spec.rb +47 -0
- data/spec/lib/oauth/client_credentials/issuer_spec.rb +57 -0
- data/spec/lib/oauth/client_credentials/validation_spec.rb +29 -0
- data/spec/lib/oauth/client_credentials_integration_spec.rb +27 -0
- data/spec/lib/oauth/client_credentials_request_spec.rb +64 -0
- data/spec/lib/oauth/client_spec.rb +39 -0
- data/spec/lib/oauth/code_request_spec.rb +44 -0
- data/spec/lib/oauth/error_response_spec.rb +40 -0
- data/spec/lib/oauth/error_spec.rb +19 -0
- data/spec/lib/oauth/helpers/scope_checker_spec.rb +74 -0
- data/spec/lib/oauth/helpers/unique_token_spec.rb +20 -0
- data/spec/lib/oauth/helpers/uri_checker_spec.rb +64 -0
- data/spec/lib/oauth/password_access_token_request_spec.rb +65 -0
- data/spec/lib/oauth/pre_authorization_spec.rb +80 -0
- data/spec/lib/oauth/refresh_token_request_spec.rb +56 -0
- data/spec/lib/oauth/scopes_spec.rb +115 -0
- data/spec/lib/oauth/token_request_spec.rb +46 -0
- data/spec/lib/oauth/token_response_spec.rb +52 -0
- data/spec/lib/oauth/token_spec.rb +83 -0
- data/spec/lib/server_spec.rb +24 -0
- data/spec/models/doorkeeper/access_grant_spec.rb +36 -0
- data/spec/models/doorkeeper/access_token_spec.rb +153 -0
- data/spec/models/doorkeeper/application_spec.rb +162 -0
- data/spec/requests/applications/applications_request_spec.rb +92 -0
- data/spec/requests/applications/authorized_applications_spec.rb +30 -0
- data/spec/requests/endpoints/authorization_spec.rb +47 -0
- data/spec/requests/endpoints/token_spec.rb +46 -0
- data/spec/requests/flows/authorization_code_errors_spec.rb +66 -0
- data/spec/requests/flows/authorization_code_spec.rb +135 -0
- data/spec/requests/flows/client_credentials_spec.rb +58 -0
- data/spec/requests/flows/implicit_grant_errors_spec.rb +31 -0
- data/spec/requests/flows/implicit_grant_spec.rb +19 -0
- data/spec/requests/flows/password_spec.rb +78 -0
- data/spec/requests/flows/refresh_token_spec.rb +71 -0
- data/spec/requests/flows/skip_authorization_spec.rb +40 -0
- data/spec/requests/protected_resources/metal_spec.rb +14 -0
- data/spec/requests/protected_resources/private_api_spec.rb +50 -0
- data/spec/routing/custom_controller_routes_spec.rb +44 -0
- data/spec/routing/default_routes_spec.rb +32 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/spec_helper_integration.rb +40 -0
- data/spec/support/dependencies/factory_girl.rb +2 -0
- data/spec/support/helpers/access_token_request_helper.rb +11 -0
- data/spec/support/helpers/authorization_request_helper.rb +32 -0
- data/spec/support/helpers/config_helper.rb +9 -0
- data/spec/support/helpers/model_helper.rb +45 -0
- data/spec/support/helpers/request_spec_helper.rb +72 -0
- data/spec/support/helpers/url_helper.rb +51 -0
- data/spec/support/orm/active_record.rb +11 -0
- data/spec/support/orm/mongo_mapper.rb +26 -0
- data/spec/support/orm/mongoid.rb +31 -0
- data/spec/support/shared/controllers_shared_context.rb +60 -0
- data/spec/support/shared/models_shared_examples.rb +60 -0
- data/spec/validators/redirect_uri_validator_spec.rb +47 -0
- data/vendor/assets/stylesheets/doorkeeper/bootstrap.min.css +356 -0
- metadata +430 -0
@@ -0,0 +1,32 @@
|
|
1
|
+
module AuthorizationRequestHelper
|
2
|
+
def resource_owner_is_authenticated(resource_owner = nil)
|
3
|
+
resource_owner ||= User.create!(:name => "Joe", :password => "sekret")
|
4
|
+
Doorkeeper.configuration.instance_variable_set(:@authenticate_resource_owner, proc { resource_owner })
|
5
|
+
end
|
6
|
+
|
7
|
+
def resource_owner_is_not_authenticated
|
8
|
+
Doorkeeper.configuration.instance_variable_set(:@authenticate_resource_owner, proc { redirect_to("/sign_in") })
|
9
|
+
end
|
10
|
+
|
11
|
+
def default_scopes_exist(*scopes)
|
12
|
+
Doorkeeper.configuration.instance_variable_set(:@default_scopes, Doorkeeper::OAuth::Scopes.from_array(scopes))
|
13
|
+
end
|
14
|
+
|
15
|
+
def optional_scopes_exist(*scopes)
|
16
|
+
Doorkeeper.configuration.instance_variable_set(:@optional_scopes, Doorkeeper::OAuth::Scopes.from_array(scopes))
|
17
|
+
end
|
18
|
+
|
19
|
+
def client_should_be_authorized(client)
|
20
|
+
client.should have(1).access_grants
|
21
|
+
end
|
22
|
+
|
23
|
+
def client_should_not_be_authorized(client)
|
24
|
+
client.should have(0).access_grants
|
25
|
+
end
|
26
|
+
|
27
|
+
def i_should_be_on_client_callback(client)
|
28
|
+
client.redirect_uri.should == "#{current_uri.scheme}://#{current_uri.host}#{current_uri.path}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
RSpec.configuration.send :include, AuthorizationRequestHelper, :type => :request
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module ConfigHelper
|
2
|
+
def config_is_set(setting, value = nil, &block)
|
3
|
+
setting_ivar = "@#{setting}"
|
4
|
+
value = block_given? ? block : value
|
5
|
+
Doorkeeper.configuration.instance_variable_set(setting_ivar, value)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
RSpec.configuration.send :include, ConfigHelper, :type => :request
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module ModelHelper
|
2
|
+
def client_exists(client_attributes = {})
|
3
|
+
@client = FactoryGirl.create(:application, client_attributes)
|
4
|
+
end
|
5
|
+
|
6
|
+
def create_resource_owner
|
7
|
+
@resource_owner = User.create!(:name => "Joe", :password => "sekret")
|
8
|
+
end
|
9
|
+
|
10
|
+
def authorization_code_exists(options = {})
|
11
|
+
@authorization = FactoryGirl.create(:access_grant, options)
|
12
|
+
end
|
13
|
+
|
14
|
+
def access_grant_should_exist_for(client, resource_owner)
|
15
|
+
grant = Doorkeeper::AccessGrant.first
|
16
|
+
grant.application.should == client
|
17
|
+
grant.resource_owner_id == resource_owner.id
|
18
|
+
end
|
19
|
+
|
20
|
+
def access_token_should_exist_for(client, resource_owner)
|
21
|
+
grant = Doorkeeper::AccessToken.first
|
22
|
+
grant.application.should == client
|
23
|
+
grant.resource_owner_id == resource_owner.id
|
24
|
+
end
|
25
|
+
|
26
|
+
def access_grant_should_not_exist
|
27
|
+
Doorkeeper::AccessGrant.all.should be_empty
|
28
|
+
end
|
29
|
+
|
30
|
+
def access_token_should_not_exist
|
31
|
+
Doorkeeper::AccessToken.all.should be_empty
|
32
|
+
end
|
33
|
+
|
34
|
+
def access_grant_should_have_scopes(*args)
|
35
|
+
grant = Doorkeeper::AccessGrant.first
|
36
|
+
grant.scopes.should == Doorkeeper::OAuth::Scopes.from_array(args)
|
37
|
+
end
|
38
|
+
|
39
|
+
def access_token_should_have_scopes(*args)
|
40
|
+
grant = Doorkeeper::AccessToken.first
|
41
|
+
grant.scopes.should == Doorkeeper::OAuth::Scopes.from_array(args)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
RSpec.configuration.send :include, ModelHelper, :type => :request
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module RequestSpecHelper
|
2
|
+
def i_should_see(content)
|
3
|
+
page.should have_content(content)
|
4
|
+
end
|
5
|
+
|
6
|
+
def i_should_not_see(content)
|
7
|
+
page.should have_no_content(content)
|
8
|
+
end
|
9
|
+
|
10
|
+
def i_should_be_on(path)
|
11
|
+
current_path.should eq(path)
|
12
|
+
end
|
13
|
+
|
14
|
+
def url_should_have_param(param, value)
|
15
|
+
current_params[param].should == value
|
16
|
+
end
|
17
|
+
|
18
|
+
def url_should_not_have_param(param)
|
19
|
+
current_params.should_not have_key(param)
|
20
|
+
end
|
21
|
+
|
22
|
+
def current_params
|
23
|
+
Rack::Utils.parse_query(current_uri.query)
|
24
|
+
end
|
25
|
+
|
26
|
+
def current_uri
|
27
|
+
URI.parse(page.current_url)
|
28
|
+
end
|
29
|
+
|
30
|
+
def should_have_header(header, value)
|
31
|
+
headers[header].should == value
|
32
|
+
end
|
33
|
+
|
34
|
+
def with_access_token_header(token)
|
35
|
+
with_header 'Authorization', "Bearer #{token}"
|
36
|
+
end
|
37
|
+
|
38
|
+
def with_header(header, value)
|
39
|
+
page.driver.header header, value
|
40
|
+
end
|
41
|
+
|
42
|
+
def basic_auth_header_for_client(client)
|
43
|
+
ActionController::HttpAuthentication::Basic.encode_credentials client.uid, client.secret
|
44
|
+
end
|
45
|
+
|
46
|
+
def should_have_json(key, value)
|
47
|
+
JSON.parse(response.body).fetch(key).should == value
|
48
|
+
end
|
49
|
+
|
50
|
+
def should_not_have_json(key)
|
51
|
+
JSON.parse(response.body).should_not have_key(key)
|
52
|
+
end
|
53
|
+
|
54
|
+
def sign_in
|
55
|
+
visit '/'
|
56
|
+
click_on "Sign in"
|
57
|
+
end
|
58
|
+
|
59
|
+
def i_should_see_translated_error_message(key)
|
60
|
+
i_should_see translated_error_message(key)
|
61
|
+
end
|
62
|
+
|
63
|
+
def translated_error_message(key)
|
64
|
+
I18n.translate key, :scope => [:doorkeeper, :errors, :messages]
|
65
|
+
end
|
66
|
+
|
67
|
+
def response_status_should_be(status)
|
68
|
+
page.driver.response.status.to_i.should == status
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
RSpec.configuration.send :include, RequestSpecHelper, :type => :request
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module UrlHelper
|
2
|
+
def token_endpoint_url(options = {})
|
3
|
+
parameters = {
|
4
|
+
:code => options[:code],
|
5
|
+
:client_id => options[:client_id] || (options[:client] ? options[:client].uid : nil),
|
6
|
+
:client_secret => options[:client_secret] || (options[:client] ? options[:client].secret : nil),
|
7
|
+
:redirect_uri => options[:redirect_uri] || (options[:client] ? options[:client].redirect_uri : nil),
|
8
|
+
:grant_type => options[:grant_type] || "authorization_code",
|
9
|
+
}
|
10
|
+
"/oauth/token?#{build_query(parameters)}"
|
11
|
+
end
|
12
|
+
|
13
|
+
def password_token_endpoint_url(options = {})
|
14
|
+
parameters = {
|
15
|
+
:code => options[:code],
|
16
|
+
:client_id => options[:client_id] || (options[:client] ? options[:client].uid : nil),
|
17
|
+
:client_secret => options[:client_secret] || (options[:client] ? options[:client].secret : nil),
|
18
|
+
:username => options[:resource_owner_username] || (options[:resource_owner] ? options[:resource_owner].name : nil),
|
19
|
+
:password => options[:resource_owner_password] || (options[:resource_owner] ? options[:resource_owner].password : nil),
|
20
|
+
:grant_type => "password",
|
21
|
+
}
|
22
|
+
"/oauth/token?#{build_query(parameters)}"
|
23
|
+
end
|
24
|
+
|
25
|
+
def authorization_endpoint_url(options = {})
|
26
|
+
parameters = {
|
27
|
+
:client_id => options[:client_id] || options[:client].uid,
|
28
|
+
:redirect_uri => options[:redirect_uri] || options[:client].redirect_uri,
|
29
|
+
:response_type => options[:response_type] || "code",
|
30
|
+
:scope => options[:scope],
|
31
|
+
:state => options[:state],
|
32
|
+
}.reject { |k, v| v.blank? }
|
33
|
+
"/oauth/authorize?#{build_query(parameters)}"
|
34
|
+
end
|
35
|
+
|
36
|
+
def refresh_token_endpoint_url(options = {})
|
37
|
+
parameters = {
|
38
|
+
:refresh_token => options[:refresh_token],
|
39
|
+
:client_id => options[:client_id] || options[:client].uid,
|
40
|
+
:client_secret => options[:client_secret] || options[:client].secret,
|
41
|
+
:grant_type => options[:grant_type] || "refresh_token",
|
42
|
+
}
|
43
|
+
"/oauth/token?#{build_query(parameters)}"
|
44
|
+
end
|
45
|
+
|
46
|
+
def build_query(hash)
|
47
|
+
Rack::Utils.build_query(hash)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
RSpec.configuration.send :include, UrlHelper, :type => :request
|
@@ -0,0 +1,26 @@
|
|
1
|
+
DatabaseCleaner[:mongo_mapper].strategy = :truncation
|
2
|
+
DatabaseCleaner[:mongo_mapper].clean_with :truncation
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
config.before :suite do
|
6
|
+
Doorkeeper::Application.create_indexes
|
7
|
+
Doorkeeper::AccessGrant.create_indexes
|
8
|
+
Doorkeeper::AccessToken.create_indexes
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
module Doorkeeper
|
13
|
+
class PlaceholderApplicationOwner
|
14
|
+
include MongoMapper::Document
|
15
|
+
|
16
|
+
set_collection_name "placeholder_application_owners"
|
17
|
+
many :applications, :class => Doorkeeper::Application
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
module OrmHelper
|
22
|
+
def mock_application_owner
|
23
|
+
PlaceholderApplicationOwner.new
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
DatabaseCleaner[:mongoid].strategy = :truncation
|
2
|
+
DatabaseCleaner[:mongoid].clean_with :truncation
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
config.before do
|
6
|
+
Doorkeeper::Application.create_indexes
|
7
|
+
Doorkeeper::AccessGrant.create_indexes
|
8
|
+
Doorkeeper::AccessToken.create_indexes
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
module Doorkeeper
|
13
|
+
class PlaceholderApplicationOwner
|
14
|
+
include Mongoid::Document
|
15
|
+
|
16
|
+
if ::Mongoid::VERSION >= "3"
|
17
|
+
self.store_in :collection => :placeholder_application_owners
|
18
|
+
else
|
19
|
+
self.store_in :placeholder_application_owners
|
20
|
+
end
|
21
|
+
|
22
|
+
has_many :applications
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
module OrmHelper
|
27
|
+
def mock_application_owner
|
28
|
+
PlaceholderApplicationOwner.new
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
shared_context "valid token", :token => :valid do
|
2
|
+
let :token_string do
|
3
|
+
"1A2B3C4D"
|
4
|
+
end
|
5
|
+
|
6
|
+
let :token do
|
7
|
+
double(Doorkeeper::AccessToken, :accessible? => true)
|
8
|
+
end
|
9
|
+
|
10
|
+
before :each do
|
11
|
+
Doorkeeper::AccessToken.stub(:authenticate).with(token_string).and_return(token)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
shared_context "invalid token", :token => :invalid do
|
16
|
+
let :token_string do
|
17
|
+
"1A2B3C4D"
|
18
|
+
end
|
19
|
+
|
20
|
+
let :token do
|
21
|
+
double(Doorkeeper::AccessToken, :accessible? => false)
|
22
|
+
end
|
23
|
+
|
24
|
+
before :each do
|
25
|
+
Doorkeeper::AccessToken.stub(:authenticate).with(token_string).and_return(token)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
shared_context "authenticated resource owner" do
|
30
|
+
before do
|
31
|
+
user = double(:resource, :id => 1)
|
32
|
+
Doorkeeper.configuration.stub(:authenticate_resource_owner) { proc do user end }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
shared_context "not authenticated resource owner" do
|
37
|
+
before do
|
38
|
+
Doorkeeper.configuration.stub(:authenticate_resource_owner) { proc do redirect_to '/' end }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
shared_context "valid authorization request" do
|
43
|
+
let :authorization do
|
44
|
+
double(:authorization, :valid? => true, :authorize => true, :success_redirect_uri => "http://something.com/cb?code=token")
|
45
|
+
end
|
46
|
+
|
47
|
+
before do
|
48
|
+
controller.stub(:authorization) { authorization }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
shared_context "invalid authorization request" do
|
53
|
+
let :authorization do
|
54
|
+
double(:authorization, :valid? => false, :authorize => false, :redirect_on_error? => false)
|
55
|
+
end
|
56
|
+
|
57
|
+
before do
|
58
|
+
controller.stub(:authorization) { authorization }
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
shared_examples "an accessible token" do
|
2
|
+
describe :accessible? do
|
3
|
+
it "is accessible if token is not expired" do
|
4
|
+
subject.stub :expired? => false
|
5
|
+
should be_accessible
|
6
|
+
end
|
7
|
+
|
8
|
+
it "is not accessible if token is expired" do
|
9
|
+
subject.stub :expired? => true
|
10
|
+
should_not be_accessible
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
shared_examples "a revocable token" do
|
16
|
+
describe :accessible? do
|
17
|
+
before { subject.save! }
|
18
|
+
|
19
|
+
it "is accessible if token is not revoked" do
|
20
|
+
subject.should be_accessible
|
21
|
+
end
|
22
|
+
|
23
|
+
it "is not accessible if token is revoked" do
|
24
|
+
subject.revoke
|
25
|
+
subject.should_not be_accessible
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
shared_examples "an unique token" do
|
31
|
+
describe :token do
|
32
|
+
it "is unique" do
|
33
|
+
tokens = []
|
34
|
+
3.times do
|
35
|
+
token = FactoryGirl.create(factory_name).token
|
36
|
+
tokens.should_not include(token)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
it "is generated before validation" do
|
41
|
+
expect { subject.valid? }.to change { subject.token }.from(nil)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "is not valid if token exists" do
|
45
|
+
token1 = FactoryGirl.create factory_name
|
46
|
+
token2 = FactoryGirl.create factory_name
|
47
|
+
token2.token = token1.token
|
48
|
+
token2.should_not be_valid
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'expects database to throw an error when tokens are the same' do
|
52
|
+
token1 = FactoryGirl.create factory_name
|
53
|
+
token2 = FactoryGirl.create factory_name
|
54
|
+
token2.token = token1.token
|
55
|
+
expect {
|
56
|
+
token2.save!(:validate => false)
|
57
|
+
}.to raise_error
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper_integration'
|
2
|
+
|
3
|
+
describe RedirectUriValidator do
|
4
|
+
subject do
|
5
|
+
FactoryGirl.create(:application)
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'is valid when the uri is a uri' do
|
9
|
+
subject.redirect_uri = "http://example.com/callback"
|
10
|
+
subject.should be_valid
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'accepts test redirect uri' do
|
14
|
+
subject.redirect_uri = 'urn:ietf:wg:oauth:2.0:oob'
|
15
|
+
subject.should be_valid
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'rejects if test uri is disabled' do
|
19
|
+
RedirectUriValidator.stub :test_redirect_uri => nil
|
20
|
+
subject.redirect_uri = "urn:some:test"
|
21
|
+
subject.should_not be_valid
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'is invalid when the uri is not a uri' do
|
25
|
+
subject.redirect_uri = ']'
|
26
|
+
subject.should_not be_valid
|
27
|
+
subject.errors[:redirect_uri].first.should == "must be a valid URI."
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'is invalid when the uri is relative' do
|
31
|
+
subject.redirect_uri = "/abcd"
|
32
|
+
subject.should_not be_valid
|
33
|
+
subject.errors[:redirect_uri].first.should == "must be an absolute URI."
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'is invalid when the uri has a fragment' do
|
37
|
+
subject.redirect_uri = "http://example.com/abcd#xyz"
|
38
|
+
subject.should_not be_valid
|
39
|
+
subject.errors[:redirect_uri].first.should == "cannot contain a fragment."
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'is invalid when the uri has a query parameter' do
|
43
|
+
subject.redirect_uri = "http://example.com/abcd?xyz=123"
|
44
|
+
subject.should_not be_valid
|
45
|
+
subject.errors[:redirect_uri].first.should == "cannot contain a query parameter."
|
46
|
+
end
|
47
|
+
end
|