Fix streaming API allowing connections to persist after access token invalidation (#15111)
Fix #14816
This commit is contained in:
17
app/lib/access_token_extension.rb
Normal file
17
app/lib/access_token_extension.rb
Normal file
@ -0,0 +1,17 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module AccessTokenExtension
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
after_commit :push_to_streaming_api
|
||||
end
|
||||
|
||||
def revoke(clock = Time)
|
||||
update(revoked_at: clock.now.utc)
|
||||
end
|
||||
|
||||
def push_to_streaming_api
|
||||
Redis.current.publish("timeline:access_token:#{id}", Oj.dump(event: :kill)) if revoked? || destroyed?
|
||||
end
|
||||
end
|
@ -70,12 +70,16 @@ class SessionActivation < ApplicationRecord
|
||||
end
|
||||
|
||||
def assign_access_token
|
||||
superapp = Doorkeeper::Application.find_by(superapp: true)
|
||||
self.access_token = Doorkeeper::AccessToken.create!(access_token_attributes)
|
||||
end
|
||||
|
||||
self.access_token = Doorkeeper::AccessToken.create!(application_id: superapp&.id,
|
||||
resource_owner_id: user_id,
|
||||
scopes: 'read write follow',
|
||||
expires_in: Doorkeeper.configuration.access_token_expires_in,
|
||||
use_refresh_token: Doorkeeper.configuration.refresh_token_enabled?)
|
||||
def access_token_attributes
|
||||
{
|
||||
application_id: Doorkeeper::Application.find_by(superapp: true)&.id,
|
||||
resource_owner_id: user_id,
|
||||
scopes: 'read write follow',
|
||||
expires_in: Doorkeeper.configuration.access_token_expires_in,
|
||||
use_refresh_token: Doorkeeper.configuration.refresh_token_enabled?,
|
||||
}
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user