doorkeeper 0.3.4 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of doorkeeper might be problematic. Click here for more details.
- data/CHANGELOG.md +13 -0
- data/README.md +32 -5
- data/app/controllers/doorkeeper/application_controller.rb +4 -11
- data/app/controllers/doorkeeper/authorizations_controller.rb +11 -2
- data/app/controllers/doorkeeper/tokens_controller.rb +19 -5
- data/app/models/doorkeeper/access_grant.rb +1 -8
- data/app/models/doorkeeper/access_token.rb +2 -10
- data/app/models/doorkeeper/application.rb +4 -0
- data/app/views/doorkeeper/authorizations/error.html.erb +1 -1
- data/app/views/doorkeeper/authorizations/new.html.erb +1 -1
- data/config/locales/en.yml +3 -0
- data/doorkeeper.gemspec +2 -1
- data/lib/doorkeeper.rb +23 -3
- data/lib/doorkeeper/config.rb +73 -12
- data/lib/doorkeeper/doorkeeper_for.rb +1 -1
- data/lib/doorkeeper/engine.rb +28 -0
- data/lib/doorkeeper/models/scopes.rb +13 -0
- data/lib/doorkeeper/oauth/access_token_request.rb +5 -16
- data/lib/doorkeeper/oauth/authorization/code.rb +1 -1
- data/lib/doorkeeper/oauth/authorization/token.rb +1 -1
- data/lib/doorkeeper/oauth/authorization_request.rb +18 -23
- data/lib/doorkeeper/oauth/client.rb +27 -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/response.rb +42 -0
- data/lib/doorkeeper/oauth/client_credentials/validation.rb +33 -0
- data/lib/doorkeeper/oauth/client_credentials_request.rb +46 -0
- data/lib/doorkeeper/oauth/error.rb +9 -0
- data/lib/doorkeeper/oauth/error_response.rb +30 -0
- data/lib/doorkeeper/oauth/helpers/scope_checker.rb +2 -2
- data/lib/doorkeeper/oauth/password_access_token_request.rb +130 -0
- data/lib/doorkeeper/oauth/scopes.rb +60 -0
- data/lib/doorkeeper/version.rb +1 -1
- data/lib/generators/doorkeeper/templates/initializer.rb +10 -5
- data/lib/generators/doorkeeper/templates/migration.rb +1 -1
- data/script/run_all +11 -0
- data/spec/controllers/authorizations_controller_spec.rb +3 -3
- data/spec/controllers/protected_resources_controller_spec.rb +7 -0
- data/spec/controllers/tokens_controller_spec.rb +1 -1
- data/spec/dummy/app/controllers/home_controller.rb +1 -1
- data/spec/dummy/app/models/user.rb +9 -0
- data/spec/dummy/config/application.rb +2 -0
- data/spec/dummy/config/initializers/doorkeeper.rb +12 -5
- data/spec/dummy/config/locales/doorkeeper.en.yml +5 -0
- data/spec/dummy/db/migrate/20120312140401_add_password_to_users.rb +5 -0
- data/spec/dummy/db/migrate/{20111206151426_create_doorkeeper_tables.rb → 20120524202412_create_doorkeeper_tables.rb} +10 -1
- data/spec/dummy/db/schema.rb +15 -6
- data/spec/lib/config_spec.rb +29 -13
- data/spec/lib/models/scopes_spec.rb +32 -0
- data/spec/lib/oauth/access_token_request_spec.rb +15 -29
- data/spec/lib/oauth/authorization_request_spec.rb +22 -72
- 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/response_spec.rb +58 -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 +60 -0
- data/spec/lib/oauth/client_spec.rb +42 -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 +15 -10
- data/spec/lib/oauth/password_access_token_request_spec.rb +152 -0
- data/spec/lib/oauth/scopes_spec.rb +115 -0
- data/spec/models/doorkeeper/access_grant_spec.rb +0 -15
- data/spec/models/doorkeeper/access_token_spec.rb +11 -4
- data/spec/requests/applications/authorized_applications_spec.rb +2 -2
- data/spec/requests/endpoints/authorization_spec.rb +2 -2
- data/spec/requests/endpoints/token_spec.rb +7 -0
- data/spec/requests/flows/authorization_code_errors_spec.rb +1 -1
- data/spec/requests/flows/authorization_code_spec.rb +8 -2
- data/spec/requests/flows/client_credentials_spec.rb +56 -0
- data/spec/requests/flows/password_spec.rb +52 -0
- data/spec/requests/flows/skip_authorization_spec.rb +2 -2
- data/spec/requests/protected_resources/private_api_spec.rb +9 -2
- data/spec/spec_helper_integration.rb +3 -0
- data/spec/support/helpers/authorization_request_helper.rb +7 -5
- data/spec/support/helpers/model_helper.rb +3 -3
- data/spec/support/helpers/request_spec_helper.rb +1 -1
- data/spec/support/helpers/url_helper.rb +12 -0
- metadata +65 -30
- data/lib/doorkeeper/config/scope.rb +0 -11
- data/lib/doorkeeper/config/scopes.rb +0 -61
- data/lib/doorkeeper/config/scopes_builder.rb +0 -18
- data/spec/dummy/config/initializers/inflections.rb +0 -10
- data/spec/dummy/config/initializers/mime_types.rb +0 -5
- data/spec/lib/config/scope_spec.rb +0 -45
- data/spec/lib/config/scopes_builder_spec.rb +0 -27
- data/spec/lib/config/scopes_spec.rb +0 -180
@@ -1,61 +0,0 @@
|
|
1
|
-
module Doorkeeper
|
2
|
-
class Scopes
|
3
|
-
include Enumerable
|
4
|
-
REQUIRED_ELEMENT_METHOD = [:name, :default]
|
5
|
-
|
6
|
-
class IllegalElement < StandardError; end
|
7
|
-
|
8
|
-
delegate :each, :to => :@scopes
|
9
|
-
|
10
|
-
def initialize
|
11
|
-
@scopes = []
|
12
|
-
end
|
13
|
-
|
14
|
-
def [](name)
|
15
|
-
select do |scope|
|
16
|
-
scope.name.to_sym == name.to_sym
|
17
|
-
end.first
|
18
|
-
end
|
19
|
-
|
20
|
-
def exists? (scope)
|
21
|
-
self[scope].present?
|
22
|
-
end
|
23
|
-
|
24
|
-
def all_included?(scopes_string)
|
25
|
-
scopes_string.split(" ").all? { |s| self.exists?(s) }
|
26
|
-
end
|
27
|
-
|
28
|
-
def add (scope)
|
29
|
-
raise IllegalElement unless valid_element?(scope)
|
30
|
-
@scopes << scope
|
31
|
-
end
|
32
|
-
|
33
|
-
def all
|
34
|
-
@scopes
|
35
|
-
end
|
36
|
-
|
37
|
-
def defaults
|
38
|
-
select do |scope|
|
39
|
-
scope.default
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def default_scope_string
|
44
|
-
defaults.map(&:name).join(" ")
|
45
|
-
end
|
46
|
-
|
47
|
-
def with_names(*names)
|
48
|
-
names = names.map(&:to_sym)
|
49
|
-
select do |scope|
|
50
|
-
names.include? scope.name.to_sym
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
private
|
55
|
-
def valid_element?(scope)
|
56
|
-
REQUIRED_ELEMENT_METHOD.all? do |method|
|
57
|
-
scope.respond_to? method
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module Doorkeeper
|
2
|
-
class Config
|
3
|
-
class ScopesBuilder
|
4
|
-
def initialize(&block)
|
5
|
-
@scopes = Doorkeeper::Scopes.new
|
6
|
-
instance_eval &block
|
7
|
-
end
|
8
|
-
|
9
|
-
def build
|
10
|
-
@scopes
|
11
|
-
end
|
12
|
-
|
13
|
-
def scope(name, options)
|
14
|
-
@scopes.add Doorkeeper::Scope.new(name, options)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,10 +0,0 @@
|
|
1
|
-
# Be sure to restart your server when you modify this file.
|
2
|
-
|
3
|
-
# Add new inflection rules using the following format
|
4
|
-
# (all these examples are active by default):
|
5
|
-
# ActiveSupport::Inflector.inflections do |inflect|
|
6
|
-
# inflect.plural /^(ox)$/i, '\1en'
|
7
|
-
# inflect.singular /^(ox)en/i, '\1'
|
8
|
-
# inflect.irregular 'person', 'people'
|
9
|
-
# inflect.uncountable %w( fish sheep )
|
10
|
-
# end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
require 'spec_helper_integration'
|
2
|
-
|
3
|
-
module Doorkeeper
|
4
|
-
describe Scope do
|
5
|
-
context 'initialized only with name' do
|
6
|
-
subject do
|
7
|
-
Scope.new("public")
|
8
|
-
end
|
9
|
-
|
10
|
-
it "has a given name" do
|
11
|
-
subject.name.should == "public"
|
12
|
-
end
|
13
|
-
|
14
|
-
it "has default set to false" do
|
15
|
-
subject.default.should be_false
|
16
|
-
end
|
17
|
-
|
18
|
-
it "has no description" do
|
19
|
-
subject.description.should be_nil
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context 'initialized with options' do
|
24
|
-
let :description do
|
25
|
-
"Paranoic scope"
|
26
|
-
end
|
27
|
-
|
28
|
-
subject do
|
29
|
-
Scope.new("write", :default => true, :description => description)
|
30
|
-
end
|
31
|
-
|
32
|
-
it "has given name" do
|
33
|
-
subject.name.should == "write"
|
34
|
-
end
|
35
|
-
|
36
|
-
it "has given value of default" do
|
37
|
-
subject.default.should be_true
|
38
|
-
end
|
39
|
-
|
40
|
-
it "has given valud of description" do
|
41
|
-
subject.description.should == description
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'spec_helper_integration'
|
2
|
-
|
3
|
-
module Doorkeeper
|
4
|
-
describe Config::ScopesBuilder do
|
5
|
-
context 'provides DSL to create Scopes collection' do
|
6
|
-
subject do
|
7
|
-
Config::ScopesBuilder.new do
|
8
|
-
scope :public, :default => true, :description => "A"
|
9
|
-
scope :write, :description => "B"
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
describe :build do
|
14
|
-
it 'returns Scopes instance' do
|
15
|
-
subject.build.should be_a(Doorkeeper::Scopes)
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'contains defined scopes' do
|
19
|
-
scopes = subject.build
|
20
|
-
scopes.all.should have(2).items
|
21
|
-
scopes[:public].description.should == "A"
|
22
|
-
scopes[:write].description.should == "B"
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,180 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'active_support/core_ext/module/delegation'
|
3
|
-
require 'active_support/core_ext/string'
|
4
|
-
require 'doorkeeper/config/scopes'
|
5
|
-
require 'doorkeeper/config/scope'
|
6
|
-
|
7
|
-
module Doorkeeper
|
8
|
-
describe Scopes do
|
9
|
-
before :each do
|
10
|
-
if defined? scopes_array
|
11
|
-
scopes_array.each do |scope|
|
12
|
-
subject.add scope
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
describe :add do
|
18
|
-
it 'allows you to add scopes' do
|
19
|
-
scope = create_scope "public", false
|
20
|
-
subject.add scope
|
21
|
-
subject.all.should == [scope]
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'raises error if you try to add illegal element' do
|
25
|
-
expect do
|
26
|
-
subject.add double
|
27
|
-
end.to raise_error Doorkeeper::Scopes::IllegalElement
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe :[] do
|
32
|
-
let :public_scope do
|
33
|
-
create_scope "public", false
|
34
|
-
end
|
35
|
-
|
36
|
-
let :write_scope do
|
37
|
-
create_scope "write", false
|
38
|
-
end
|
39
|
-
|
40
|
-
subject do
|
41
|
-
Scopes.new.tap do |scopes|
|
42
|
-
scopes.add public_scope
|
43
|
-
scopes.add write_scope
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'returns the scope with given name' do
|
48
|
-
subject[:public].should == public_scope
|
49
|
-
subject[:write].should == write_scope
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'returns nil if there does not exist scope with given name' do
|
53
|
-
subject[:awesome].should be_nil
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
describe :exists? do
|
58
|
-
subject do
|
59
|
-
Scopes.new.tap do |scopes|
|
60
|
-
scopes.add create_scope "public", false
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'returns true if scope with given name is present' do
|
65
|
-
subject.exists?("public").should be_true
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'returns false if scope with given name does not exist' do
|
69
|
-
subject.exists?("other").should be_false
|
70
|
-
end
|
71
|
-
|
72
|
-
it 'handles symbols' do
|
73
|
-
subject.exists?(:public).should be_true
|
74
|
-
subject.exists?(:other).should be_false
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
describe :all do
|
79
|
-
let :scopes_array do
|
80
|
-
create_scopes_array "scope1", true,
|
81
|
-
"scope2", false,
|
82
|
-
"scope3", true
|
83
|
-
end
|
84
|
-
|
85
|
-
it "returns all added scopes" do
|
86
|
-
subject.all.should == scopes_array
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
describe :defaults do
|
91
|
-
let :default_scopes do
|
92
|
-
create_scopes_array "public", true,
|
93
|
-
"other_public", true
|
94
|
-
end
|
95
|
-
|
96
|
-
let :scopes_array do
|
97
|
-
array = create_scopes_array "awesome", false,
|
98
|
-
"awesome2", false
|
99
|
-
array + default_scopes
|
100
|
-
end
|
101
|
-
|
102
|
-
it "returns scopes with a default flag" do
|
103
|
-
subject.defaults.should == default_scopes
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
describe :with_names do
|
108
|
-
let :scopes_array do
|
109
|
-
create_scopes_array "scope1", true,
|
110
|
-
"scope2", false,
|
111
|
-
"scope3", false
|
112
|
-
|
113
|
-
end
|
114
|
-
|
115
|
-
it "returns array of scopes with given names" do
|
116
|
-
returned_scopes = subject.with_names("scope1", "scope3")
|
117
|
-
returned_scopes.should have(2).items
|
118
|
-
returned_scopes.map(&:name).should include("scope1", "scope3")
|
119
|
-
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
describe :default_scope_string do
|
124
|
-
let :default_scopes do
|
125
|
-
create_scopes_array "public", true,
|
126
|
-
"other_public", true
|
127
|
-
end
|
128
|
-
|
129
|
-
let :scopes_array do
|
130
|
-
array = create_scopes_array "awesome", false,
|
131
|
-
"awesome2", false
|
132
|
-
array + default_scopes
|
133
|
-
end
|
134
|
-
|
135
|
-
it "returns the string that joins names of default scopes" do
|
136
|
-
subject.default_scope_string.should == "public other_public"
|
137
|
-
end
|
138
|
-
|
139
|
-
end
|
140
|
-
|
141
|
-
describe :all_included? do
|
142
|
-
subject do
|
143
|
-
Scopes.new.tap do |s|
|
144
|
-
s.add create_scope("public", true)
|
145
|
-
s.add create_scope("write", false)
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
it "is true if any scopes is included" do
|
150
|
-
subject.all_included?("public").should be_true
|
151
|
-
end
|
152
|
-
|
153
|
-
it "is true if all scopes are included" do
|
154
|
-
subject.all_included?("public write").should be_true
|
155
|
-
end
|
156
|
-
|
157
|
-
it "is true if all scopes are included in any order" do
|
158
|
-
subject.all_included?("write public").should be_true
|
159
|
-
end
|
160
|
-
|
161
|
-
it "is false if no scopes are included" do
|
162
|
-
subject.all_included?("notexistent").should be_false
|
163
|
-
end
|
164
|
-
|
165
|
-
it "is false if no scopes are included even for existing ones" do
|
166
|
-
subject.all_included?("public write notexistent").should be_false
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
def create_scopes_array(*args)
|
171
|
-
args.each_slice(2).map do |slice|
|
172
|
-
create_scope(*slice)
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
def create_scope(name, default)
|
177
|
-
Scope.new(name, :default => default)
|
178
|
-
end
|
179
|
-
end
|
180
|
-
end
|