couchkeeper 0.6.7
Sign up to get free protection for your applications and to get access to all the features.
- 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,7 @@
|
|
1
|
+
class AddOwnerToApplication < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
add_column :oauth_applications, :owner_id, :integer, :null => true
|
4
|
+
add_column :oauth_applications, :owner_type, :string, :null => true
|
5
|
+
add_index :oauth_applications, [:owner_id, :owner_type]
|
6
|
+
end
|
7
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
Doorkeeper.configure do
|
2
|
+
# Change the ORM that doorkeeper will use.
|
3
|
+
# Currently supported options are :active_record, :mongoid2, :mongoid3, :mongo_mapper
|
4
|
+
orm :active_record
|
5
|
+
|
6
|
+
# This block will be called to check whether the resource owner is authenticated or not.
|
7
|
+
resource_owner_authenticator do
|
8
|
+
raise "Please configure doorkeeper resource_owner_authenticator block located in #{__FILE__}"
|
9
|
+
# Put your resource owner authentication logic here.
|
10
|
+
# Example implementation:
|
11
|
+
# User.find_by_id(session[:user_id]) || redirect_to(new_user_session_url)
|
12
|
+
end
|
13
|
+
|
14
|
+
# If you want to restrict access to the web interface for adding oauth authorized applications, you need to declare the block below.
|
15
|
+
# admin_authenticator do
|
16
|
+
# # Put your admin authentication logic here.
|
17
|
+
# # Example implementation:
|
18
|
+
# Admin.find_by_id(session[:admin_id]) || redirect_to(new_admin_session_url)
|
19
|
+
# end
|
20
|
+
|
21
|
+
# Authorization Code expiration time (default 10 minutes).
|
22
|
+
# authorization_code_expires_in 10.minutes
|
23
|
+
|
24
|
+
# Access token expiration time (default 2 hours).
|
25
|
+
# If you want to disable expiration, set this to nil.
|
26
|
+
# access_token_expires_in 2.hours
|
27
|
+
|
28
|
+
# Issue access tokens with refresh token (disabled by default)
|
29
|
+
# use_refresh_token
|
30
|
+
|
31
|
+
# Provide support for an owner to be assigned to each registered application (disabled by default)
|
32
|
+
# Optional parameter :confirmation => true (default false) if you want to enforce ownership of
|
33
|
+
# a registered application
|
34
|
+
# Note: you must also run the rails g doorkeeper:application_owner generator to provide the necessary support
|
35
|
+
# enable_application_owner :confirmation => false
|
36
|
+
|
37
|
+
# Define access token scopes for your provider
|
38
|
+
# For more information go to https://github.com/applicake/doorkeeper/wiki/Using-Scopes
|
39
|
+
# default_scopes :public
|
40
|
+
# optional_scopes :write, :update
|
41
|
+
|
42
|
+
# Change the way client credentials are retrieved from the request object.
|
43
|
+
# By default it retrieves first from the `HTTP_AUTHORIZATION` header, then
|
44
|
+
# falls back to the `:client_id` and `:client_secret` params from the `params` object.
|
45
|
+
# Check out the wiki for more information on customization
|
46
|
+
# client_credentials :from_basic, :from_params
|
47
|
+
|
48
|
+
# Change the way access token is authenticated from the request object.
|
49
|
+
# By default it retrieves first from the `HTTP_AUTHORIZATION` header, then
|
50
|
+
# falls back to the `:access_token` or `:bearer_token` params from the `params` object.
|
51
|
+
# Check out the wiki for mor information on customization
|
52
|
+
# access_token_methods :from_bearer_authorization, :from_access_token_param, :from_bearer_param
|
53
|
+
|
54
|
+
# Change the test redirect uri for client apps
|
55
|
+
# When clients register with the following redirect uri, they won't be redirected to any server and the authorization code will be displayed within the provider
|
56
|
+
# The value can be any string. Use nil to disable this feature. When disabled, clients must provide a valid URL
|
57
|
+
# (Similar behaviour: https://developers.google.com/accounts/docs/OAuth2InstalledApp#choosingredirecturi)
|
58
|
+
#
|
59
|
+
# test_redirect_uri 'urn:ietf:wg:oauth:2.0:oob'
|
60
|
+
|
61
|
+
# Under some circumstances you might want to have applications auto-approved,
|
62
|
+
# so that the user skips the authorization step.
|
63
|
+
# For example if dealing with trusted a application.
|
64
|
+
# skip_authorization do |resource_owner, client|
|
65
|
+
# client.superapp? or resource_owner.admin?
|
66
|
+
# end
|
67
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
class CreateDoorkeeperTables < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :oauth_applications do |t|
|
4
|
+
t.string :name, :null => false
|
5
|
+
t.string :uid, :null => false
|
6
|
+
t.string :secret, :null => false
|
7
|
+
t.string :redirect_uri, :null => false
|
8
|
+
t.timestamps
|
9
|
+
end
|
10
|
+
|
11
|
+
add_index :oauth_applications, :uid, :unique => true
|
12
|
+
|
13
|
+
create_table :oauth_access_grants do |t|
|
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.string :redirect_uri, :null => false
|
19
|
+
t.datetime :created_at, :null => false
|
20
|
+
t.datetime :revoked_at
|
21
|
+
t.string :scopes
|
22
|
+
end
|
23
|
+
|
24
|
+
add_index :oauth_access_grants, :token, :unique => true
|
25
|
+
|
26
|
+
create_table :oauth_access_tokens do |t|
|
27
|
+
t.integer :resource_owner_id
|
28
|
+
t.integer :application_id, :null => false
|
29
|
+
t.string :token, :null => false
|
30
|
+
t.string :refresh_token
|
31
|
+
t.integer :expires_in
|
32
|
+
t.datetime :revoked_at
|
33
|
+
t.datetime :created_at, :null => false
|
34
|
+
t.string :scopes
|
35
|
+
end
|
36
|
+
|
37
|
+
add_index :oauth_access_tokens, :token, :unique => true
|
38
|
+
add_index :oauth_access_tokens, :resource_owner_id
|
39
|
+
add_index :oauth_access_tokens, :refresh_token, :unique => true
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Doorkeeper
|
2
|
+
module Generators
|
3
|
+
class ViewsGenerator < ::Rails::Generators::Base
|
4
|
+
source_root File.expand_path('../../../../app/views/doorkeeper', __FILE__)
|
5
|
+
|
6
|
+
desc "Copies default Doorkeeper views to your application."
|
7
|
+
|
8
|
+
def manifest
|
9
|
+
directory 'applications', 'app/views/doorkeeper/applications'
|
10
|
+
directory 'authorizations', 'app/views/doorkeeper/authorizations'
|
11
|
+
directory 'authorized_applications', 'app/views/doorkeeper/authorized_applications'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/script/rails
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#!/usr/bin/env ruby
|
3
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
4
|
+
|
5
|
+
ENGINE_PATH = File.expand_path('../..', __FILE__)
|
6
|
+
load File.expand_path('../../spec/dummy/script/rails', __FILE__)
|
data/script/run_all
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
set -e
|
3
|
+
|
4
|
+
rails=3.2.8 orm=active_record bundle install --quiet
|
5
|
+
rails=3.2.8 orm=active_record bundle exec rake
|
6
|
+
|
7
|
+
rails=3.2.8 orm=mongoid2 bundle install --quiet
|
8
|
+
rails=3.2.8 orm=mongoid2 bundle exec rake
|
9
|
+
|
10
|
+
rails=3.2.8 orm=mongoid3 bundle install --quiet
|
11
|
+
rails=3.2.8 orm=mongoid3 bundle exec rake
|
12
|
+
|
13
|
+
rails=3.2.8 orm=mongo_mapper bundle install --quiet
|
14
|
+
rails=3.2.8 orm=mongo_mapper bundle exec rake
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper_integration'
|
2
|
+
|
3
|
+
module Doorkeeper
|
4
|
+
describe ApplicationsController do
|
5
|
+
context "when admin is not authenticated" do
|
6
|
+
before(:each) do
|
7
|
+
Doorkeeper.configuration.stub(:authenticate_admin => proc do
|
8
|
+
redirect_to main_app.root_url
|
9
|
+
end)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "redirects as set in Doorkeeper.authenticate_admin" do
|
13
|
+
get :index
|
14
|
+
expect(response).to redirect_to(controller.main_app.root_url)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,154 @@
|
|
1
|
+
require 'spec_helper_integration'
|
2
|
+
|
3
|
+
describe Doorkeeper::AuthorizationsController, "implicit grant flow" do
|
4
|
+
include AuthorizationRequestHelper
|
5
|
+
|
6
|
+
def fragments(param)
|
7
|
+
fragment = URI.parse(response.location).fragment
|
8
|
+
Rack::Utils.parse_query(fragment)[param]
|
9
|
+
end
|
10
|
+
|
11
|
+
def translated_error_message(key)
|
12
|
+
I18n.translate key, :scope => [:doorkeeper, :errors, :messages]
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:client) { FactoryGirl.create :application }
|
16
|
+
let(:user) { User.create!(:name => "Joe", :password => "sekret") }
|
17
|
+
|
18
|
+
before do
|
19
|
+
controller.stub :current_resource_owner => user
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "POST #create" do
|
23
|
+
before do
|
24
|
+
post :create, :client_id => client.uid, :response_type => "token", :redirect_uri => client.redirect_uri
|
25
|
+
end
|
26
|
+
|
27
|
+
it "redirects after authorization" do
|
28
|
+
expect(response).to be_redirect
|
29
|
+
end
|
30
|
+
|
31
|
+
it "redirects to client redirect uri" do
|
32
|
+
expect(response.location).to match(%r[^#{client.redirect_uri}])
|
33
|
+
end
|
34
|
+
|
35
|
+
it "includes access token in fragment" do
|
36
|
+
expect(fragments("access_token")).to eq(Doorkeeper::AccessToken.first.token)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "includes token type in fragment" do
|
40
|
+
expect(fragments("token_type")).to eq('bearer')
|
41
|
+
end
|
42
|
+
|
43
|
+
it "includes token expiration in fragment" do
|
44
|
+
expect(fragments("expires_in").to_i).to eq(2.hours.to_i)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "issues the token for the current client" do
|
48
|
+
expect(Doorkeeper::AccessToken.first.application_id).to eq(client.id)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "issues the token for the current resource owner" do
|
52
|
+
expect(Doorkeeper::AccessToken.first.resource_owner_id).to eq(user.id)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "POST #create with errors" do
|
57
|
+
before do
|
58
|
+
default_scopes_exist :public
|
59
|
+
post :create, :client_id => client.uid, :response_type => "token", :scope => "invalid", :redirect_uri => client.redirect_uri
|
60
|
+
end
|
61
|
+
|
62
|
+
it "redirects after authorization" do
|
63
|
+
expect(response).to be_redirect
|
64
|
+
end
|
65
|
+
|
66
|
+
it "redirects to client redirect uri" do
|
67
|
+
expect(response.location).to match(%r[^#{client.redirect_uri}])
|
68
|
+
end
|
69
|
+
|
70
|
+
it "does not include access token in fragment" do
|
71
|
+
expect(fragments("access_token")).to be_nil
|
72
|
+
end
|
73
|
+
|
74
|
+
it "includes error in fragment" do
|
75
|
+
expect(fragments("error")).to eq('invalid_scope')
|
76
|
+
end
|
77
|
+
|
78
|
+
it "includes error description in fragment" do
|
79
|
+
expect(fragments("error_description")).to eq(translated_error_message(:invalid_scope))
|
80
|
+
end
|
81
|
+
|
82
|
+
it "does not issue any access token" do
|
83
|
+
expect(Doorkeeper::AccessToken.all).to be_empty
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "POST #create with application already authorized" do
|
88
|
+
it "returns the existing access token in a fragment"
|
89
|
+
end
|
90
|
+
|
91
|
+
describe "GET #new" do
|
92
|
+
before do
|
93
|
+
get :new, :client_id => client.uid, :response_type => "token", :redirect_uri => client.redirect_uri
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'renders new template' do
|
97
|
+
expect(response).to render_template(:new)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "GET #new with skip_authorization true" do
|
102
|
+
before do
|
103
|
+
Doorkeeper.configuration.stub(:skip_authorization => proc do
|
104
|
+
true
|
105
|
+
end)
|
106
|
+
get :new, :client_id => client.uid, :response_type => "token", :redirect_uri => client.redirect_uri
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should redirect immediately" do
|
110
|
+
response.should be_redirect
|
111
|
+
response.location.should =~ %r[^#{client.redirect_uri}]
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should issue a token" do
|
115
|
+
Doorkeeper::AccessToken.count.should be 1
|
116
|
+
end
|
117
|
+
|
118
|
+
it "includes token type in fragment" do
|
119
|
+
fragments("token_type").should == "bearer"
|
120
|
+
end
|
121
|
+
|
122
|
+
it "includes token expiration in fragment" do
|
123
|
+
fragments("expires_in").to_i.should == 2.hours.to_i
|
124
|
+
end
|
125
|
+
|
126
|
+
it "issues the token for the current client" do
|
127
|
+
Doorkeeper::AccessToken.first.application_id.should == client.id
|
128
|
+
end
|
129
|
+
|
130
|
+
it "issues the token for the current resource owner" do
|
131
|
+
Doorkeeper::AccessToken.first.resource_owner_id.should == user.id
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
describe "GET #new with errors" do
|
136
|
+
before do
|
137
|
+
default_scopes_exist :public
|
138
|
+
get :new, :an_invalid => 'request'
|
139
|
+
end
|
140
|
+
|
141
|
+
it "does not redirect" do
|
142
|
+
expect(response).to_not be_redirect
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'renders error template' do
|
146
|
+
expect(response).to render_template(:error)
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'does not issue any token' do
|
150
|
+
expect(Doorkeeper::AccessGrant.count).to eq 0
|
151
|
+
expect(Doorkeeper::AccessToken.count).to eq 0
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
@@ -0,0 +1,304 @@
|
|
1
|
+
require 'spec_helper_integration'
|
2
|
+
|
3
|
+
module ControllerActions
|
4
|
+
def index
|
5
|
+
render :text => "index"
|
6
|
+
end
|
7
|
+
|
8
|
+
def show
|
9
|
+
render :text => "show"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
shared_examples "specified for particular actions" do
|
14
|
+
context "with valid token", :token => :valid do
|
15
|
+
it "allows into index action" do
|
16
|
+
get :index, :access_token => token_string
|
17
|
+
expect(response).to be_success
|
18
|
+
end
|
19
|
+
|
20
|
+
it "allows into show action" do
|
21
|
+
get :show, :id => "3", :access_token => token_string
|
22
|
+
expect(response).to be_success
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "with invalid token", :token => :invalid do
|
27
|
+
include_context "invalid token"
|
28
|
+
|
29
|
+
it "does not allow into index action" do
|
30
|
+
get :index, :access_token => token_string
|
31
|
+
expect(response.status).to eq 401
|
32
|
+
end
|
33
|
+
|
34
|
+
it "allows into show action" do
|
35
|
+
get :show, :id => "5", :access_token => token_string
|
36
|
+
expect(response).to be_success
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
shared_examples "specified with except" do
|
42
|
+
context "with valid token", :token => :valid do
|
43
|
+
it "allows into index action" do
|
44
|
+
get :index, :access_token => token_string
|
45
|
+
expect(response).to be_success
|
46
|
+
end
|
47
|
+
|
48
|
+
it "allows into show action" do
|
49
|
+
get :show, :id => "4", :access_token => token_string
|
50
|
+
expect(response).to be_success
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "with invalid token", :token => :invalid do
|
55
|
+
it "allows into index action" do
|
56
|
+
get :index, :access_token => token_string
|
57
|
+
expect(response).to be_success
|
58
|
+
end
|
59
|
+
|
60
|
+
it "does not allow into show action" do
|
61
|
+
get :show, :id => "14", :access_token => token_string
|
62
|
+
expect(response.status).to eq 401
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "Doorkeeper_for helper" do
|
68
|
+
context "accepts token code specified as" do
|
69
|
+
controller do
|
70
|
+
doorkeeper_for :all
|
71
|
+
|
72
|
+
def index
|
73
|
+
render :text => "index"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
let(:token_string) { "1A2BC3" }
|
78
|
+
|
79
|
+
it "access_token param" do
|
80
|
+
Doorkeeper::AccessToken.should_receive(:authenticate).with(token_string)
|
81
|
+
get :index, :access_token => token_string
|
82
|
+
end
|
83
|
+
|
84
|
+
it "bearer_token param" do
|
85
|
+
Doorkeeper::AccessToken.should_receive(:authenticate).with(token_string)
|
86
|
+
get :index, :bearer_token => token_string
|
87
|
+
end
|
88
|
+
|
89
|
+
it "Authorization header" do
|
90
|
+
Doorkeeper::AccessToken.should_receive(:authenticate).with(token_string)
|
91
|
+
request.env["HTTP_AUTHORIZATION"] = "Bearer #{token_string}"
|
92
|
+
get :index
|
93
|
+
end
|
94
|
+
|
95
|
+
it "different kind of Authorization header" do
|
96
|
+
Doorkeeper::AccessToken.should_not_receive(:authenticate)
|
97
|
+
request.env["HTTP_AUTHORIZATION"] = "Basic #{Base64.encode64("foo:bar")}"
|
98
|
+
get :index
|
99
|
+
end
|
100
|
+
|
101
|
+
it "doesn't change Authorization header value" do
|
102
|
+
Doorkeeper::AccessToken.should_receive(:authenticate).exactly(2).times
|
103
|
+
request.env["HTTP_AUTHORIZATION"] = "Bearer #{token_string}"
|
104
|
+
get :index
|
105
|
+
get :index
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
context "defined for all actions" do
|
110
|
+
controller do
|
111
|
+
doorkeeper_for :all
|
112
|
+
|
113
|
+
include ControllerActions
|
114
|
+
end
|
115
|
+
|
116
|
+
context "with valid token", :token => :valid do
|
117
|
+
it "allows into index action" do
|
118
|
+
get :index, :access_token => token_string
|
119
|
+
expect(response).to be_success
|
120
|
+
end
|
121
|
+
|
122
|
+
it "allows into show action" do
|
123
|
+
get :show, :id => "4", :access_token => token_string
|
124
|
+
expect(response).to be_success
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
context "with invalid token", :token => :invalid do
|
129
|
+
it "does not allow into index action" do
|
130
|
+
get :index, :access_token => token_string
|
131
|
+
expect(response.status).to eq 401
|
132
|
+
end
|
133
|
+
|
134
|
+
it "does not allow into show action" do
|
135
|
+
get :show, :id => "4", :access_token => token_string
|
136
|
+
expect(response.status).to eq 401
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
context "defined only for index action" do
|
142
|
+
controller do
|
143
|
+
doorkeeper_for :index
|
144
|
+
|
145
|
+
include ControllerActions
|
146
|
+
end
|
147
|
+
include_examples "specified for particular actions"
|
148
|
+
end
|
149
|
+
|
150
|
+
context "defined for actions except index" do
|
151
|
+
controller do
|
152
|
+
doorkeeper_for :all, :except => :index
|
153
|
+
|
154
|
+
include ControllerActions
|
155
|
+
end
|
156
|
+
|
157
|
+
include_examples "specified with except"
|
158
|
+
end
|
159
|
+
|
160
|
+
context "defined with scopes" do
|
161
|
+
controller do
|
162
|
+
doorkeeper_for :all, :scopes => [:write]
|
163
|
+
|
164
|
+
include ControllerActions
|
165
|
+
end
|
166
|
+
|
167
|
+
let(:token_string) { "1A2DUWE" }
|
168
|
+
|
169
|
+
it "allows if the token has particular scopes" do
|
170
|
+
token = double(Doorkeeper::AccessToken, :accessible? => true, :scopes => [:write, :public])
|
171
|
+
Doorkeeper::AccessToken.should_receive(:authenticate).with(token_string).and_return(token)
|
172
|
+
get :index, :access_token => token_string
|
173
|
+
expect(response).to be_success
|
174
|
+
end
|
175
|
+
|
176
|
+
it "does not allow if the token does not include given scope" do
|
177
|
+
token = double(Doorkeeper::AccessToken, :accessible? => true, :scopes => [:public])
|
178
|
+
Doorkeeper::AccessToken.should_receive(:authenticate).with(token_string).and_return(token)
|
179
|
+
get :index, :access_token => token_string
|
180
|
+
expect(response.status).to eq 401
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
context "when custom unauthorized render options are configured" do
|
185
|
+
controller do
|
186
|
+
doorkeeper_for :all
|
187
|
+
|
188
|
+
include ControllerActions
|
189
|
+
end
|
190
|
+
|
191
|
+
context "with a JSON custom render", :token => :invalid do
|
192
|
+
before do
|
193
|
+
controller.should_receive(:doorkeeper_unauthorized_render_options).and_return({ :json => ActiveSupport::JSON.encode({ :error => "Unauthorized" }) } )
|
194
|
+
end
|
195
|
+
|
196
|
+
it "it renders a custom JSON response", :token => :invalid do
|
197
|
+
get :index, :access_token => token_string
|
198
|
+
expect(response.status).to eq 401
|
199
|
+
expect(response.content_type).to eq('application/json')
|
200
|
+
parsed_body = JSON.parse(response.body)
|
201
|
+
expect(parsed_body).not_to be_nil
|
202
|
+
expect(parsed_body['error']).to eq('Unauthorized')
|
203
|
+
end
|
204
|
+
|
205
|
+
end
|
206
|
+
|
207
|
+
context "with a text custom render", :token => :invalid do
|
208
|
+
before do
|
209
|
+
controller.should_receive(:doorkeeper_unauthorized_render_options).and_return({ :text => "Unauthorized" } )
|
210
|
+
end
|
211
|
+
|
212
|
+
it "it renders a custom JSON response", :token => :invalid do
|
213
|
+
get :index, :access_token => token_string
|
214
|
+
expect(response.status).to eq 401
|
215
|
+
expect(response.content_type).to eq('text/html')
|
216
|
+
expect(response.body.should).to eq('Unauthorized')
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
context "when defined with conditional if block" do
|
222
|
+
controller do
|
223
|
+
doorkeeper_for :index, :if => lambda { the_false }
|
224
|
+
doorkeeper_for :show, :if => lambda { the_true }
|
225
|
+
|
226
|
+
include ControllerActions
|
227
|
+
|
228
|
+
private
|
229
|
+
def the_true
|
230
|
+
true
|
231
|
+
end
|
232
|
+
|
233
|
+
def the_false
|
234
|
+
false
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
context "with valid token", :token => :valid do
|
239
|
+
it "enables access if passed block evaluates to false" do
|
240
|
+
get :index, :access_token => token_string
|
241
|
+
expect(response).to be_success
|
242
|
+
end
|
243
|
+
|
244
|
+
it "enables access if passed block evaluates to true" do
|
245
|
+
get :show, :id => 1, :access_token => token_string
|
246
|
+
expect(response).to be_success
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
context "with invalid token", :token => :invalid do
|
251
|
+
it "enables access if passed block evaluates to false" do
|
252
|
+
get :index, :access_token => token_string
|
253
|
+
expect(response).to be_success
|
254
|
+
end
|
255
|
+
|
256
|
+
it "does not enable access if passed block evaluates to true" do
|
257
|
+
get :show, :id => 3, :access_token => token_string
|
258
|
+
expect(response.status).to eq 401
|
259
|
+
end
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
context "when defined with conditional unless block" do
|
264
|
+
controller do
|
265
|
+
doorkeeper_for :index, :unless => lambda { the_false }
|
266
|
+
doorkeeper_for :show, :unless => lambda { the_true }
|
267
|
+
|
268
|
+
include ControllerActions
|
269
|
+
|
270
|
+
def the_true
|
271
|
+
true
|
272
|
+
end
|
273
|
+
|
274
|
+
private
|
275
|
+
|
276
|
+
def the_false
|
277
|
+
false
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
context "with valid token", :token => :valid do
|
282
|
+
it "allows access if passed block evaluates to false" do
|
283
|
+
get :index, :access_token => token_string
|
284
|
+
expect(response).to be_success
|
285
|
+
end
|
286
|
+
|
287
|
+
it "allows access if passed block evaluates to true" do
|
288
|
+
get :show, :id => 1, :access_token => token_string
|
289
|
+
expect(response).to be_success
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
293
|
+
context "with invalid token", :token => :invalid do
|
294
|
+
it "does not allow access if passed block evaluates to false" do
|
295
|
+
get :index, :access_token => token_string
|
296
|
+
end
|
297
|
+
|
298
|
+
it "allows access if passed block evaluates to true" do
|
299
|
+
get :show, :id => 3, :access_token => token_string
|
300
|
+
expect(response).to be_success
|
301
|
+
end
|
302
|
+
end
|
303
|
+
end
|
304
|
+
end
|