-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce polymorphic resource owner
- Loading branch information
Showing
50 changed files
with
1,300 additions
and
909 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# frozen_string_literal: true | ||
|
||
module Doorkeeper | ||
module Models | ||
module ResourceOwnerable | ||
extend ActiveSupport::Concern | ||
|
||
module ClassMethods | ||
# Searches for record by Resource Owner considering Doorkeeper | ||
# configuration for resource owner association. | ||
# | ||
# @param resource_owner [ActiveRecord::Base, Integer] | ||
# resource owner | ||
# | ||
# @return [Doorkeeper::AccessGrant, Doorkeeper::AccessToken] | ||
# collection of records | ||
# | ||
def by_resource_owner(resource_owner) | ||
if Doorkeeper.configuration.polymorphic_resource_owner? | ||
where(resource_owner: resource_owner) | ||
else | ||
where(resource_owner_id: resource_owner_id_for(resource_owner)) | ||
end | ||
end | ||
|
||
protected | ||
|
||
# Backward compatible way to retrieve resource owner itself (if | ||
# polymorphic association enabled) or just it's ID. | ||
# | ||
# @param resource_owner [ActiveRecord::Base, Integer] | ||
# resource owner | ||
# | ||
# @return [ActiveRecord::Base, Integer] | ||
# instance of Resource Owner or it's ID | ||
# | ||
def resource_owner_id_for(resource_owner) | ||
if resource_owner.respond_to?(:to_key) | ||
resource_owner.id | ||
else | ||
resource_owner | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
015a062
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nbulaj Do you have any examples for how one might implement
resource_owner_authenticator
for a polymorphic resource owner?Without this option enabled, it looks something like this:
However, with the polymorphic, you would need a way to determine the resource type. It could be by client id, it could be by an additional query parameter. Any suggestions?