简体   繁体   中英

Rails Overriding Doorkeeper class

How can I override the AccessToken class of the Doorkeeper gem?

https://github.com/doorkeeper-gem/doorkeeper/blob/master/lib/doorkeeper/orm/active_record/access_token.rb

I already tried creating the class at models/access_token.rb

module Doorkeeper
  class AccessToken < ActiveRecord::Base
    belongs_to :resource_owner, class_name: 'OauthResourceOwner'

    include AccessTokenMixin

    def as_json(*)
      super.except!(:resource_owner_id).merge!(
        owner: {
          id: resource_owner&.owner_id,
          type: resource_owner&.owner_type&.tableize
        }
      )
    end
  end
end

I faced with same issue. And add association in initializer

Doorkeeper::AccessToken.belongs_to :resource_owner, class_name: 'OauthResourceOwner'

在Ruby中,类是“开放的”,这意味着您没有覆盖AccessToken ,而是向AccessToken添加方法。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM