class Doorkeeper::OAuth::ClientCredentials::Creator
def call(client, scopes, attributes = {})
def call(client, scopes, attributes = {}) existing_token = nil if lookup_existing_token? existing_token = find_active_existing_token_for(client, scopes) return existing_token if server_config.reuse_access_token && existing_token&.reusable? end with_revocation(existing_token: existing_token) do application = client.is_a?(server_config.application_model) ? client : client&.application server_config.access_token_model.create_for( application: application, resource_owner: nil, scopes: scopes, **attributes, ) end end
def find_active_existing_token_for(client, scopes)
def find_active_existing_token_for(client, scopes) server_config.access_token_model.matching_token_for(client, nil, scopes, include_expired: false) end
def lookup_existing_token?
def lookup_existing_token? server_config.reuse_access_token || server_config.revoke_previous_client_credentials_token? end
def server_config
def server_config Doorkeeper.config end
def with_revocation(existing_token:)
def with_revocation(existing_token:) if existing_token && server_config.revoke_previous_client_credentials_token? existing_token.with_lock do raise Errors::DoorkeeperError, :invalid_token_reuse if existing_token.revoked? existing_token.revoke yield end else yield end end