Enables polymorphic Resource Owner feature for Doorkeeper Access Tokens & Grants.
By default Doorkeeper set only resource_owner_id
without knowing model name of the Resource Owner.
Feature available only starting from Doorkeeper 5.4.
Enable configuration option:
{% code-tabs %} {% code-tabs-item title="config/initializers/doorkeeper.rb" %}
Doorkeeper.configure do
orm :active_record
use_polymorphic_resource_owner
end
{% endcode-tabs-item %} {% endcode-tabs %}
Generate migration to add polymorphic columns to tables:
$ bundle exec rails g doorkeeper:enable_polymorphic_resource_owner
If you previously set foreign key for :resource_owner_id
column - you need to drop it as now it
would be a polymorphic association. You can drop FK in the migration generated above.
Run the migration:
$ bundle exec rails db:migrate
Use the feature!
Now you can access resource owner by doorkeeper_token.resource_owner
association.
resource_owner
instance instead of it's ID (like it was before).
- GitLab (https://gitlab.com/gitlab-org/gitlab-foss/blob/master/config/initializers/doorkeeper.rb#L129)
- Doorkeeper ORM extensions
Original PR: doorkeeper-gem/doorkeeper#1355