看门人:如何知道授权何时创建?

Doorkeeper: How to know when a grant is created?

我想在用户授予应用程序访问权限时创建会员记录。

门卫有活动吗?

我的解决方案是使用 rails 观察者:

Gemfile:

gem 'rails-observers'

app/models/doorkeeper/access_token_observer.rb:

class Doorkeeper::AccessTokenObserver < ActiveRecord::Observer
  def after_create(access_token)
    # do stuff with:
    # access_token.application_id
    # access_token.resource_owner_id
  end
end