Skip to main content

slack_web_api/api/
openid.rs

1// このファイルは codegen/generate.py が生成する。手で編集しない
2
3#![allow(unused_imports)]
4
5use crate::objects::*;
6use crate::{
7    CursorPaginated, NextCursor, ResponseMetadata, SlackApiMethod, SlackClient, SlackError,
8};
9use serde::{Deserialize, Serialize};
10
11/// Arguments for the Slack Web API method [`openid.connect.token`](https://docs.slack.dev/reference/methods/openid.connect.token): Exchanges a temporary OAuth verifier code for an access token for Sign in with Slack.
12///
13/// Send it with [`SlackClient::openid_connect_token`].
14#[doc(alias = "openid.connect.token")]
15#[derive(Debug, Clone, PartialEq, Serialize, Default)]
16#[non_exhaustive]
17pub struct OpenidConnectTokenRequest {
18    /// Issued when you created your application.
19    #[serde(skip_serializing_if = "Option::is_none")]
20    pub client_id: Option<String>,
21    /// Issued when you created your application.
22    #[serde(skip_serializing_if = "Option::is_none")]
23    pub client_secret: Option<String>,
24    /// The `code` param returned via the OAuth callback.
25    #[serde(skip_serializing_if = "Option::is_none")]
26    pub code: Option<String>,
27    /// This must match the originally submitted URI (if one was sent).
28    #[serde(skip_serializing_if = "Option::is_none")]
29    pub redirect_uri: Option<String>,
30    /// The `grant_type` param as described in the OAuth spec.
31    #[serde(skip_serializing_if = "Option::is_none")]
32    pub grant_type: Option<String>,
33    /// The `refresh_token` param as described in the OAuth spec.
34    #[serde(skip_serializing_if = "Option::is_none")]
35    pub refresh_token: Option<String>,
36    /// PKCE code verifier (RFC 7636). Required when the authorization request included a `code_challenge`.
37    #[serde(skip_serializing_if = "Option::is_none")]
38    pub code_verifier: Option<String>,
39}
40
41impl OpenidConnectTokenRequest {
42    pub fn new() -> Self {
43        Self {
44            client_id: None,
45            client_secret: None,
46            code: None,
47            redirect_uri: None,
48            grant_type: None,
49            refresh_token: None,
50            code_verifier: None,
51        }
52    }
53
54    pub fn client_id(mut self, client_id: impl Into<String>) -> Self {
55        self.client_id = Some(client_id.into());
56        self
57    }
58
59    pub fn client_secret(mut self, client_secret: impl Into<String>) -> Self {
60        self.client_secret = Some(client_secret.into());
61        self
62    }
63
64    pub fn code(mut self, code: impl Into<String>) -> Self {
65        self.code = Some(code.into());
66        self
67    }
68
69    pub fn redirect_uri(mut self, redirect_uri: impl Into<String>) -> Self {
70        self.redirect_uri = Some(redirect_uri.into());
71        self
72    }
73
74    pub fn grant_type(mut self, grant_type: impl Into<String>) -> Self {
75        self.grant_type = Some(grant_type.into());
76        self
77    }
78
79    pub fn refresh_token(mut self, refresh_token: impl Into<String>) -> Self {
80        self.refresh_token = Some(refresh_token.into());
81        self
82    }
83
84    pub fn code_verifier(mut self, code_verifier: impl Into<String>) -> Self {
85        self.code_verifier = Some(code_verifier.into());
86        self
87    }
88}
89
90impl SlackApiMethod for OpenidConnectTokenRequest {
91    const METHOD: &'static str = "openid.connect.token";
92    type Response = OpenidConnectTokenResponse;
93}
94
95/// Successful response of the Slack Web API method [`openid.connect.token`](https://docs.slack.dev/reference/methods/openid.connect.token).
96#[doc(alias = "openid.connect.token")]
97#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
98pub struct OpenidConnectTokenResponse {
99    #[serde(
100        default,
101        deserialize_with = "crate::de::opt_string",
102        skip_serializing_if = "Option::is_none"
103    )]
104    pub access_token: Option<String>,
105    #[serde(
106        default,
107        deserialize_with = "crate::de::opt_string",
108        skip_serializing_if = "Option::is_none"
109    )]
110    pub token_type: Option<String>,
111    #[serde(
112        default,
113        deserialize_with = "crate::de::opt_string",
114        skip_serializing_if = "Option::is_none"
115    )]
116    pub id_token: Option<String>,
117    #[serde(
118        default,
119        deserialize_with = "crate::de::opt_object",
120        skip_serializing_if = "Option::is_none"
121    )]
122    pub response_metadata: Option<ResponseMetadata>,
123    #[serde(
124        default,
125        deserialize_with = "crate::de::opt_string",
126        skip_serializing_if = "Option::is_none"
127    )]
128    pub warning: Option<String>,
129}
130
131/// Arguments for the Slack Web API method [`openid.connect.userInfo`](https://docs.slack.dev/reference/methods/openid.connect.userInfo): Get the identity of a user who has authorized Sign in with Slack.
132///
133/// Send it with [`SlackClient::openid_connect_user_info`].
134#[doc(alias = "openid.connect.userInfo")]
135#[derive(Debug, Clone, PartialEq, Serialize, Default)]
136#[non_exhaustive]
137pub struct OpenidConnectUserInfoRequest {}
138
139impl OpenidConnectUserInfoRequest {
140    pub fn new() -> Self {
141        Self {}
142    }
143}
144
145impl SlackApiMethod for OpenidConnectUserInfoRequest {
146    const METHOD: &'static str = "openid.connect.userInfo";
147    type Response = OpenidConnectUserInfoResponse;
148}
149
150/// Successful response of the Slack Web API method [`openid.connect.userInfo`](https://docs.slack.dev/reference/methods/openid.connect.userInfo).
151#[doc(alias = "openid.connect.userInfo")]
152#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
153pub struct OpenidConnectUserInfoResponse {
154    #[serde(
155        default,
156        deserialize_with = "crate::de::opt_string",
157        skip_serializing_if = "Option::is_none"
158    )]
159    pub sub: Option<String>,
160    #[serde(
161        rename = "https://slack.com/user_id",
162        default,
163        deserialize_with = "crate::de::opt_string",
164        skip_serializing_if = "Option::is_none"
165    )]
166    pub slack_user_id: Option<String>,
167    #[serde(
168        rename = "https://slack.com/team_id",
169        default,
170        deserialize_with = "crate::de::opt_string",
171        skip_serializing_if = "Option::is_none"
172    )]
173    pub slack_team_id: Option<String>,
174    #[serde(
175        default,
176        deserialize_with = "crate::de::opt_string",
177        skip_serializing_if = "Option::is_none"
178    )]
179    pub email: Option<String>,
180    #[serde(
181        default,
182        deserialize_with = "crate::de::opt_bool",
183        skip_serializing_if = "Option::is_none"
184    )]
185    pub email_verified: Option<bool>,
186    #[serde(
187        default,
188        deserialize_with = "crate::de::opt_i64",
189        skip_serializing_if = "Option::is_none"
190    )]
191    pub date_email_verified: Option<i64>,
192    #[serde(
193        default,
194        deserialize_with = "crate::de::opt_string",
195        skip_serializing_if = "Option::is_none"
196    )]
197    pub name: Option<String>,
198    #[serde(
199        default,
200        deserialize_with = "crate::de::opt_string",
201        skip_serializing_if = "Option::is_none"
202    )]
203    pub picture: Option<String>,
204    #[serde(
205        default,
206        deserialize_with = "crate::de::opt_string",
207        skip_serializing_if = "Option::is_none"
208    )]
209    pub given_name: Option<String>,
210    #[serde(
211        default,
212        deserialize_with = "crate::de::opt_string",
213        skip_serializing_if = "Option::is_none"
214    )]
215    pub family_name: Option<String>,
216    #[serde(
217        default,
218        deserialize_with = "crate::de::opt_string",
219        skip_serializing_if = "Option::is_none"
220    )]
221    pub locale: Option<String>,
222    #[serde(
223        rename = "https://slack.com/team_name",
224        default,
225        deserialize_with = "crate::de::opt_string",
226        skip_serializing_if = "Option::is_none"
227    )]
228    pub slack_team_name: Option<String>,
229    #[serde(
230        rename = "https://slack.com/team_domain",
231        default,
232        deserialize_with = "crate::de::opt_string",
233        skip_serializing_if = "Option::is_none"
234    )]
235    pub slack_team_domain: Option<String>,
236    #[serde(
237        rename = "https://slack.com/user_image_24",
238        default,
239        deserialize_with = "crate::de::opt_string",
240        skip_serializing_if = "Option::is_none"
241    )]
242    pub slack_user_image_24: Option<String>,
243    #[serde(
244        rename = "https://slack.com/user_image_32",
245        default,
246        deserialize_with = "crate::de::opt_string",
247        skip_serializing_if = "Option::is_none"
248    )]
249    pub slack_user_image_32: Option<String>,
250    #[serde(
251        rename = "https://slack.com/user_image_48",
252        default,
253        deserialize_with = "crate::de::opt_string",
254        skip_serializing_if = "Option::is_none"
255    )]
256    pub slack_user_image_48: Option<String>,
257    #[serde(
258        rename = "https://slack.com/user_image_72",
259        default,
260        deserialize_with = "crate::de::opt_string",
261        skip_serializing_if = "Option::is_none"
262    )]
263    pub slack_user_image_72: Option<String>,
264    #[serde(
265        rename = "https://slack.com/user_image_192",
266        default,
267        deserialize_with = "crate::de::opt_string",
268        skip_serializing_if = "Option::is_none"
269    )]
270    pub slack_user_image_192: Option<String>,
271    #[serde(
272        rename = "https://slack.com/user_image_512",
273        default,
274        deserialize_with = "crate::de::opt_string",
275        skip_serializing_if = "Option::is_none"
276    )]
277    pub slack_user_image_512: Option<String>,
278    #[serde(
279        rename = "https://slack.com/team_image_34",
280        default,
281        deserialize_with = "crate::de::opt_string",
282        skip_serializing_if = "Option::is_none"
283    )]
284    pub slack_team_image_34: Option<String>,
285    #[serde(
286        rename = "https://slack.com/team_image_44",
287        default,
288        deserialize_with = "crate::de::opt_string",
289        skip_serializing_if = "Option::is_none"
290    )]
291    pub slack_team_image_44: Option<String>,
292    #[serde(
293        rename = "https://slack.com/team_image_68",
294        default,
295        deserialize_with = "crate::de::opt_string",
296        skip_serializing_if = "Option::is_none"
297    )]
298    pub slack_team_image_68: Option<String>,
299    #[serde(
300        rename = "https://slack.com/team_image_88",
301        default,
302        deserialize_with = "crate::de::opt_string",
303        skip_serializing_if = "Option::is_none"
304    )]
305    pub slack_team_image_88: Option<String>,
306    #[serde(
307        rename = "https://slack.com/team_image_102",
308        default,
309        deserialize_with = "crate::de::opt_string",
310        skip_serializing_if = "Option::is_none"
311    )]
312    pub slack_team_image_102: Option<String>,
313    #[serde(
314        rename = "https://slack.com/team_image_132",
315        default,
316        deserialize_with = "crate::de::opt_string",
317        skip_serializing_if = "Option::is_none"
318    )]
319    pub slack_team_image_132: Option<String>,
320    #[serde(
321        rename = "https://slack.com/team_image_230",
322        default,
323        deserialize_with = "crate::de::opt_string",
324        skip_serializing_if = "Option::is_none"
325    )]
326    pub slack_team_image_230: Option<String>,
327    #[serde(
328        rename = "https://slack.com/team_image_default",
329        default,
330        deserialize_with = "crate::de::opt_bool",
331        skip_serializing_if = "Option::is_none"
332    )]
333    pub slack_team_image_default: Option<bool>,
334    #[serde(
335        default,
336        deserialize_with = "crate::de::opt_object",
337        skip_serializing_if = "Option::is_none"
338    )]
339    pub response_metadata: Option<ResponseMetadata>,
340    #[serde(
341        default,
342        deserialize_with = "crate::de::opt_string",
343        skip_serializing_if = "Option::is_none"
344    )]
345    pub warning: Option<String>,
346}
347
348impl SlackClient {
349    /// Calls the Slack Web API method [`openid.connect.token`](https://docs.slack.dev/reference/methods/openid.connect.token): Exchanges a temporary OAuth verifier code for an access token for Sign in with Slack.
350    ///
351    /// Rate limit: Tier 4 (<https://docs.slack.dev/apis/web-api/rate-limits>).
352    ///
353    /// # Errors
354    ///
355    /// Returns [`SlackError::Api`] when Slack answers `"ok": false`; see [`SlackClient::call`] for the other cases.
356    #[doc(alias = "openid.connect.token")]
357    pub async fn openid_connect_token(
358        &self,
359        request: &OpenidConnectTokenRequest,
360    ) -> Result<OpenidConnectTokenResponse, SlackError> {
361        self.call(request).await
362    }
363
364    /// Calls the Slack Web API method [`openid.connect.userInfo`](https://docs.slack.dev/reference/methods/openid.connect.userInfo): Get the identity of a user who has authorized Sign in with Slack.
365    ///
366    /// Required scopes:
367    ///
368    /// - user token: `openid`
369    ///
370    /// Rate limit: Tier 3 (<https://docs.slack.dev/apis/web-api/rate-limits>).
371    ///
372    /// # Errors
373    ///
374    /// Returns [`SlackError::Api`] when Slack answers `"ok": false`; see [`SlackClient::call`] for the other cases.
375    #[doc(alias = "openid.connect.userInfo")]
376    pub async fn openid_connect_user_info(
377        &self,
378        request: &OpenidConnectUserInfoRequest,
379    ) -> Result<OpenidConnectUserInfoResponse, SlackError> {
380        self.call(request).await
381    }
382}