From eac4133b10a8a5b5b1d357cdc1f300b0ea043fd2 Mon Sep 17 00:00:00 2001 From: kohbis <18735471+kohbis@users.noreply.github.com> Date: Sun, 22 Jan 2023 00:38:04 +0900 Subject: [PATCH] fix: pass 'token' as an HTTP Authorization header --- src/api/mod.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/api/mod.rs b/src/api/mod.rs index 2f8d4e2..ce154b1 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -21,10 +21,9 @@ pub struct SlackChannel { * Get slack channels. */ pub async fn get_channels(config: &Config) -> Result> { - let params = vec![("token", &config.token)]; - let url = Url::parse_with_params("https://slack.com/api/conversations.list", params).unwrap(); + let url = Url::parse("https://slack.com/api/conversations.list").unwrap(); - let client = Client::new().get(url); + let client = Client::new().get(url).bearer_auth(&config.token); let res: SlackResponse = client.send().await?.json().await?; @@ -39,14 +38,13 @@ pub async fn get_channels(config: &Config) -> Result> { * Post slack message. */ pub async fn post_message(config: &Config, channel: &str, text: &str) -> Result { - let body = vec![ - ("channel", channel), - ("text", text), - ("token", &config.token), - ]; + let body = vec![("channel", channel), ("text", text)]; let url = Url::parse("https://slack.com/api/chat.postMessage").unwrap(); - let client = Client::new().post(url).form(&body); + let client = Client::new() + .post(url) + .bearer_auth(&config.token) + .form(&body); let res: SlackResponse = client.send().await?.json().await?;