Skip to content

Commit

Permalink
fix. ensure values are encoded
Browse files Browse the repository at this point in the history
  • Loading branch information
juliusl committed Jun 22, 2023
1 parent 72c3ecb commit f2c36fb
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/plugins/authenticate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,22 @@ impl Authenticate {
https://$registry/oauth2/token
*/

let body = format!(
"{}&grant_type=password&username={}&password={}",
challenge_uri.query().unwrap(),
user,
password
);

let req = Request::builder()
.uri(challenge_uri)
.header("Content-Type", "application/x-www-form-urlencoded")
.method(Method::POST)
.body(body);

(ns, req)
if let Ok(encoded) = serde_urlencoded::to_string(&[
("grant_type", "password"),
("username", user.as_str()),
("password", password.as_str()),
]) {
let body = format!("{}&{}", challenge_uri.query().unwrap(), encoded);
let req = Request::builder()
.uri(challenge_uri)
.header("Content-Type", "application/x-www-form-urlencoded")
.method(Method::POST)
.body(body);
(ns, req)
} else {
tracing::error!("Could not encode username/password authn body");
return None;
}
} else if let (Some(ns), Some(token)) = (
tc.search().find_symbol("REGISTRY_NAMESPACE"),
tc.search().find_symbol("REGISTRY_TOKEN"),
Expand Down

0 comments on commit f2c36fb

Please sign in to comment.