Use jsonApiRequest method instead of request method in PhysicalFile for file transfers

Created on 14 November 2023, 8 months ago
Updated 15 November 2023, 8 months ago

Problem/Motivation

While syncing content with the "Physical file" import processor plugin enabled in the client's import config and using "Basic Auth" as the authorization method in the client's remote config, there is a call made to the server using the request() method in entity_share/modules/entity_share_client/src/Plugin/EntityShareClient/Processor/PhysicalFile.php to fetch the file. This call is eventually completing the authentication process via the user_login_form using the provided credentials.
In our case, the authentication fails, since we are using the password_encrypt → module, wherein the password needs to be an encrypted one. This led to us wondering if this call from PhysicalFile.php could be updated to jsonApiRequest() instead of request(). This change works fine for our use-case but just need to know if there is any particular reason why this call is using request() instead of jsonApiRequest() from RemoteManager.php

Steps to reproduce

  1. Setup 2 Drupal 9 websites: http://local.abc.com/ and http://local.xyz.com/
  2. Enable entity_share_server on http://local.abc.com/ to act as server and add channel for Article content type with access enabled for a user with administrator role here: /admin/config/services/entity_share/channel Also enable basic_auth module on this site.
  3. Install and enable password_encrypt → module on http://local.abc.com/
  4. Enable dblog module on http://local.abc.com/
  5. Enable entity_share_client and entity_share_async modules on http://local.xyz.com/ to act as client and add Import config with Physical file option enabled here: /admin/config/services/entity_share/import_config and add remote website as http://local.abc.com/ and select Basic Auth as the authorization method and specify the credentials of the user configured in step 2 on server.
  6. Create Article content with an image on http://local.abc.com/
  7. Navigate to /admin/content/entity_share/pull on http://local.xyz.com/ and see that the newly created content on server is available here to import. Select the content to Import asynchronously and execute cron.
  8. Once the content is imported successfully on http://local.xyz.com/, navigate to http://local.abc.com/admin/reports/dblog and filter the logs with user type to see the "Login attempt failed for the user" log.

Proposed resolution

Change the following line of code in /entity_share/modules/entity_share_client/src/Plugin/EntityShareClient/Processor/PhysicalFile.php:

$response = $this->remoteManager->request($runtime_import_context->getRemote(), 'GET', $remote_file_url);

to:

$response = $this->remoteManager->jsonApiRequest($runtime_import_context->getRemote(), 'GET', $remote_file_url);

Remaining tasks

Discuss if there is an alternate approach to handle this.

💬 Support request
Status

Needs review

Version

3.0

Component

Entity Share Client

Created by

🇮🇳India Vinay15 Navi Mumbai

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024