Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gatsby-core-utils basicAuth issues - TypeError: Parameter auth is deprecated. Use username / password instead. #32664

Closed
2 tasks done
satrix321 opened this issue Aug 2, 2021 · 4 comments · Fixed by #32665
Closed
2 tasks done
Labels
topic: core Relates to Gatsby's core (e.g. page loading, reporter, state machine) type: bug An issue or pull request relating to a bug in Gatsby

Comments

@satrix321
Copy link
Contributor

Preliminary Checks

Description

I've tried updating to the newest version of gatsby-source-drupal, which passes the file requests through gatsby-source-filesystem (createRemoteFileNode function) and to gatsby-core-utils (fetchRemoteFile function). I'm using basic auth for authentication, but during the "Downloading remote files from Drupal" step I'm getting the following error:

failed to process https://...
TypeError: Parameter auth is deprecated. Use username / password instead.

I've looked through the code, and it seems that the culprit is the way the http headers for basic auth are set and passed to "got" library. The culprit seems to be this line of code:

httpOpts.auth = `${auth.htaccess_user}:${auth.htaccess_pass}`

Linking to related "got" options documentation: https://github.com/sindresorhus/got/blob/main/documentation/2-options.md#username

For testing purposes I went ahead and replaced the following code inside my node_modules:

httpOpts.auth = `${auth.htaccess_user}:${auth.htaccess_pass}`;

with

httpOpts.username = auth.htaccess_user;
httpOpts.password = auth.htaccess_pass;

and it seems to fix this issue.

Reproduction Link

Steps to Reproduce

  1. Use a source plugin (eg. Drupal) with basic auth configuration
  2. Have some remote file nodes that need to be created
  3. Run "gatsby build" command

Expected Result

Files should be downloaded without any issues.

Actual Result

info Downloading remote files from Drupal

ERROR

failed to process https://...
TypeError: Parameter auth is deprecated. Use username / password instead.

not finished source and transform nodes - 316.871s
failed Remote file download - 0.208s

Environment

System:
    OS: Linux 5.4 Ubuntu 20.04.2 LTS (Focal Fossa)
    CPU: (8) x64 Intel(R) Core(TM) i7-10610U CPU @ 1.80GHz
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 14.17.3 - ~/.nvm/versions/node/v14.17.3/bin/node
    Yarn: 1.22.10 - /mnt/c/Program Files/nodejs/yarn
    npm: 6.14.13 - ~/.nvm/versions/node/v14.17.3/bin/npm
  npmPackages:
    gatsby: ^3.10.2 => 3.10.2
    gatsby-background-image: ^1.5.3 => 1.5.3
    gatsby-plugin-create-client-paths: ^3.10.0 => 3.10.0
    gatsby-plugin-emotion: ^6.10.0 => 6.10.0
    gatsby-plugin-google-tagmanager: ^3.10.0 => 3.10.0
    gatsby-plugin-image: ^1.10.1 => 1.10.1
    gatsby-plugin-loadable-components-ssr: ^3.2.0 => 3.2.0
    gatsby-plugin-manifest: ^3.10.0 => 3.10.0
    gatsby-plugin-meta-redirect: ^1.1.1 => 1.1.1
    gatsby-plugin-react-helmet: ^4.10.0 => 4.10.0
    gatsby-plugin-robots-txt: ^1.6.8 => 1.6.8
    gatsby-plugin-sass: ^4.10.0 => 4.10.0
    gatsby-plugin-sharp: ^3.10.2 => 3.10.2
    gatsby-plugin-sitemap: ^4.6.0 => 4.6.0
    gatsby-plugin-typegen: ^2.2.4 => 2.2.4
    gatsby-plugin-use-query-params: ^1.0.1 => 1.0.1
    gatsby-plugin-webpack-bundle-analyser-v2: ^1.1.24 => 1.1.24
    gatsby-query-params: ^1.2.1 => 1.2.1
    gatsby-source-filesystem: ^3.10.0 => 3.10.0
    gatsby-transformer-sharp: ^3.10.0 => 3.10.0

Config Flags

No response

@satrix321 satrix321 added the type: bug An issue or pull request relating to a bug in Gatsby label Aug 2, 2021
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Aug 2, 2021
@LekoArts LekoArts added topic: core Relates to Gatsby's core (e.g. page loading, reporter, state machine) and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Aug 2, 2021
@joernroeder
Copy link
Contributor

I'm running into the same issue with the wp source plugin

@joernroeder
Copy link
Contributor

joernroeder commented Aug 16, 2021

@LekoArts I'm seeing the same error and it now breaks my builds. dato and wp both getting the affected got version

├─ gatsby-source-datocms@2.6.16
│  └─ got@11.8.2
├─ gatsby-source-wordpress@5.11.0
│  └─ got@11.8.2

Should I revert to prior versions, or add a specific resolution to fix it?

@LekoArts
Copy link
Contributor

I also suspect it's not working as intended due to sindresorhus/got#1169 - so it's better to use the username and password option.

@joernroeder
Copy link
Contributor

joernroeder commented Aug 18, 2021

I've patched my setup with patch-package and the following diff:

patches/gatsby-core-utils+2.11.0.patch

diff --git a/node_modules/gatsby-core-utils/dist/fetch-remote-file.js b/node_modules/gatsby-core-utils/dist/fetch-remote-file.js
index 960e97e..c5af990 100644
--- a/node_modules/gatsby-core-utils/dist/fetch-remote-file.js
+++ b/node_modules/gatsby-core-utils/dist/fetch-remote-file.js
@@ -146,7 +146,8 @@ async function fetchRemoteFile({
   const httpOpts = {};
 
   if (auth && (auth.htaccess_pass || auth.htaccess_user)) {
-    httpOpts.auth = `${auth.htaccess_user}:${auth.htaccess_pass}`;
+    httpOpts.username = auth.htaccess_user;
+    httpOpts.password = auth.htaccess_pass;
   } // Create the temp and permanent file names for the url.
 

looking forward to see this in master and published.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: core Relates to Gatsby's core (e.g. page loading, reporter, state machine) type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants