-
Notifications
You must be signed in to change notification settings - Fork 7
/
doorkeeper_models.rb
44 lines (33 loc) · 1.33 KB
/
doorkeeper_models.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
require_relative 'doorkeeper'
Rails.application.config.to_prepare do
Doorkeeper::Application.class_exec do
has_many :application_users, foreign_key: :application_id,
dependent: :destroy,
inverse_of: :application
has_many :users, through: :application_users
has_many :application_groups, foreign_key: :application_id,
dependent: :destroy,
inverse_of: :application
has_many :groups, through: :application_groups
has_many :messages, inverse_of: :application
has_many :security_logs, inverse_of: :application
def is_redirect_url?(url)
return false if url.nil?
# Let doorkeeper do the work of checking the URL against the app's redirect_uris
Doorkeeper::OAuth::Helpers::URIChecker.valid_for_authorization?(url, redirect_uri)
end
end
Doorkeeper::AccessToken.class_exec do
before_create :create_application_user
def create_application_user
return unless application_id && resource_owner_id
FindOrCreateApplicationUser.call(application_id, resource_owner_id)
end
end
Doorkeeper::TokensController.class_exec do
alias_method :original_create, :create # before_action not available
def create
original_create
end
end
end