Skip to content

Commit 9a09db0

Browse files
Merge pull request #52 from CleverCloud/clg/51
fix(oauth): ensure oauth_signature is URL encoded
2 parents 2d89c43 + a20ecbc commit 9a09db0

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/client/mod.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
77
use std::{
88
collections::BTreeMap,
9-
convert::TryFrom,
109
error::Error,
1110
fmt::{self, Debug, Display, Formatter},
1211
future::Future,
@@ -227,11 +226,14 @@ pub trait OAuth1: Debug {
227226
let signature = self.signature(method, endpoint)?;
228227
let mut params = self.params();
229228

230-
params.insert(OAUTH1_SIGNATURE.to_string(), signature);
229+
params.insert(
230+
OAUTH1_SIGNATURE.to_string(),
231+
urlencoding::encode(&signature).into_owned(),
232+
);
231233

232234
let mut base = params
233235
.iter()
234-
.map(|(k, v)| format!("{}=\"{}\"", k, v))
236+
.map(|(k, v)| format!("{k}=\"{v}\""))
235237
.collect::<Vec<_>>();
236238

237239
base.sort();
@@ -331,7 +333,7 @@ impl OAuth1 for Signer {
331333
if !query.is_empty() {
332334
for qparam in query.split('&') {
333335
let (k, v) = qparam.split_at(qparam.find('=').ok_or_else(|| {
334-
SignerError::Parse(format!("failed to parse query parameter, {}", qparam))
336+
SignerError::Parse(format!("failed to parse query parameter, {qparam}"))
335337
})?);
336338

337339
if !params.contains_key(k) {
@@ -367,8 +369,8 @@ impl OAuth1 for Signer {
367369
fn signing_key(&self) -> String {
368370
format!(
369371
"{}&{}",
370-
urlencoding::encode(&self.consumer_secret.to_owned()),
371-
urlencoding::encode(&self.secret.to_owned())
372+
urlencoding::encode(&self.consumer_secret),
373+
urlencoding::encode(&self.secret)
372374
)
373375
}
374376
}
@@ -513,7 +515,7 @@ impl Request for Client {
513515
Some(Credentials::Bearer { token }) => {
514516
request.headers_mut().insert(
515517
header::AUTHORIZATION,
516-
HeaderValue::from_str(&format!("Bearer {}", token))
518+
HeaderValue::from_str(&format!("Bearer {token}"))
517519
.map_err(ClientError::SerializeHeaderValue)?,
518520
);
519521
}
@@ -522,7 +524,7 @@ impl Request for Client {
522524

523525
request.headers_mut().insert(
524526
header::AUTHORIZATION,
525-
HeaderValue::from_str(&format!("Basic {token}",))
527+
HeaderValue::from_str(&format!("Basic {token}"))
526528
.map_err(ClientError::SerializeHeaderValue)?,
527529
);
528530
}

0 commit comments

Comments
 (0)