@@ -14,6 +14,7 @@ module AccessTokenMixin
1414 include Models ::Scopes
1515 include Models ::ResourceOwnerable
1616 include Models ::ExpirationTimeSqlMath
17+ include Models ::Concerns ::WriteToPrimary
1718
1819 module ClassMethods
1920 # Returns an instance of the Doorkeeper::AccessToken with
@@ -66,12 +67,14 @@ def by_previous_refresh_token(previous_refresh_token)
6667 # instance of the Resource Owner model or it's ID
6768 #
6869 def revoke_all_for ( application_id , resource_owner , clock = Time )
69- by_resource_owner ( resource_owner )
70- . where (
71- application_id : application_id ,
72- revoked_at : nil ,
73- )
74- . update_all ( revoked_at : clock . now . utc )
70+ with_primary_role do
71+ by_resource_owner ( resource_owner )
72+ . where (
73+ application_id : application_id ,
74+ revoked_at : nil ,
75+ )
76+ . update_all ( revoked_at : clock . now . utc )
77+ end
7578 end
7679
7780 # Looking for not revoked Access Token with a matching set of scopes
@@ -260,7 +263,9 @@ def create_for(application:, resource_owner:, scopes:, **token_attributes)
260263 token_attributes [ :resource_owner_id ] = resource_owner_id_for ( resource_owner )
261264 end
262265
263- create! ( token_attributes )
266+ with_primary_role do
267+ create! ( token_attributes )
268+ end
264269 end
265270
266271 # Looking for not revoked Access Token records that belongs to specific
@@ -435,7 +440,12 @@ def revoke_previous_refresh_token!
435440 return if !self . class . refresh_token_revoked_on_use? || previous_refresh_token . blank?
436441
437442 old_refresh_token &.revoke
438- update_attribute ( :previous_refresh_token , "" )
443+
444+ if self . class . respond_to? ( :with_primary_role )
445+ self . class . with_primary_role { update_attribute ( :previous_refresh_token , "" ) }
446+ else
447+ update_attribute ( :previous_refresh_token , "" )
448+ end
439449 end
440450
441451 private
0 commit comments