yggdrasil_authenticator/model/request/refresh_request.rs
1use crate::auth_profile::AuthProfile;
2use serde::Serialize;
3
4/// A request struct for refreshing an access token in Yggdrasil's authentication system.
5///
6/// This struct is used to represent a request to refresh the user's access token,
7/// client token, and optionally request user information or refresh a selected profile.
8#[derive(Serialize)]
9pub struct RefreshRequest {
10 /// The access token to refresh.
11 #[serde(rename = "accessToken")]
12 pub access_token: String,
13
14 /// The client token associated with the user.
15 #[serde(rename = "clientToken")]
16 pub client_token: String,
17
18 /// Whether to request user information in the response.
19 #[serde(rename = "requestUser")]
20 pub request_user: bool,
21
22 /// The selected profile to refresh, if any. This field is not serialized if it is `None`.
23 #[serde(rename = "selectedProfile", skip_serializing_if = "Option::is_none")]
24 pub selected_profile: Option<AuthProfile>,
25}
26
27impl RefreshRequest {
28 /// Creates a new `RefreshRequest` with the provided access token, client token, and optionally
29 /// the selected profile and a flag indicating whether to request user information.
30 ///
31 /// # Arguments
32 ///
33 /// * `access_token` - The access token to refresh.
34 /// * `client_token` - The client token associated with the user.
35 /// * `request_user` - Whether to request user information in the response.
36 /// * `selected_profile` - An optional profile to refresh. Can be `None` if no profile is selected.
37 ///
38 /// # Returns
39 ///
40 /// A new `RefreshRequest` instance.
41 pub fn new(
42 access_token: String,
43 client_token: String,
44 request_user: bool,
45 selected_profile: Option<AuthProfile>,
46 ) -> RefreshRequest {
47 RefreshRequest {
48 access_token,
49 client_token,
50 request_user,
51 selected_profile,
52 }
53 }
54}