summaryrefslogtreecommitdiff
path: root/cli/npm/common.rs
diff options
context:
space:
mode:
authorhaturau <135221985+haturatu@users.noreply.github.com>2024-11-20 01:20:47 +0900
committerGitHub <noreply@github.com>2024-11-20 01:20:47 +0900
commit85719a67e59c7aa45bead26e4942d7df8b1b42d4 (patch)
treeface0aecaac53e93ce2f23b53c48859bcf1a36ec /cli/npm/common.rs
parent67697bc2e4a62a9670699fd18ad0dd8efc5bd955 (diff)
parent186b52731c6bb326c4d32905c5e732d082e83465 (diff)
Merge branch 'denoland:main' into main
Diffstat (limited to 'cli/npm/common.rs')
-rw-r--r--cli/npm/common.rs23
1 files changed, 14 insertions, 9 deletions
diff --git a/cli/npm/common.rs b/cli/npm/common.rs
index a3a828e74..55f1bc086 100644
--- a/cli/npm/common.rs
+++ b/cli/npm/common.rs
@@ -3,6 +3,7 @@
use base64::prelude::BASE64_STANDARD;
use base64::Engine;
use deno_core::anyhow::bail;
+use deno_core::anyhow::Context;
use deno_core::error::AnyError;
use deno_npm::npm_rc::RegistryConfig;
use http::header;
@@ -36,17 +37,21 @@ pub fn maybe_auth_header_for_npm_registry(
}
if username.is_some() && password.is_some() {
+ // The npm client does some double encoding when generating the
+ // bearer token value, see
+ // https://github.com/npm/cli/blob/780afc50e3a345feb1871a28e33fa48235bc3bd5/workspaces/config/lib/index.js#L846-L851
+ let pw_base64 = BASE64_STANDARD
+ .decode(password.unwrap())
+ .with_context(|| "The password in npmrc is an invalid base64 string")?;
+ let bearer = BASE64_STANDARD.encode(format!(
+ "{}:{}",
+ username.unwrap(),
+ String::from_utf8_lossy(&pw_base64)
+ ));
+
return Ok(Some((
header::AUTHORIZATION,
- header::HeaderValue::from_str(&format!(
- "Basic {}",
- BASE64_STANDARD.encode(&format!(
- "{}:{}",
- username.unwrap(),
- password.unwrap()
- ))
- ))
- .unwrap(),
+ header::HeaderValue::from_str(&format!("Basic {}", bearer)).unwrap(),
)));
}