slack_chat_api/
oauth_v_2.rs

1use crate::Client;
2use crate::ClientResult;
3
4pub struct OauthV2 {
5    pub client: Client,
6}
7
8impl OauthV2 {
9    #[doc(hidden)]
10    pub fn new(client: Client) -> Self {
11        OauthV2 { client }
12    }
13
14    /**
15     * This function performs a `GET` to the `/oauth.v2.access` endpoint.
16     *
17     * Exchanges a temporary OAuth verifier code for an access token.
18     *
19     * FROM: <https://api.slack.com/methods/oauth.v2.access>
20     *
21     * **Parameters:**
22     *
23     * * `client_id: &str` -- Issued when you created your application.
24     * * `client_secret: &str` -- Issued when you created your application.
25     * * `code: &str` -- The `code` param returned via the OAuth callback.
26     * * `redirect_uri: &str` -- This must match the originally submitted URI (if one was sent).
27     */
28    pub async fn oauth_access(
29        &self,
30        client_id: &str,
31        client_secret: &str,
32        code: &str,
33        redirect_uri: &str,
34    ) -> ClientResult<crate::Response<crate::types::DndEndSchema>> {
35        let mut query_args: Vec<(String, String)> = Default::default();
36        if !client_id.is_empty() {
37            query_args.push(("client_id".to_string(), client_id.to_string()));
38        }
39        if !client_secret.is_empty() {
40            query_args.push(("client_secret".to_string(), client_secret.to_string()));
41        }
42        if !code.is_empty() {
43            query_args.push(("code".to_string(), code.to_string()));
44        }
45        if !redirect_uri.is_empty() {
46            query_args.push(("redirect_uri".to_string(), redirect_uri.to_string()));
47        }
48        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
49        let url = self
50            .client
51            .url(&format!("/oauth.v2.access?{}", query_), None);
52        self.client
53            .get(
54                &url,
55                crate::Message {
56                    body: None,
57                    content_type: None,
58                },
59            )
60            .await
61    }
62}