Skip to content

Commit

Permalink
Fix Slack authentication in blocking client
Browse files Browse the repository at this point in the history
The Slack API has moved on, while this crate has not. Adapted
the approach from slack-rs#107
to pluck the auth token out of the parameter body and send it as
a bearer auth header instead. It is rather surprising to realize that
Slack ever accepted this as a body param, but hey.
  • Loading branch information
ceejbot committed Apr 18, 2022
1 parent d1f1d56 commit 9027667
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/sync/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,25 @@ mod reqwest_support {
{
let mut url = reqwest::Url::parse(method_url.as_ref()).expect("Unable to parse url");

url.query_pairs_mut().extend_pairs(params);
let mut token = None;
{
let mut qp = url.query_pairs_mut();
for param in params {
let (k, v) = param.borrow();
if k.as_ref() == "token" {
token = Some(v.as_ref().to_owned());
continue;
}
qp.append_pair(k.as_ref(), v.as_ref());
}
}

Ok(self.get(url).send()?.text()?)
let mut req = self.get(url);
if let Some(token) = token {
req = req.bearer_auth(token);
};

Ok(req.send()?.text()?)
}
}

Expand Down

0 comments on commit 9027667

Please sign in to comment.