paperless_api_client/
oauth.rs

1use crate::Client;
2use anyhow::Result;
3#[derive(Clone, Debug)]
4pub struct Oauth {
5    pub client: Client,
6}
7
8impl Oauth {
9    #[doc(hidden)]
10    pub fn new(client: Client) -> Self {
11        Self { client }
12    }
13
14    #[doc = "Perform a `GET` request to `/api/oauth/callback/`.\n\nCallback view for OAuth2 authentication\n\n```rust,no_run\nasync fn example_oauth_callback_retrieve() -> anyhow::Result<()> {\n    let client = paperless_api_client::Client::new_from_env();\n    client.oauth().callback_retrieve().await?;\n    Ok(())\n}\n```"]
15    #[tracing::instrument]
16    #[allow(non_snake_case)]
17    pub async fn callback_retrieve<'a>(&'a self) -> Result<(), crate::types::error::Error> {
18        let mut req = self.client.client.request(
19            http::Method::GET,
20            format!("{}/{}", self.client.base_url, "api/oauth/callback/"),
21        );
22        req = req.header("Authorization", format!("Token {}", &self.client.token));
23        let resp = req.send().await?;
24        let status = resp.status();
25        if status.is_success() {
26            Ok(())
27        } else {
28            let text = resp.text().await.unwrap_or_default();
29            Err(crate::types::error::Error::Server {
30                body: text.to_string(),
31                status,
32            })
33        }
34    }
35}