Skip to main content

quantum_sdk/
auth.rs

1//! Authentication — sign in via OAuth providers.
2
3use serde::{Deserialize, Serialize};
4
5use crate::client::Client;
6use crate::error::Result;
7
8/// User information returned after authentication.
9#[derive(Debug, Clone, Deserialize)]
10pub struct AuthUser {
11    /// User identifier.
12    pub id: String,
13
14    /// Display name.
15    #[serde(default)]
16    pub name: Option<String>,
17
18    /// Email address.
19    #[serde(default)]
20    pub email: Option<String>,
21
22    /// Avatar URL.
23    #[serde(default)]
24    pub avatar_url: Option<String>,
25}
26
27/// Response from authentication endpoints.
28#[derive(Debug, Clone, Deserialize)]
29pub struct AuthResponse {
30    /// API token for subsequent requests.
31    pub token: String,
32
33    /// Authenticated user information.
34    pub user: AuthUser,
35}
36
37/// Request body for Apple Sign-In.
38#[derive(Debug, Clone, Serialize)]
39pub struct AuthAppleRequest {
40    /// The Apple identity token (JWT from Sign in with Apple).
41    pub id_token: String,
42
43    /// Optional display name (only provided on first sign-in).
44    #[serde(skip_serializing_if = "Option::is_none")]
45    pub name: Option<String>,
46}
47
48impl Client {
49    /// Authenticate with Apple Sign-In.
50    ///
51    /// The `id_token` is the JWT received from the Sign in with Apple flow.
52    /// On first sign-in, pass the user's `name` so the account is created
53    /// with a display name.
54    pub async fn auth_apple(&self, req: &AuthAppleRequest) -> Result<AuthResponse> {
55        let (resp, _meta) = self
56            .post_json::<AuthAppleRequest, AuthResponse>("/qai/v1/auth/apple", req)
57            .await?;
58        Ok(resp)
59    }
60}