Skip to main content

uptrakit_openapi_client/
oauth_clients.rs

1//! Operator OAuth client management (`/api/oauth/clients`).
2
3use crate::Result;
4use crate::UptrakitClient;
5use crate::types_impl::oauth::{
6    DcrRegistrationRequest, DcrRegistrationResponse, OAuthClientResponse,
7};
8use crate::types_impl::pagination::{PaginatedResponse, PaginationParams};
9
10impl UptrakitClient {
11    /// List registered OAuth clients (paginated, newest first).
12    pub async fn list_clients(
13        &self,
14        params: &PaginationParams,
15    ) -> Result<PaginatedResponse<OAuthClientResponse>> {
16        self.get_with_query(crate::paths::oauth::CLIENTS, params)
17            .await
18    }
19
20    /// Manually register an OAuth client (operator, RFC 7591 shape).
21    ///
22    /// The response carries a one-time `registration_access_token` — never
23    /// log or `Debug`-format it.
24    pub async fn manual_register_client(
25        &self,
26        req: &DcrRegistrationRequest,
27    ) -> Result<DcrRegistrationResponse> {
28        self.post_json(crate::paths::oauth::CLIENTS, req).await
29    }
30
31    /// Revoke an OAuth client (cascades to its consents and refresh tokens).
32    pub async fn revoke_client(&self, client_id: &str) -> Result<()> {
33        self.delete(&crate::paths::oauth::client_by_id(client_id))
34            .await
35    }
36
37    /// Promote an OAuth client to trusted.
38    pub async fn trust_client(&self, client_id: &str) -> Result<()> {
39        self.post_empty_no_content(&crate::paths::oauth::client_trust(client_id))
40            .await
41    }
42}
43
44#[cfg(test)]
45mod tests {
46    #[test]
47    fn client_by_id_encodes_url_shaped_ids() {
48        let path = crate::paths::oauth::client_by_id("https://example.com/client.json");
49        let rest = path
50            .strip_prefix("/api/oauth/clients/")
51            .expect("path must start with the clients prefix");
52        assert!(
53            !rest.contains('/'),
54            "encoded id must be a single path segment: {path}"
55        );
56    }
57}