lib/doorkeeper/oauth/client_credentials/creator.rb in doorkeeper-5.2.0.rc1 vs lib/doorkeeper/oauth/client_credentials/creator.rb in doorkeeper-5.2.0.rc2
- old
+ new
@@ -3,13 +3,27 @@
module Doorkeeper
module OAuth
class ClientCredentialsRequest < BaseRequest
class Creator
def call(client, scopes, attributes = {})
+ existing_token = existing_token_for(client, scopes)
+
+ if Doorkeeper.configuration.reuse_access_token && existing_token&.reusable?
+ return existing_token
+ end
+
+ existing_token&.revoke
+
AccessToken.find_or_create_for(
client, nil, scopes, attributes[:expires_in],
attributes[:use_refresh_token]
)
+ end
+
+ private
+
+ def existing_token_for(client, scopes)
+ Doorkeeper::AccessToken.matching_token_for client, nil, scopes
end
end
end
end
end