doorkeeper 0.4.2 → 0.5.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.
- data/.gitignore +2 -0
- data/.travis.yml +5 -1
- data/CHANGELOG.md +29 -0
- data/Gemfile +12 -4
- data/README.md +76 -7
- data/Rakefile +1 -25
- data/app/assets/javascripts/doorkeeper/application.js +0 -7
- data/app/controllers/doorkeeper/application_controller.rb +1 -27
- data/app/controllers/doorkeeper/applications_controller.rb +14 -6
- data/app/controllers/doorkeeper/authorized_applications_controller.rb +1 -1
- data/app/controllers/doorkeeper/token_info_controller.rb +11 -0
- data/app/controllers/doorkeeper/tokens_controller.rb +11 -8
- data/app/validators/redirect_uri_validator.rb +12 -0
- 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/index.html.erb +4 -4
- data/app/views/doorkeeper/applications/new.html.erb +1 -1
- data/app/views/doorkeeper/applications/show.html.erb +3 -3
- data/app/views/doorkeeper/authorizations/new.html.erb +2 -2
- data/app/views/doorkeeper/authorized_applications/index.html.erb +1 -1
- data/config/locales/en.yml +35 -0
- data/doorkeeper.gemspec +3 -3
- data/gemfiles/gemfile.rails-3.1.x +10 -0
- data/gemfiles/gemfile.rails-3.2.x +10 -0
- data/lib/doorkeeper/config.rb +56 -38
- data/lib/doorkeeper/doorkeeper_for.rb +2 -0
- data/lib/doorkeeper/engine.rb +3 -32
- data/lib/doorkeeper/helpers/controller.rb +29 -0
- data/lib/doorkeeper/helpers/filter.rb +4 -18
- data/{app/models/doorkeeper → lib/doorkeeper/models}/access_grant.rb +7 -7
- data/{app/models/doorkeeper → lib/doorkeeper/models}/access_token.rb +27 -24
- 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 +15 -0
- data/lib/doorkeeper/models/active_record/application.rb +18 -0
- data/lib/doorkeeper/models/application.rb +38 -0
- data/lib/doorkeeper/models/expirable.rb +6 -4
- data/lib/doorkeeper/models/mongoid/access_grant.rb +22 -0
- data/lib/doorkeeper/models/mongoid/access_token.rb +35 -0
- data/lib/doorkeeper/models/mongoid/application.rb +22 -0
- data/lib/doorkeeper/models/mongoid/revocable.rb +15 -0
- data/lib/doorkeeper/models/mongoid/scopes.rb +15 -0
- data/lib/doorkeeper/models/ownership.rb +16 -0
- data/lib/doorkeeper/models/revocable.rb +1 -1
- data/lib/doorkeeper/models/scopes.rb +9 -5
- data/lib/doorkeeper/oauth/access_token_request.rb +2 -2
- data/lib/doorkeeper/oauth/authorization/code.rb +5 -3
- data/lib/doorkeeper/oauth/authorization.rb +1 -0
- data/lib/doorkeeper/oauth/client.rb +2 -2
- data/lib/doorkeeper/oauth/client_credentials_request.rb +4 -1
- data/lib/doorkeeper/oauth/helpers/unique_token.rb +2 -5
- data/lib/doorkeeper/oauth/password_access_token_request.rb +2 -5
- data/lib/doorkeeper/oauth/token.rb +36 -0
- data/lib/doorkeeper/rails/routes/mapper.rb +28 -0
- data/lib/doorkeeper/rails/routes/mapping.rb +39 -0
- data/lib/doorkeeper/rails/routes.rb +77 -0
- data/lib/doorkeeper/version.rb +1 -1
- data/lib/doorkeeper.rb +10 -3
- data/lib/generators/doorkeeper/application_owner_generator.rb +15 -0
- data/lib/generators/doorkeeper/install_generator.rb +2 -9
- data/lib/generators/doorkeeper/migration_generator.rb +15 -0
- data/lib/generators/doorkeeper/templates/README +15 -1
- data/lib/generators/doorkeeper/templates/add_owner_to_application_migration.rb +7 -0
- data/lib/generators/doorkeeper/templates/initializer.rb +31 -15
- data/lib/generators/doorkeeper/templates/migration.rb +7 -4
- data/lib/generators/doorkeeper/views_generator.rb +1 -1
- data/script/run_all +3 -0
- data/spec/controllers/applications_controller_spec.rb +1 -1
- data/spec/controllers/authorizations_controller_spec.rb +4 -4
- data/spec/controllers/protected_resources_controller_spec.rb +7 -7
- data/spec/controllers/token_info_controller_spec.rb +54 -0
- data/spec/controllers/tokens_controller_spec.rb +3 -2
- data/spec/dummy/app/controllers/custom_authorizations_controller.rb +7 -0
- data/spec/dummy/app/models/user.rb +16 -5
- data/spec/dummy/config/application.rb +4 -7
- data/spec/dummy/config/boot.rb +3 -7
- data/spec/dummy/config/initializers/doorkeeper.rb +13 -0
- data/spec/dummy/config/mongoid.yml +7 -0
- data/spec/dummy/config/routes.rb +29 -1
- data/spec/dummy/db/migrate/20120312140401_add_password_to_users.rb +1 -1
- data/spec/dummy/db/migrate/20120524202412_create_doorkeeper_tables.rb +6 -4
- data/spec/dummy/db/schema.rb +5 -3
- data/spec/generators/application_owner_generator_spec.rb +23 -0
- data/spec/generators/install_generator_spec.rb +1 -6
- data/spec/generators/migration_generator_spec.rb +20 -0
- data/spec/lib/config_spec.rb +72 -4
- data/spec/lib/models/expirable_spec.rb +8 -11
- data/spec/lib/models/revocable_spec.rb +1 -1
- data/spec/lib/oauth/access_token_request_spec.rb +15 -9
- data/spec/lib/oauth/authorization_request_spec.rb +1 -0
- data/spec/lib/oauth/client_credentials_request_spec.rb +15 -9
- data/spec/lib/oauth/client_spec.rb +5 -8
- data/spec/lib/oauth/helpers/unique_token_spec.rb +2 -20
- data/spec/lib/oauth/password_access_token_request_spec.rb +16 -9
- data/spec/lib/oauth/token_spec.rb +83 -0
- data/spec/models/doorkeeper/access_token_spec.rb +41 -1
- data/spec/models/doorkeeper/application_spec.rb +53 -20
- data/spec/requests/flows/authorization_code_spec.rb +1 -1
- data/spec/requests/flows/client_credentials_spec.rb +2 -0
- data/spec/requests/flows/password_spec.rb +25 -0
- data/spec/requests/flows/refresh_token_spec.rb +5 -2
- data/spec/requests/protected_resources/private_api_spec.rb +10 -3
- data/spec/routing/custom_controller_routes_spec.rb +44 -0
- data/spec/routing/default_routes_spec.rb +32 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/spec_helper_integration.rb +18 -8
- data/spec/support/dependencies/factory_girl.rb +0 -3
- data/spec/support/orm/active_record.rb +11 -0
- data/spec/support/orm/mongoid.rb +26 -0
- data/spec/support/shared/controllers_shared_context.rb +2 -2
- data/spec/support/shared/models_shared_examples.rb +16 -0
- data/spec/validators/redirect_uri_validator_spec.rb +40 -0
- metadata +59 -32
- data/app/helpers/doorkeeper/application_helper.rb +0 -4
- data/app/models/doorkeeper/application.rb +0 -54
- data/config/routes.rb +0 -9
- data/lib/tasks/doorkeeper_tasks.rake +0 -4
- data/spec/support/dependencies/database_cleaner.rb +0 -16
|
@@ -79,29 +79,29 @@ describe "Doorkeeper_for helper" do
|
|
|
79
79
|
end
|
|
80
80
|
|
|
81
81
|
it "access_token param" do
|
|
82
|
-
Doorkeeper::AccessToken.should_receive(:
|
|
82
|
+
Doorkeeper::AccessToken.should_receive(:authenticate).with(token_string)
|
|
83
83
|
get :index, :access_token => token_string
|
|
84
84
|
end
|
|
85
85
|
|
|
86
86
|
it "bearer_token param" do
|
|
87
|
-
Doorkeeper::AccessToken.should_receive(:
|
|
87
|
+
Doorkeeper::AccessToken.should_receive(:authenticate).with(token_string)
|
|
88
88
|
get :index, :bearer_token => token_string
|
|
89
89
|
end
|
|
90
90
|
|
|
91
91
|
it "Authorization header" do
|
|
92
|
-
Doorkeeper::AccessToken.should_receive(:
|
|
92
|
+
Doorkeeper::AccessToken.should_receive(:authenticate).with(token_string)
|
|
93
93
|
request.env["HTTP_AUTHORIZATION"] = "Bearer #{token_string}"
|
|
94
94
|
get :index
|
|
95
95
|
end
|
|
96
96
|
|
|
97
97
|
it "different kind of Authorization header" do
|
|
98
|
-
Doorkeeper::AccessToken.should_not_receive(:
|
|
98
|
+
Doorkeeper::AccessToken.should_not_receive(:authenticate)
|
|
99
99
|
request.env["HTTP_AUTHORIZATION"] = "Basic #{Base64.encode64("foo:bar")}"
|
|
100
100
|
get :index
|
|
101
101
|
end
|
|
102
102
|
|
|
103
103
|
it "doesn't change Authorization header value" do
|
|
104
|
-
Doorkeeper::AccessToken.should_receive(:
|
|
104
|
+
Doorkeeper::AccessToken.should_receive(:authenticate).exactly(2).times
|
|
105
105
|
request.env["HTTP_AUTHORIZATION"] = "Bearer #{token_string}"
|
|
106
106
|
get :index
|
|
107
107
|
get :index
|
|
@@ -172,14 +172,14 @@ describe "Doorkeeper_for helper" do
|
|
|
172
172
|
|
|
173
173
|
it "allows if the token has particular scopes" do
|
|
174
174
|
token = double(Doorkeeper::AccessToken, :accessible? => true, :scopes => [:write, :public])
|
|
175
|
-
Doorkeeper::AccessToken.should_receive(:
|
|
175
|
+
Doorkeeper::AccessToken.should_receive(:authenticate).with(token_string).and_return(token)
|
|
176
176
|
get :index, :access_token => token_string
|
|
177
177
|
response.should be_success
|
|
178
178
|
end
|
|
179
179
|
|
|
180
180
|
it "does not allow if the token does not include given scope" do
|
|
181
181
|
token = double(Doorkeeper::AccessToken, :accessible? => true, :scopes => [:public])
|
|
182
|
-
Doorkeeper::AccessToken.should_receive(:
|
|
182
|
+
Doorkeeper::AccessToken.should_receive(:authenticate).with(token_string).and_return(token)
|
|
183
183
|
get :index, :access_token => token_string
|
|
184
184
|
response.status.should == 401
|
|
185
185
|
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
require 'spec_helper_integration'
|
|
2
|
+
|
|
3
|
+
describe Doorkeeper::TokenInfoController do
|
|
4
|
+
|
|
5
|
+
describe "when requesting tokeninfo with valid token" do
|
|
6
|
+
|
|
7
|
+
let(:doorkeeper_token) { FactoryGirl.create(:access_token) }
|
|
8
|
+
|
|
9
|
+
before(:each) do
|
|
10
|
+
controller.stub(:doorkeeper_token) { doorkeeper_token }
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def do_get
|
|
14
|
+
get :show
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
describe "successful request" do
|
|
18
|
+
|
|
19
|
+
it "responds with tokeninfo" do
|
|
20
|
+
do_get
|
|
21
|
+
response.body.should eq doorkeeper_token.to_json
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "responds with a 200 status" do
|
|
25
|
+
do_get
|
|
26
|
+
response.status.should eq 200
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
describe "invalid token response" do
|
|
31
|
+
before(:each) do
|
|
32
|
+
controller.stub(:doorkeeper_token => nil)
|
|
33
|
+
end
|
|
34
|
+
it "responds with 401 when doorkeeper_token is not valid" do
|
|
35
|
+
do_get
|
|
36
|
+
response.status.should eq 401
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "responds with 401 when doorkeeper_token is invalid, expired or revoked" do
|
|
40
|
+
controller.stub(:doorkeeper_token => doorkeeper_token)
|
|
41
|
+
doorkeeper_token.stub(:accessible? => false)
|
|
42
|
+
do_get
|
|
43
|
+
response.status.should eq 401
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "responds body message for error" do
|
|
47
|
+
do_get
|
|
48
|
+
response.body.should eq Doorkeeper::OAuth::ErrorResponse.new(:name => :invalid_request, :status => :unauthorized).attributes.to_json
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
end
|
|
@@ -12,7 +12,7 @@ describe Doorkeeper::TokensController do
|
|
|
12
12
|
|
|
13
13
|
it "returns the authorization" do
|
|
14
14
|
token.should_receive(:authorization)
|
|
15
|
-
post :create
|
|
15
|
+
post :create
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
18
|
|
|
@@ -27,8 +27,9 @@ describe Doorkeeper::TokensController do
|
|
|
27
27
|
|
|
28
28
|
it "returns the error response" do
|
|
29
29
|
token.stub(:error_response => stub(:to_json => [], :status => :unauthorized))
|
|
30
|
-
post :create
|
|
30
|
+
post :create
|
|
31
31
|
response.status.should == 401
|
|
32
32
|
end
|
|
33
33
|
end
|
|
34
|
+
|
|
34
35
|
end
|
|
@@ -1,11 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
if defined? ActiveRecord
|
|
2
|
+
class User < ActiveRecord::Base
|
|
3
|
+
end
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
if defined? Mongoid
|
|
7
|
+
class User
|
|
8
|
+
include Mongoid::Document
|
|
9
|
+
include Mongoid::Timestamps
|
|
10
|
+
|
|
11
|
+
field :name, :type => String
|
|
12
|
+
field :password, :type => String
|
|
13
|
+
end
|
|
14
|
+
end
|
|
4
15
|
|
|
16
|
+
class User
|
|
5
17
|
attr_accessible :name, :password
|
|
6
18
|
|
|
7
19
|
def self.authenticate!(name, password)
|
|
8
|
-
|
|
9
|
-
owner.authenticate(password) if owner
|
|
20
|
+
User.where(:name => name, :password => password).first
|
|
10
21
|
end
|
|
11
22
|
end
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
require File.expand_path('../boot', __FILE__)
|
|
2
2
|
|
|
3
|
-
# Pick the frameworks you want:
|
|
4
|
-
require "active_record/railtie"
|
|
5
3
|
require "action_controller/railtie"
|
|
6
|
-
# require "action_mailer/railtie"
|
|
7
4
|
require "active_resource/railtie"
|
|
8
5
|
require "sprockets/railtie"
|
|
9
|
-
# require "rails/test_unit/railtie"
|
|
10
6
|
|
|
11
|
-
Bundler.require
|
|
12
|
-
|
|
7
|
+
Bundler.require :default
|
|
8
|
+
|
|
9
|
+
require "#{DOORKEEPER_ORM}/railtie"
|
|
13
10
|
|
|
14
11
|
module Dummy
|
|
15
12
|
class Application < Rails::Application
|
|
@@ -27,7 +24,7 @@ module Dummy
|
|
|
27
24
|
# Activate observers that should always be running.
|
|
28
25
|
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
|
|
29
26
|
|
|
30
|
-
config.active_record.whitelist_attributes = true
|
|
27
|
+
config.active_record.whitelist_attributes = true if defined?(ActiveRecord)
|
|
31
28
|
|
|
32
29
|
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
|
33
30
|
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
data/spec/dummy/config/boot.rb
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
require 'rubygems'
|
|
2
|
-
|
|
2
|
+
require 'bundler/setup'
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
ENV['BUNDLE_GEMFILE'] = gemfile
|
|
6
|
-
require 'bundler'
|
|
7
|
-
Bundler.setup
|
|
8
|
-
end
|
|
4
|
+
DOORKEEPER_ORM = (ENV['DOORKEEPER_ORM'] || :active_record).to_sym unless defined?(DOORKEEPER_ORM)
|
|
9
5
|
|
|
10
|
-
$:.unshift File.expand_path('../../../../lib', __FILE__)
|
|
6
|
+
$:.unshift File.expand_path('../../../../lib', __FILE__)
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
Doorkeeper.configure do
|
|
2
|
+
# Change the ORM that doorkeeper will use
|
|
3
|
+
# Currently supported => :active_record, :mongoid
|
|
4
|
+
orm DOORKEEPER_ORM
|
|
5
|
+
|
|
2
6
|
# This block will be called to check whether the
|
|
3
7
|
# resource owner is authenticated or not
|
|
4
8
|
resource_owner_authenticator do |routes|
|
|
@@ -21,6 +25,9 @@ Doorkeeper.configure do
|
|
|
21
25
|
# Admin.find_by_id(session[:admin_id]) || redirect_to(routes.new_admin_session_url)
|
|
22
26
|
# end
|
|
23
27
|
|
|
28
|
+
# Authorization Code expiration time (default 10 minutes).
|
|
29
|
+
# access_token_expires_in 10.minutes
|
|
30
|
+
|
|
24
31
|
# Access token expiration time (default 2 hours)
|
|
25
32
|
# If you want to disable expiration, set this to nil.
|
|
26
33
|
# access_token_expires_in 2.hours
|
|
@@ -38,4 +45,10 @@ Doorkeeper.configure do
|
|
|
38
45
|
# fallsback to `:client_id` and `:client_secret` from `params` object
|
|
39
46
|
# Check out the wiki for mor information on customization
|
|
40
47
|
# client_credentials :from_basic, :from_params
|
|
48
|
+
|
|
49
|
+
# Change the way access token is authenticated from the request object.
|
|
50
|
+
# By default it retrieves first from `HTTP_AUTHORIZATION` header and
|
|
51
|
+
# fallsback to `:access_token` or `:bearer_token` from `params` object
|
|
52
|
+
# Check out the wiki for mor information on customization
|
|
53
|
+
# access_token_methods :from_bearer_authorization, :from_access_token_param, :from_bearer_param
|
|
41
54
|
end
|
data/spec/dummy/config/routes.rb
CHANGED
|
@@ -1,7 +1,35 @@
|
|
|
1
1
|
Rails.application.routes.draw do
|
|
2
|
-
|
|
2
|
+
use_doorkeeper
|
|
3
|
+
|
|
4
|
+
scope 'space' do
|
|
5
|
+
use_doorkeeper do
|
|
6
|
+
controllers :authorizations => 'custom_authorizations',
|
|
7
|
+
:tokens => 'custom_authorizations',
|
|
8
|
+
:applications => 'custom_authorizations',
|
|
9
|
+
:token_info => 'custom_authorizations'
|
|
10
|
+
|
|
11
|
+
as :authorizations => 'custom_auth',
|
|
12
|
+
:tokens => 'custom_token',
|
|
13
|
+
:token_info => 'custom_token_info'
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
scope 'outer_space' do
|
|
18
|
+
use_doorkeeper do
|
|
19
|
+
controllers :authorizations => 'custom_authorizations',
|
|
20
|
+
:tokens => 'custom_authorizations',
|
|
21
|
+
:token_info => 'custom_authorizations'
|
|
22
|
+
|
|
23
|
+
as :authorizations => 'custom_auth',
|
|
24
|
+
:tokens => 'custom_token',
|
|
25
|
+
:token_info => 'custom_token_info'
|
|
26
|
+
|
|
27
|
+
skip_controllers :tokens, :applications, :token_info
|
|
28
|
+
end
|
|
29
|
+
end
|
|
3
30
|
|
|
4
31
|
get 'metal.json' => 'metal#index'
|
|
32
|
+
|
|
5
33
|
get '/callback', :to => "home#callback"
|
|
6
34
|
get '/sign_in', :to => "home#sign_in"
|
|
7
35
|
resources :semi_protected_resources
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
class CreateDoorkeeperTables < ActiveRecord::Migration
|
|
2
2
|
def change
|
|
3
3
|
create_table :oauth_applications do |t|
|
|
4
|
-
t.string
|
|
5
|
-
t.string
|
|
6
|
-
t.string
|
|
7
|
-
t.string
|
|
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.integer :owner_id, :null => true
|
|
9
|
+
t.string :owner_type, :null => true
|
|
8
10
|
t.timestamps
|
|
9
11
|
end
|
|
10
12
|
|
data/spec/dummy/db/schema.rb
CHANGED
|
@@ -46,6 +46,8 @@ ActiveRecord::Schema.define(:version => 20120524202412) do
|
|
|
46
46
|
t.string "uid", :null => false
|
|
47
47
|
t.string "secret", :null => false
|
|
48
48
|
t.string "redirect_uri", :null => false
|
|
49
|
+
t.string "owner_type", :null => true, :default => "User"
|
|
50
|
+
t.integer "owner_id", :null => true
|
|
49
51
|
t.datetime "created_at", :null => false
|
|
50
52
|
t.datetime "updated_at", :null => false
|
|
51
53
|
end
|
|
@@ -54,9 +56,9 @@ ActiveRecord::Schema.define(:version => 20120524202412) do
|
|
|
54
56
|
|
|
55
57
|
create_table "users", :force => true do |t|
|
|
56
58
|
t.string "name"
|
|
57
|
-
t.datetime "created_at",
|
|
58
|
-
t.datetime "updated_at",
|
|
59
|
-
t.string "
|
|
59
|
+
t.datetime "created_at", :null => false
|
|
60
|
+
t.datetime "updated_at", :null => false
|
|
61
|
+
t.string "password"
|
|
60
62
|
end
|
|
61
63
|
|
|
62
64
|
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require 'spec_helper_integration'
|
|
2
|
+
require 'generators/doorkeeper/application_owner_generator'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
describe 'Doorkeeper::ApplicationOwnerGenerator' do
|
|
6
|
+
include GeneratorSpec::TestCase
|
|
7
|
+
|
|
8
|
+
tests Doorkeeper::ApplicationOwnerGenerator
|
|
9
|
+
destination ::File.expand_path("../tmp/dummy", __FILE__)
|
|
10
|
+
|
|
11
|
+
describe "after running the generator" do
|
|
12
|
+
before :each do
|
|
13
|
+
prepare_destination
|
|
14
|
+
FileUtils.mkdir(::File.expand_path("config", Pathname(destination_root)))
|
|
15
|
+
FileUtils.copy_file(::File.expand_path("../templates/routes.rb", __FILE__), ::File.expand_path("config/routes.rb", Pathname.new(destination_root)))
|
|
16
|
+
run_generator
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "creates a migration" do
|
|
20
|
+
assert_migration "db/migrate/add_owner_to_application.rb"
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
require 'spec_helper_integration'
|
|
2
2
|
require 'generators/doorkeeper/install_generator'
|
|
3
3
|
|
|
4
|
-
|
|
5
4
|
describe 'Doorkeeper::InstallGenerator' do
|
|
6
5
|
include GeneratorSpec::TestCase
|
|
7
6
|
|
|
@@ -16,10 +15,6 @@ describe 'Doorkeeper::InstallGenerator' do
|
|
|
16
15
|
run_generator
|
|
17
16
|
end
|
|
18
17
|
|
|
19
|
-
it "creates a migration" do
|
|
20
|
-
assert_migration "db/migrate/create_doorkeeper_tables.rb"
|
|
21
|
-
end
|
|
22
|
-
|
|
23
18
|
it "creates an initializer file" do
|
|
24
19
|
assert_file 'config/initializers/doorkeeper.rb'
|
|
25
20
|
end
|
|
@@ -29,7 +24,7 @@ describe 'Doorkeeper::InstallGenerator' do
|
|
|
29
24
|
end
|
|
30
25
|
|
|
31
26
|
it "adds sample route" do
|
|
32
|
-
assert_file "config/routes.rb", /
|
|
27
|
+
assert_file "config/routes.rb", /use_doorkeeper/
|
|
33
28
|
end
|
|
34
29
|
end
|
|
35
30
|
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require 'spec_helper_integration'
|
|
2
|
+
require 'generators/doorkeeper/migration_generator'
|
|
3
|
+
|
|
4
|
+
describe 'Doorkeeper::MigrationGenerator' do
|
|
5
|
+
include GeneratorSpec::TestCase
|
|
6
|
+
|
|
7
|
+
tests Doorkeeper::MigrationGenerator
|
|
8
|
+
destination ::File.expand_path("../tmp/dummy", __FILE__)
|
|
9
|
+
|
|
10
|
+
describe "after running the generator" do
|
|
11
|
+
before :each do
|
|
12
|
+
prepare_destination
|
|
13
|
+
run_generator
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "creates a migration" do
|
|
17
|
+
assert_migration "db/migrate/create_doorkeeper_tables.rb"
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
data/spec/lib/config_spec.rb
CHANGED
|
@@ -7,6 +7,7 @@ describe Doorkeeper, "configuration" do
|
|
|
7
7
|
it "sets the block that is accessible via authenticate_resource_owner" do
|
|
8
8
|
block = proc do end
|
|
9
9
|
Doorkeeper.configure do
|
|
10
|
+
orm DOORKEEPER_ORM
|
|
10
11
|
resource_owner_authenticator &block
|
|
11
12
|
end
|
|
12
13
|
subject.authenticate_resource_owner.should == block
|
|
@@ -17,6 +18,7 @@ describe Doorkeeper, "configuration" do
|
|
|
17
18
|
it "sets the block that is accessible via authenticate_admin" do
|
|
18
19
|
block = proc do end
|
|
19
20
|
Doorkeeper.configure do
|
|
21
|
+
orm DOORKEEPER_ORM
|
|
20
22
|
admin_authenticator &block
|
|
21
23
|
end
|
|
22
24
|
subject.authenticate_admin.should == block
|
|
@@ -30,6 +32,7 @@ describe Doorkeeper, "configuration" do
|
|
|
30
32
|
|
|
31
33
|
it "can change the value" do
|
|
32
34
|
Doorkeeper.configure do
|
|
35
|
+
orm DOORKEEPER_ORM
|
|
33
36
|
access_token_expires_in 4.hours
|
|
34
37
|
end
|
|
35
38
|
subject.access_token_expires_in.should == 4.hours
|
|
@@ -37,6 +40,7 @@ describe Doorkeeper, "configuration" do
|
|
|
37
40
|
|
|
38
41
|
it "can be set to nil" do
|
|
39
42
|
Doorkeeper.configure do
|
|
43
|
+
orm DOORKEEPER_ORM
|
|
40
44
|
access_token_expires_in nil
|
|
41
45
|
end
|
|
42
46
|
subject.access_token_expires_in.should be_nil
|
|
@@ -45,17 +49,24 @@ describe Doorkeeper, "configuration" do
|
|
|
45
49
|
|
|
46
50
|
describe "scopes" do
|
|
47
51
|
it "has default scopes" do
|
|
48
|
-
Doorkeeper.configure {
|
|
52
|
+
Doorkeeper.configure {
|
|
53
|
+
orm DOORKEEPER_ORM
|
|
54
|
+
default_scopes :public
|
|
55
|
+
}
|
|
49
56
|
subject.default_scopes.should include(:public)
|
|
50
57
|
end
|
|
51
58
|
|
|
52
59
|
it 'has optional scopes' do
|
|
53
|
-
Doorkeeper.configure {
|
|
60
|
+
Doorkeeper.configure {
|
|
61
|
+
orm DOORKEEPER_ORM
|
|
62
|
+
optional_scopes :write, :update
|
|
63
|
+
}
|
|
54
64
|
subject.optional_scopes.should include(:write, :update)
|
|
55
65
|
end
|
|
56
66
|
|
|
57
67
|
it 'has all scopes' do
|
|
58
68
|
Doorkeeper.configure do
|
|
69
|
+
orm DOORKEEPER_ORM
|
|
59
70
|
default_scopes :normal
|
|
60
71
|
optional_scopes :admin
|
|
61
72
|
end
|
|
@@ -69,7 +80,10 @@ describe Doorkeeper, "configuration" do
|
|
|
69
80
|
end
|
|
70
81
|
|
|
71
82
|
it "can change the value" do
|
|
72
|
-
Doorkeeper.configure {
|
|
83
|
+
Doorkeeper.configure {
|
|
84
|
+
orm DOORKEEPER_ORM
|
|
85
|
+
use_refresh_token
|
|
86
|
+
}
|
|
73
87
|
subject.refresh_token_enabled?.should be_true
|
|
74
88
|
end
|
|
75
89
|
end
|
|
@@ -80,8 +94,62 @@ describe Doorkeeper, "configuration" do
|
|
|
80
94
|
end
|
|
81
95
|
|
|
82
96
|
it "can change the value" do
|
|
83
|
-
Doorkeeper.configure {
|
|
97
|
+
Doorkeeper.configure {
|
|
98
|
+
orm DOORKEEPER_ORM
|
|
99
|
+
client_credentials :from_digest, :from_params
|
|
100
|
+
}
|
|
84
101
|
subject.client_credentials_methods.should == [:from_digest, :from_params]
|
|
85
102
|
end
|
|
86
103
|
end
|
|
104
|
+
|
|
105
|
+
describe 'access_token_credentials' do
|
|
106
|
+
it 'has defaults order' do
|
|
107
|
+
subject.access_token_methods.should == [:from_bearer_authorization, :from_access_token_param, :from_bearer_param]
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
it "can change the value" do
|
|
111
|
+
Doorkeeper.configure {
|
|
112
|
+
orm DOORKEEPER_ORM
|
|
113
|
+
access_token_methods :from_access_token_param, :from_bearer_param
|
|
114
|
+
}
|
|
115
|
+
subject.access_token_methods.should == [:from_access_token_param, :from_bearer_param]
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
describe "enable_application_owner" do
|
|
120
|
+
it "is disabled by default" do
|
|
121
|
+
Doorkeeper.configuration.enable_application_owner?.should_not be_true
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
context "when enabled without confirmation" do
|
|
125
|
+
before do
|
|
126
|
+
Doorkeeper.configure do
|
|
127
|
+
orm DOORKEEPER_ORM
|
|
128
|
+
enable_application_owner
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
it "adds support for application owner" do
|
|
132
|
+
Doorkeeper::Application.new.should respond_to :owner
|
|
133
|
+
end
|
|
134
|
+
it "Doorkeeper.configuration.confirm_application_owner? returns false" do
|
|
135
|
+
Doorkeeper.configuration.confirm_application_owner?.should_not be_true
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
context "when enabled with confirmation set to true" do
|
|
140
|
+
before do
|
|
141
|
+
Doorkeeper.configure do
|
|
142
|
+
orm DOORKEEPER_ORM
|
|
143
|
+
enable_application_owner :confirmation => true
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
it "adds support for application owner" do
|
|
147
|
+
Doorkeeper::Application.new.should respond_to :owner
|
|
148
|
+
end
|
|
149
|
+
it "Doorkeeper.configuration.confirm_application_owner? returns true" do
|
|
150
|
+
Doorkeeper.configuration.confirm_application_owner?.should be_true
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
end
|
|
87
155
|
end
|
|
@@ -31,19 +31,16 @@ describe 'Expirable' do
|
|
|
31
31
|
end
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
-
describe :
|
|
35
|
-
it "
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
subject.time_left.should == 10.seconds
|
|
39
|
-
end
|
|
34
|
+
describe :expires_in_seconds do
|
|
35
|
+
it "should return the amount of time remaining until the token is expired" do
|
|
36
|
+
subject.stub :expires_in => 2.minutes
|
|
37
|
+
subject.expires_in_seconds.should == 60
|
|
40
38
|
end
|
|
41
39
|
|
|
42
|
-
it "
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
subject.time_left.should == 0
|
|
46
|
-
end
|
|
40
|
+
it "should return 0 when expired" do
|
|
41
|
+
subject.stub :expires_in => 30.seconds
|
|
42
|
+
subject.expires_in_seconds.should == 0
|
|
47
43
|
end
|
|
44
|
+
|
|
48
45
|
end
|
|
49
46
|
end
|
|
@@ -12,7 +12,7 @@ describe 'Revocable' do
|
|
|
12
12
|
describe :revoke do
|
|
13
13
|
it "updates :revoked_at attribute with current time" do
|
|
14
14
|
clock = double :now => stub
|
|
15
|
-
subject.should_receive(:
|
|
15
|
+
subject.should_receive(:update_column).with(:revoked_at, clock.now)
|
|
16
16
|
subject.revoke(clock)
|
|
17
17
|
end
|
|
18
18
|
end
|
|
@@ -56,16 +56,19 @@ module Doorkeeper::OAuth
|
|
|
56
56
|
end
|
|
57
57
|
|
|
58
58
|
describe "with a valid authorization code, client and existing expired access token" do
|
|
59
|
-
|
|
59
|
+
before do
|
|
60
|
+
AccessTokenRequest.new(client, params).authorize
|
|
61
|
+
last_token = Doorkeeper::AccessToken.last
|
|
62
|
+
# TODO: make this better, maybe with an expire! method?
|
|
63
|
+
last_token.update_column :created_at, 10.days.ago
|
|
64
|
+
end
|
|
60
65
|
|
|
61
66
|
it "will create a new token" do
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
subject.authorize
|
|
68
|
-
subject.access_token.should_not eq(expired_access_token)
|
|
67
|
+
grant = FactoryGirl.create(:access_grant, :application => client)
|
|
68
|
+
authorization = AccessTokenRequest.new(client, params.merge(:code => grant.token))
|
|
69
|
+
expect {
|
|
70
|
+
authorization.authorize
|
|
71
|
+
}.to change { Doorkeeper::AccessToken.count }.by(1)
|
|
69
72
|
end
|
|
70
73
|
end
|
|
71
74
|
|
|
@@ -165,7 +168,10 @@ module Doorkeeper::OAuth
|
|
|
165
168
|
}
|
|
166
169
|
|
|
167
170
|
before do
|
|
168
|
-
Doorkeeper.configure {
|
|
171
|
+
Doorkeeper.configure {
|
|
172
|
+
orm DOORKEEPER_ORM
|
|
173
|
+
use_refresh_token
|
|
174
|
+
}
|
|
169
175
|
end
|
|
170
176
|
|
|
171
177
|
describe "with a valid authorization code and client" do
|
|
@@ -25,16 +25,22 @@ module Doorkeeper::OAuth
|
|
|
25
25
|
subject.response.should be_a(ClientCredentialsRequest::Response)
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
end
|
|
28
|
+
context 'if issue was not created' do
|
|
29
|
+
before do
|
|
30
|
+
subject.issuer = stub :create => false, :error => :invalid
|
|
31
|
+
end
|
|
33
32
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
its(:authorize) { should be_false }
|
|
34
|
+
|
|
35
|
+
it 'has an error response' do
|
|
36
|
+
subject.authorize
|
|
37
|
+
subject.response.should be_a(Doorkeeper::OAuth::ErrorResponse)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it 'delegates the error to issuer' do
|
|
41
|
+
subject.authorize
|
|
42
|
+
subject.error.should == :invalid
|
|
43
|
+
end
|
|
38
44
|
end
|
|
39
45
|
|
|
40
46
|
context 'with scopes' do
|