doorkeeper
  • Doorkeeper Guides
  • Ruby on Rails
    • Getting Started
    • Routes
    • Configuration
    • Scopes
    • Securing the API
    • API Mode
    • PKCE Flow
    • Polymorphic Resource Owner
  • Grape
    • Grape
  • ORMs
    • Active Record
    • MongoDB
    • Sequel
    • Couchbase
  • Internals
    • Database Design
    • Internationalization (i18n)
    • Rake
    • Testing
    • Upgrading
    • Creating extensions
  • Security
    • Token and Application Secrets
  • Configuration
    • Models
    • Scopes
    • Skip Authorization
    • Other Configurations
    • Route Constraints and other integrations
Powered by GitBook
On this page
  • How to use it
  • Known projects affected

Was this helpful?

  1. Ruby on Rails

Polymorphic Resource Owner

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.

How to use it

Enable configuration option:

Doorkeeper.configure do
  orm :active_record

  use_polymorphic_resource_owner
end

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.

:warning: :warning: [ATTENTION]: If you enabled this option on existing project - you need to manually set polymorphic type column with the class of the Resource Owner. Otherwise your existing users/clients could face issues and spam you logs with errors.

:warning: :warning: [ATTENTION]: Also this feature could be a breaking change for those users that patched Doorkeeper internals, specially models. You need to fix your patches to user resource_owner instance instead of it's ID (like it was before).

Known projects affected

  • Doorkeeper ORM extensions

PreviousPKCE FlowNextGrape

Last updated 5 years ago

Was this helpful?

GitLab ()

Original PR:

https://gitlab.com/gitlab-org/gitlab-foss/blob/master/config/initializers/doorkeeper.rb#L129
https://github.com/doorkeeper-gem/doorkeeper/pull/1355