oxide_api/
hidden.rs

1use anyhow::Result;
2
3use crate::Client;
4
5pub struct Hidden {
6    pub client: Client,
7}
8
9impl Hidden {
10    #[doc(hidden)]
11    pub fn new(client: Client) -> Self {
12        Hidden { client }
13    }
14
15    /**
16     * Start an OAuth 2.0 Device Authorization Grant.
17     *
18     * This function performs a `POST` to the `/device/auth` endpoint.
19     *
20     * This endpoint is designed to be accessed from an *unauthenticated* API client. It generates and records a `device_code` and `user_code` which must be verified and confirmed prior to a token being granted.
21     */
22    pub async fn device_auth_request(&self) -> Result<()> {
23        let url = "/device/auth".to_string();
24        self.client.post(&url, None).await
25    }
26
27    /**
28     * Confirm an OAuth 2.0 Device Authorization Grant.
29     *
30     * This function performs a `POST` to the `/device/confirm` endpoint.
31     *
32     * This endpoint is designed to be accessed by the user agent (browser), not the client requesting the token. So we do not actually return the token here; it will be returned in response to the poll on `/device/token`.
33     */
34    pub async fn device_auth_confirm(&self, body: &crate::types::DeviceAuthVerify) -> Result<()> {
35        let url = "/device/confirm".to_string();
36        self.client
37            .post(&url, Some(reqwest::Body::from(serde_json::to_vec(body)?)))
38            .await
39    }
40
41    /**
42     * Request a device access token.
43     *
44     * This function performs a `POST` to the `/device/token` endpoint.
45     *
46     * This endpoint should be polled by the client until the user code is verified and the grant is confirmed.
47     */
48    pub async fn device_access_token(&self) -> Result<()> {
49        let url = "/device/token".to_string();
50        self.client.post(&url, None).await
51    }
52
53    /**
54     * This function performs a `POST` to the `/login` endpoint.
55     */
56    pub async fn spoof_login(&self, body: &crate::types::SpoofLoginBody) -> Result<()> {
57        let url = "/login".to_string();
58        self.client
59            .post(&url, Some(reqwest::Body::from(serde_json::to_vec(body)?)))
60            .await
61    }
62
63    /**
64     * This function performs a `POST` to the `/logout` endpoint.
65     */
66    pub async fn logout(&self) -> Result<()> {
67        let url = "/logout".to_string();
68        self.client.post(&url, None).await
69    }
70
71    /**
72     * Fetch the user associated with the current session.
73     *
74     * This function performs a `GET` to the `/session/me` endpoint.
75     */
76    pub async fn session_me(&self) -> Result<crate::types::User> {
77        let url = "/session/me".to_string();
78        self.client.get(&url, None).await
79    }
80}