doorkeeper 0.3.0 → 0.3.1
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/README.md +8 -0
- data/app/controllers/doorkeeper/authorizations_controller.rb +2 -1
- data/app/controllers/doorkeeper/authorized_applications_controller.rb +2 -2
- data/app/models/doorkeeper/access_grant.rb +33 -0
- data/app/models/doorkeeper/access_token.rb +72 -0
- data/app/models/doorkeeper/application.rb +47 -0
- data/app/views/doorkeeper/authorizations/new.html.erb +14 -14
- data/lib/doorkeeper/doorkeeper_for.rb +13 -13
- data/lib/doorkeeper/oauth/access_token_request.rb +5 -5
- data/lib/doorkeeper/oauth/authorization_request.rb +2 -2
- data/lib/doorkeeper/version.rb +1 -1
- data/lib/generators/doorkeeper/install_generator.rb +1 -0
- data/lib/generators/doorkeeper/templates/initializer.rb +2 -2
- data/lib/generators/doorkeeper/views_generator.rb +15 -0
- metadata +24 -23
- data/app/models/access_grant.rb +0 -31
- data/app/models/access_token.rb +0 -70
- data/app/models/application.rb +0 -45
data/README.md
CHANGED
@@ -79,6 +79,14 @@ end
|
|
79
79
|
|
80
80
|
You don't need to setup any before filter, `doorkeeper_for` will handle that for you.
|
81
81
|
|
82
|
+
You can pass `if` or `unless` blocks that would specify when doorkeeper has to guard the access.
|
83
|
+
|
84
|
+
``` ruby
|
85
|
+
class Api::V1::ProductsController < Api::V1::ApiController
|
86
|
+
doorkeeper_for :all, :if => lambda { request.xhr? }
|
87
|
+
end
|
88
|
+
```
|
89
|
+
|
82
90
|
### Access Token Scopes
|
83
91
|
|
84
92
|
You can also require the access token to have specific scopes in certain actions:
|
@@ -32,6 +32,7 @@ class Doorkeeper::AuthorizationsController < Doorkeeper::ApplicationController
|
|
32
32
|
private
|
33
33
|
|
34
34
|
def authorization
|
35
|
-
|
35
|
+
authorization_params = params.has_key?(:authorization) ? params[:authorization] : params
|
36
|
+
@authorization ||= Doorkeeper::OAuth::AuthorizationRequest.new(current_resource_owner, authorization_params)
|
36
37
|
end
|
37
38
|
end
|
@@ -2,11 +2,11 @@ class Doorkeeper::AuthorizedApplicationsController < Doorkeeper::ApplicationCont
|
|
2
2
|
before_filter :authenticate_resource_owner!
|
3
3
|
|
4
4
|
def index
|
5
|
-
@applications = Application.authorized_for(current_resource_owner)
|
5
|
+
@applications = Doorkeeper::Application.authorized_for(current_resource_owner)
|
6
6
|
end
|
7
7
|
|
8
8
|
def destroy
|
9
|
-
AccessToken.revoke_all_for params[:id], current_resource_owner
|
9
|
+
Doorkeeper::AccessToken.revoke_all_for params[:id], current_resource_owner
|
10
10
|
redirect_to authorized_applications_path, :notice => "Application revoked."
|
11
11
|
end
|
12
12
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Doorkeeper
|
2
|
+
class AccessGrant < ActiveRecord::Base
|
3
|
+
include Doorkeeper::OAuth::Helpers
|
4
|
+
include Doorkeeper::Models::Expirable
|
5
|
+
include Doorkeeper::Models::Revocable
|
6
|
+
|
7
|
+
self.table_name = :oauth_access_grants
|
8
|
+
|
9
|
+
belongs_to :application
|
10
|
+
|
11
|
+
validates :resource_owner_id, :application_id, :token, :expires_in, :redirect_uri, :presence => true
|
12
|
+
|
13
|
+
before_validation :generate_token, :on => :create
|
14
|
+
|
15
|
+
def accessible?
|
16
|
+
!expired? && !revoked?
|
17
|
+
end
|
18
|
+
|
19
|
+
def scopes
|
20
|
+
self[:scopes].split(" ").map(&:to_sym) if self[:scopes]
|
21
|
+
end
|
22
|
+
|
23
|
+
def scopes_string
|
24
|
+
self[:scopes]
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def generate_token
|
30
|
+
self.token = UniqueToken.generate_for :token, self.class
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module Doorkeeper
|
2
|
+
class AccessToken < ActiveRecord::Base
|
3
|
+
include Doorkeeper::OAuth::Helpers
|
4
|
+
include Doorkeeper::Models::Expirable
|
5
|
+
include Doorkeeper::Models::Revocable
|
6
|
+
|
7
|
+
self.table_name = :oauth_access_tokens
|
8
|
+
|
9
|
+
belongs_to :application
|
10
|
+
|
11
|
+
scope :accessible, where(:revoked_at => nil)
|
12
|
+
|
13
|
+
validates :application_id, :resource_owner_id, :token, :presence => true
|
14
|
+
|
15
|
+
attr_accessor :use_refresh_token
|
16
|
+
|
17
|
+
before_validation :generate_token, :on => :create
|
18
|
+
before_validation :generate_refresh_token, :on => :create, :if => :use_refresh_token?
|
19
|
+
|
20
|
+
def self.revoke_all_for(application_id, resource_owner)
|
21
|
+
where(:application_id => application_id,
|
22
|
+
:resource_owner_id => resource_owner.id).delete_all
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.matching_token_for(application, resource_owner_or_id, scopes)
|
26
|
+
token = last_authorized_token_for(application, resource_owner_or_id)
|
27
|
+
token if token && ScopeChecker.matches?(token.scopes, scopes)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.last_authorized_token_for(application, resource_owner_or_id)
|
31
|
+
resource_owner_id = resource_owner_or_id.kind_of?(ActiveRecord::Base) ? resource_owner_or_id.id : resource_owner_or_id
|
32
|
+
accessible.
|
33
|
+
where(:application_id => application.id,
|
34
|
+
:resource_owner_id => resource_owner_id).
|
35
|
+
order("created_at desc").
|
36
|
+
limit(1).
|
37
|
+
first
|
38
|
+
end
|
39
|
+
private_class_method :last_authorized_token_for
|
40
|
+
|
41
|
+
def token_type
|
42
|
+
"bearer"
|
43
|
+
end
|
44
|
+
|
45
|
+
def accessible?
|
46
|
+
!expired? && !revoked?
|
47
|
+
end
|
48
|
+
|
49
|
+
def scopes
|
50
|
+
scope_string = self[:scopes] || ""
|
51
|
+
scope_string.split(" ").map(&:to_sym)
|
52
|
+
end
|
53
|
+
|
54
|
+
def scopes_string
|
55
|
+
self[:scopes]
|
56
|
+
end
|
57
|
+
|
58
|
+
def use_refresh_token?
|
59
|
+
self.use_refresh_token
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def generate_refresh_token
|
65
|
+
self.refresh_token = UniqueToken.generate_for :refresh_token, self.class
|
66
|
+
end
|
67
|
+
|
68
|
+
def generate_token
|
69
|
+
self.token = UniqueToken.generate_for :token, self.class
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Doorkeeper
|
2
|
+
class Application < ActiveRecord::Base
|
3
|
+
include Doorkeeper::OAuth::Helpers
|
4
|
+
|
5
|
+
self.table_name = :oauth_applications
|
6
|
+
|
7
|
+
has_many :access_grants
|
8
|
+
has_many :authorized_tokens, :class_name => "AccessToken", :conditions => { :revoked_at => nil }
|
9
|
+
has_many :authorized_applications, :through => :authorized_tokens, :source => :application
|
10
|
+
|
11
|
+
validates :name, :secret, :redirect_uri, :presence => true
|
12
|
+
validates :uid, :presence => true, :uniqueness => true
|
13
|
+
validate :validate_redirect_uri
|
14
|
+
|
15
|
+
before_validation :generate_uid, :generate_secret, :on => :create
|
16
|
+
|
17
|
+
def self.column_names_with_table
|
18
|
+
self.column_names.map { |c| "oauth_applications.#{c}" }
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.authorized_for(resource_owner)
|
22
|
+
joins(:authorized_applications).
|
23
|
+
where(:oauth_access_tokens => { :resource_owner_id => resource_owner.id }).
|
24
|
+
group(column_names_with_table.join(','))
|
25
|
+
end
|
26
|
+
|
27
|
+
def validate_redirect_uri
|
28
|
+
return unless redirect_uri
|
29
|
+
uri = URI.parse(redirect_uri)
|
30
|
+
errors.add(:redirect_uri, "cannot contain a fragment.") unless uri.fragment.nil?
|
31
|
+
errors.add(:redirect_uri, "must be an absolute URL.") if uri.scheme.nil? || uri.host.nil?
|
32
|
+
errors.add(:redirect_uri, "cannot contain a query parameter.") unless uri.query.nil?
|
33
|
+
rescue URI::InvalidURIError => e
|
34
|
+
errors.add(:redirect_uri, "must be a valid URI.")
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def generate_uid
|
40
|
+
self.uid = UniqueToken.generate_for :uid, self.class
|
41
|
+
end
|
42
|
+
|
43
|
+
def generate_secret
|
44
|
+
self.secret = UniqueToken.generate_for :secret, self.class
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -15,23 +15,23 @@
|
|
15
15
|
<% end %>
|
16
16
|
|
17
17
|
<div class="inline_block">
|
18
|
-
<%=
|
19
|
-
<%=
|
20
|
-
<%=
|
21
|
-
<%=
|
22
|
-
<%=
|
23
|
-
<%=
|
24
|
-
<%=
|
18
|
+
<%= form_for @authorization, :as => :authorization, :url => authorization_path, :method => :post do |f| %>
|
19
|
+
<%= f.hidden_field :client_id %>
|
20
|
+
<%= f.hidden_field :redirect_uri %>
|
21
|
+
<%= f.hidden_field :state %>
|
22
|
+
<%= f.hidden_field :response_type %>
|
23
|
+
<%= f.hidden_field :scope %>
|
24
|
+
<%= f.submit "Authorize", :class => "btn success" %> or
|
25
25
|
<% end %>
|
26
26
|
</div>
|
27
27
|
<div class="inline_block">
|
28
|
-
<%=
|
29
|
-
<%=
|
30
|
-
<%=
|
31
|
-
<%=
|
32
|
-
<%=
|
33
|
-
<%=
|
34
|
-
<%=
|
28
|
+
<%= form_for @authorization, :as => :authorization, :url => authorization_path, :method => :delete do |f| %>
|
29
|
+
<%= f.hidden_field :client_id %>
|
30
|
+
<%= f.hidden_field :redirect_uri %>
|
31
|
+
<%= f.hidden_field :state %>
|
32
|
+
<%= f.hidden_field :response_type %>
|
33
|
+
<%= f.hidden_field :scope %>
|
34
|
+
<%= f.submit "Deny", :class => "btn" %>
|
35
35
|
<% end %>
|
36
36
|
</div>
|
37
37
|
</div>
|
@@ -4,20 +4,20 @@ module Doorkeeper
|
|
4
4
|
def initialize(options)
|
5
5
|
options ||= {}
|
6
6
|
raise InvalidSyntax unless options.is_a? Hash
|
7
|
+
@filter_options = {}
|
7
8
|
|
8
9
|
options.each do |k, v|
|
9
10
|
self.send(k, v)
|
10
11
|
end
|
11
12
|
end
|
12
13
|
|
13
|
-
|
14
14
|
def validate_token(token)
|
15
15
|
return false unless token
|
16
16
|
token.accessible? and validate_token_scopes(token)
|
17
17
|
end
|
18
18
|
|
19
19
|
def filter_options
|
20
|
-
|
20
|
+
@filter_options
|
21
21
|
end
|
22
22
|
|
23
23
|
private
|
@@ -25,6 +25,14 @@ module Doorkeeper
|
|
25
25
|
@scopes = scopes
|
26
26
|
end
|
27
27
|
|
28
|
+
def if(if_block)
|
29
|
+
@filter_options[:if] = if_block
|
30
|
+
end
|
31
|
+
|
32
|
+
def unless(unless_block)
|
33
|
+
@filter_options[:unless] = unless_block
|
34
|
+
end
|
35
|
+
|
28
36
|
def validate_token_scopes(token)
|
29
37
|
return true if @scopes.blank?
|
30
38
|
token.scopes.any? { |scope| @scopes.include? scope}
|
@@ -32,30 +40,22 @@ module Doorkeeper
|
|
32
40
|
end
|
33
41
|
|
34
42
|
class AllDoorkeeperFor < DoorkeeperFor
|
35
|
-
def filter_options
|
36
|
-
@except ? {:except => @except} : {}
|
37
|
-
end
|
38
|
-
|
39
43
|
private
|
40
44
|
def except(actions)
|
41
|
-
@except = actions
|
45
|
+
@filter_options[:except] = actions
|
42
46
|
end
|
43
47
|
end
|
44
48
|
|
45
49
|
class SelectedDoorkeeperFor < DoorkeeperFor
|
46
50
|
def initialize(*args)
|
47
51
|
options = args.pop if args.last.is_a? Hash
|
48
|
-
only(args)
|
49
52
|
super(options)
|
50
|
-
|
51
|
-
|
52
|
-
def filter_options
|
53
|
-
{:only => @only}
|
53
|
+
only(args)
|
54
54
|
end
|
55
55
|
|
56
56
|
private
|
57
57
|
def only(actions)
|
58
|
-
@only = actions
|
58
|
+
@filter_options[:only] = actions
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
@@ -46,7 +46,7 @@ module Doorkeeper::OAuth
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def access_token
|
49
|
-
@access_token ||= AccessToken.matching_token_for client, base_token.resource_owner_id, base_token.scopes_string
|
49
|
+
@access_token ||= Doorkeeper::AccessToken.matching_token_for client, base_token.resource_owner_id, base_token.scopes_string
|
50
50
|
end
|
51
51
|
|
52
52
|
def token_type
|
@@ -80,7 +80,7 @@ module Doorkeeper::OAuth
|
|
80
80
|
end
|
81
81
|
|
82
82
|
def client
|
83
|
-
@client ||= Application.find_by_uid_and_secret(@client_id, @client_secret)
|
83
|
+
@client ||= Doorkeeper::Application.find_by_uid_and_secret(@client_id, @client_secret)
|
84
84
|
end
|
85
85
|
|
86
86
|
def base_token
|
@@ -88,15 +88,15 @@ module Doorkeeper::OAuth
|
|
88
88
|
end
|
89
89
|
|
90
90
|
def token_via_authorization_code
|
91
|
-
AccessGrant.find_by_token(code)
|
91
|
+
Doorkeeper::AccessGrant.find_by_token(code)
|
92
92
|
end
|
93
93
|
|
94
94
|
def token_via_refresh_token
|
95
|
-
AccessToken.find_by_refresh_token(refresh_token)
|
95
|
+
Doorkeeper::AccessToken.find_by_refresh_token(refresh_token)
|
96
96
|
end
|
97
97
|
|
98
98
|
def create_access_token
|
99
|
-
@access_token = AccessToken.create!({
|
99
|
+
@access_token = Doorkeeper::AccessToken.create!({
|
100
100
|
:application_id => client.id,
|
101
101
|
:resource_owner_id => base_token.resource_owner_id,
|
102
102
|
:scopes => base_token.scopes_string,
|
@@ -35,7 +35,7 @@ module Doorkeeper::OAuth
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def access_token_exists?
|
38
|
-
AccessToken.matching_token_for(client, resource_owner, scope).present?
|
38
|
+
Doorkeeper::AccessToken.matching_token_for(client, resource_owner, scope).present?
|
39
39
|
end
|
40
40
|
|
41
41
|
def deny
|
@@ -60,7 +60,7 @@ module Doorkeeper::OAuth
|
|
60
60
|
end
|
61
61
|
|
62
62
|
def client
|
63
|
-
@client ||= Application.find_by_uid(client_id)
|
63
|
+
@client ||= Doorkeeper::Application.find_by_uid(client_id)
|
64
64
|
end
|
65
65
|
|
66
66
|
def scopes
|
data/lib/doorkeeper/version.rb
CHANGED
@@ -3,6 +3,7 @@ require 'rails/generators/active_record'
|
|
3
3
|
class Doorkeeper::InstallGenerator < Rails::Generators::Base
|
4
4
|
include Rails::Generators::Migration
|
5
5
|
source_root File.expand_path('../templates', __FILE__)
|
6
|
+
desc "Installs Doorkeeper."
|
6
7
|
|
7
8
|
def install
|
8
9
|
migration_template 'migration.rb', 'db/migrate/create_doorkeeper_tables.rb'
|
@@ -7,7 +7,7 @@ Doorkeeper.configure do
|
|
7
7
|
# If you want to use named routes from your app you need
|
8
8
|
# to call them on routes object eg.
|
9
9
|
# routes.new_user_session_path
|
10
|
-
# e.g. User.find_by_id(session[:user_id]) || redirect_to
|
10
|
+
# e.g. User.find_by_id(session[:user_id]) || redirect_to(routes.new_user_session_path)
|
11
11
|
end
|
12
12
|
|
13
13
|
# If you want to restrict the access to the web interface for
|
@@ -18,7 +18,7 @@ Doorkeeper.configure do
|
|
18
18
|
# # If you want to use named routes from your app you need
|
19
19
|
# # to call them on routes object eg.
|
20
20
|
# # routes.new_admin_session_path
|
21
|
-
# Admin.find_by_id(session[:admin_id]) || redirect_to
|
21
|
+
# Admin.find_by_id(session[:admin_id]) || redirect_to(routes.new_admin_session_path)
|
22
22
|
# end
|
23
23
|
|
24
24
|
# Access token expiration time (default 2 hours)
|
@@ -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
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: doorkeeper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-02-
|
13
|
+
date: 2012-02-17 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: railties
|
17
|
-
requirement: &
|
17
|
+
requirement: &70236642092660 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '3.1'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70236642092660
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: sqlite3
|
28
|
-
requirement: &
|
28
|
+
requirement: &70236642091820 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: 1.3.5
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70236642091820
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: rspec-rails
|
39
|
-
requirement: &
|
39
|
+
requirement: &70236642091180 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ~>
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: 2.8.1
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *70236642091180
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: capybara
|
50
|
-
requirement: &
|
50
|
+
requirement: &70236642090640 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ~>
|
@@ -55,10 +55,10 @@ dependencies:
|
|
55
55
|
version: 1.1.2
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *70236642090640
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: generator_spec
|
61
|
-
requirement: &
|
61
|
+
requirement: &70236642090080 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - ~>
|
@@ -66,10 +66,10 @@ dependencies:
|
|
66
66
|
version: 0.8.5
|
67
67
|
type: :development
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *70236642090080
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: factory_girl_rails
|
72
|
-
requirement: &
|
72
|
+
requirement: &70236642089500 !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
74
74
|
requirements:
|
75
75
|
- - ~>
|
@@ -77,10 +77,10 @@ dependencies:
|
|
77
77
|
version: 1.4.0
|
78
78
|
type: :development
|
79
79
|
prerelease: false
|
80
|
-
version_requirements: *
|
80
|
+
version_requirements: *70236642089500
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
82
|
name: timecop
|
83
|
-
requirement: &
|
83
|
+
requirement: &70236642088800 !ruby/object:Gem::Requirement
|
84
84
|
none: false
|
85
85
|
requirements:
|
86
86
|
- - ~>
|
@@ -88,10 +88,10 @@ dependencies:
|
|
88
88
|
version: 0.3.5
|
89
89
|
type: :development
|
90
90
|
prerelease: false
|
91
|
-
version_requirements: *
|
91
|
+
version_requirements: *70236642088800
|
92
92
|
- !ruby/object:Gem::Dependency
|
93
93
|
name: database_cleaner
|
94
|
-
requirement: &
|
94
|
+
requirement: &70236642087420 !ruby/object:Gem::Requirement
|
95
95
|
none: false
|
96
96
|
requirements:
|
97
97
|
- - ~>
|
@@ -99,7 +99,7 @@ dependencies:
|
|
99
99
|
version: 0.7.1
|
100
100
|
type: :development
|
101
101
|
prerelease: false
|
102
|
-
version_requirements: *
|
102
|
+
version_requirements: *70236642087420
|
103
103
|
description: Doorkeeper is an OAuth 2 provider for Rails.
|
104
104
|
email:
|
105
105
|
- felipe@applicake.com
|
@@ -123,12 +123,12 @@ files:
|
|
123
123
|
- app/controllers/doorkeeper/tokens_controller.rbc
|
124
124
|
- app/helpers/doorkeeper/application_helper.rb
|
125
125
|
- app/helpers/doorkeeper/application_helper.rbc
|
126
|
-
- app/models/access_grant.rb
|
127
126
|
- app/models/access_grant.rbc
|
128
|
-
- app/models/access_token.rb
|
129
127
|
- app/models/access_token.rbc
|
130
|
-
- app/models/application.rb
|
131
128
|
- app/models/application.rbc
|
129
|
+
- app/models/doorkeeper/access_grant.rb
|
130
|
+
- app/models/doorkeeper/access_token.rb
|
131
|
+
- app/models/doorkeeper/application.rb
|
132
132
|
- app/views/doorkeeper/applications/_form.html.erb
|
133
133
|
- app/views/doorkeeper/applications/edit.html.erb
|
134
134
|
- app/views/doorkeeper/applications/index.html.erb
|
@@ -177,6 +177,7 @@ files:
|
|
177
177
|
- lib/generators/doorkeeper/templates/initializer.rb
|
178
178
|
- lib/generators/doorkeeper/templates/migration.rb
|
179
179
|
- lib/generators/doorkeeper/templates/README
|
180
|
+
- lib/generators/doorkeeper/views_generator.rb
|
180
181
|
- lib/tasks/doorkeeper_tasks.rake
|
181
182
|
- lib/tasks/doorkeeper_tasks.rake.compiled.rbc
|
182
183
|
- MIT-LICENSE
|
@@ -196,7 +197,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
196
197
|
version: '0'
|
197
198
|
segments:
|
198
199
|
- 0
|
199
|
-
hash:
|
200
|
+
hash: 2595534068459567857
|
200
201
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
201
202
|
none: false
|
202
203
|
requirements:
|
@@ -205,7 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
205
206
|
version: '0'
|
206
207
|
segments:
|
207
208
|
- 0
|
208
|
-
hash:
|
209
|
+
hash: 2595534068459567857
|
209
210
|
requirements: []
|
210
211
|
rubyforge_project:
|
211
212
|
rubygems_version: 1.8.12
|
data/app/models/access_grant.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
class AccessGrant < ActiveRecord::Base
|
2
|
-
include Doorkeeper::OAuth::Helpers
|
3
|
-
include Doorkeeper::Models::Expirable
|
4
|
-
include Doorkeeper::Models::Revocable
|
5
|
-
|
6
|
-
self.table_name = :oauth_access_grants
|
7
|
-
|
8
|
-
belongs_to :application
|
9
|
-
|
10
|
-
validates :resource_owner_id, :application_id, :token, :expires_in, :redirect_uri, :presence => true
|
11
|
-
|
12
|
-
before_validation :generate_token, :on => :create
|
13
|
-
|
14
|
-
def accessible?
|
15
|
-
!expired? && !revoked?
|
16
|
-
end
|
17
|
-
|
18
|
-
def scopes
|
19
|
-
self[:scopes].split(" ").map(&:to_sym) if self[:scopes]
|
20
|
-
end
|
21
|
-
|
22
|
-
def scopes_string
|
23
|
-
self[:scopes]
|
24
|
-
end
|
25
|
-
|
26
|
-
private
|
27
|
-
|
28
|
-
def generate_token
|
29
|
-
self.token = UniqueToken.generate_for :token, self.class
|
30
|
-
end
|
31
|
-
end
|
data/app/models/access_token.rb
DELETED
@@ -1,70 +0,0 @@
|
|
1
|
-
class AccessToken < ActiveRecord::Base
|
2
|
-
include Doorkeeper::OAuth::Helpers
|
3
|
-
include Doorkeeper::Models::Expirable
|
4
|
-
include Doorkeeper::Models::Revocable
|
5
|
-
|
6
|
-
self.table_name = :oauth_access_tokens
|
7
|
-
|
8
|
-
belongs_to :application
|
9
|
-
|
10
|
-
scope :accessible, where(:revoked_at => nil)
|
11
|
-
|
12
|
-
validates :application_id, :resource_owner_id, :token, :presence => true
|
13
|
-
|
14
|
-
attr_accessor :use_refresh_token
|
15
|
-
|
16
|
-
before_validation :generate_token, :on => :create
|
17
|
-
before_validation :generate_refresh_token, :on => :create, :if => :use_refresh_token?
|
18
|
-
|
19
|
-
def self.revoke_all_for(application_id, resource_owner)
|
20
|
-
where(:application_id => application_id,
|
21
|
-
:resource_owner_id => resource_owner.id).delete_all
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.matching_token_for(application, resource_owner_or_id, scopes)
|
25
|
-
token = last_authorized_token_for(application, resource_owner_or_id)
|
26
|
-
token if token && ScopeChecker.matches?(token.scopes, scopes)
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.last_authorized_token_for(application, resource_owner_or_id)
|
30
|
-
resource_owner_id = resource_owner_or_id.kind_of?(ActiveRecord::Base) ? resource_owner_or_id.id : resource_owner_or_id
|
31
|
-
accessible.
|
32
|
-
where(:application_id => application.id,
|
33
|
-
:resource_owner_id => resource_owner_id).
|
34
|
-
order("created_at desc").
|
35
|
-
limit(1).
|
36
|
-
first
|
37
|
-
end
|
38
|
-
private_class_method :last_authorized_token_for
|
39
|
-
|
40
|
-
def token_type
|
41
|
-
"bearer"
|
42
|
-
end
|
43
|
-
|
44
|
-
def accessible?
|
45
|
-
!expired? && !revoked?
|
46
|
-
end
|
47
|
-
|
48
|
-
def scopes
|
49
|
-
scope_string = self[:scopes] || ""
|
50
|
-
scope_string.split(" ").map(&:to_sym)
|
51
|
-
end
|
52
|
-
|
53
|
-
def scopes_string
|
54
|
-
self[:scopes]
|
55
|
-
end
|
56
|
-
|
57
|
-
def use_refresh_token?
|
58
|
-
self.use_refresh_token
|
59
|
-
end
|
60
|
-
|
61
|
-
private
|
62
|
-
|
63
|
-
def generate_refresh_token
|
64
|
-
self.refresh_token = UniqueToken.generate_for :refresh_token, self.class
|
65
|
-
end
|
66
|
-
|
67
|
-
def generate_token
|
68
|
-
self.token = UniqueToken.generate_for :token, self.class
|
69
|
-
end
|
70
|
-
end
|
data/app/models/application.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
class Application < ActiveRecord::Base
|
2
|
-
include Doorkeeper::OAuth::Helpers
|
3
|
-
|
4
|
-
self.table_name = :oauth_applications
|
5
|
-
|
6
|
-
has_many :access_grants
|
7
|
-
has_many :authorized_tokens, :class_name => "AccessToken", :conditions => { :revoked_at => nil }
|
8
|
-
has_many :authorized_applications, :through => :authorized_tokens, :source => :application
|
9
|
-
|
10
|
-
validates :name, :secret, :redirect_uri, :presence => true
|
11
|
-
validates :uid, :presence => true, :uniqueness => true
|
12
|
-
validate :validate_redirect_uri
|
13
|
-
|
14
|
-
before_validation :generate_uid, :generate_secret, :on => :create
|
15
|
-
|
16
|
-
def self.column_names_with_table
|
17
|
-
self.column_names.map { |c| "oauth_applications.#{c}" }
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.authorized_for(resource_owner)
|
21
|
-
joins(:authorized_applications).
|
22
|
-
where(:oauth_access_tokens => { :resource_owner_id => resource_owner.id }).
|
23
|
-
group(column_names_with_table.join(','))
|
24
|
-
end
|
25
|
-
|
26
|
-
def validate_redirect_uri
|
27
|
-
return unless redirect_uri
|
28
|
-
uri = URI.parse(redirect_uri)
|
29
|
-
errors.add(:redirect_uri, "cannot contain a fragment.") unless uri.fragment.nil?
|
30
|
-
errors.add(:redirect_uri, "must be an absolute URL.") if uri.scheme.nil? || uri.host.nil?
|
31
|
-
errors.add(:redirect_uri, "cannot contain a query parameter.") unless uri.query.nil?
|
32
|
-
rescue URI::InvalidURIError => e
|
33
|
-
errors.add(:redirect_uri, "must be a valid URI.")
|
34
|
-
end
|
35
|
-
|
36
|
-
private
|
37
|
-
|
38
|
-
def generate_uid
|
39
|
-
self.uid = UniqueToken.generate_for :uid, self.class
|
40
|
-
end
|
41
|
-
|
42
|
-
def generate_secret
|
43
|
-
self.secret = UniqueToken.generate_for :secret, self.class
|
44
|
-
end
|
45
|
-
end
|