Skip to main content

openapp_sdk_core/resources/
auth.rs

1//! `Auth` resource group.
2
3use std::sync::Arc;
4
5use reqwest::Method;
6
7use super::JsonValue;
8use crate::{
9    error::SdkError,
10    transport::{RequestSpec, Transport},
11};
12
13#[derive(Debug, Clone)]
14pub struct AuthClient {
15    transport: Arc<Transport>,
16}
17
18impl AuthClient {
19    pub(crate) fn new(transport: Arc<Transport>) -> Self {
20        Self { transport }
21    }
22
23    pub async fn whoami(&self) -> Result<JsonValue, SdkError> {
24        self.transport
25            .request_json::<(), JsonValue>(RequestSpec {
26                method: Method::GET,
27                path: "/auth/whoami",
28                ..Default::default()
29            })
30            .await
31    }
32
33    pub async fn session(&self) -> Result<JsonValue, SdkError> {
34        self.transport
35            .request_json::<(), JsonValue>(RequestSpec {
36                method: Method::GET,
37                path: "/auth/session",
38                ..Default::default()
39            })
40            .await
41    }
42
43    pub async fn kratos_identity(&self) -> Result<JsonValue, SdkError> {
44        self.transport
45            .request_json::<(), JsonValue>(RequestSpec {
46                method: Method::GET,
47                path: "/auth/kratos-identity",
48                ..Default::default()
49            })
50            .await
51    }
52
53    pub async fn provisioned(&self) -> Result<JsonValue, SdkError> {
54        self.transport
55            .request_json::<(), JsonValue>(RequestSpec {
56                method: Method::GET,
57                path: "/auth/provisioned",
58                ..Default::default()
59            })
60            .await
61    }
62
63    pub async fn logout(&self) -> Result<(), SdkError> {
64        self.transport
65            .request_json::<(), ()>(RequestSpec {
66                method: Method::POST,
67                path: "/auth/logout",
68                ..Default::default()
69            })
70            .await
71    }
72
73    pub async fn sign_out(&self) -> Result<(), SdkError> {
74        self.transport
75            .request_json::<(), ()>(RequestSpec {
76                method: Method::POST,
77                path: "/auth/sign-out",
78                ..Default::default()
79            })
80            .await
81    }
82}