manta_shared/types/auth.rs
1//! Wire types for the `POST /api/v1/auth/{token,validate}` endpoints.
2//!
3//! Carried over the wire by both `manta-cli` (sending requests via
4//! `MantaClient`) and `manta-server` (deserializing them in handlers).
5
6use serde::{Deserialize, Serialize};
7use utoipa::ToSchema;
8
9/// Request body for `POST /api/v1/auth/token`.
10///
11/// Paired with [`AuthTokenResponse`] on success. The `/auth/*`
12/// sub-router is wrapped by `strip_body_for_logs`, so neither the
13/// request body nor the issued token appears in access logs.
14///
15/// # Wire shape
16///
17/// ```json
18/// { "username": "alice", "password": "hunter2" }
19/// ```
20#[derive(Debug, Deserialize, Serialize, ToSchema)]
21pub struct AuthTokenRequest {
22 /// Keycloak username submitted to the configured backend.
23 pub username: String,
24 /// Keycloak password. Never logged by the server (the
25 /// `/auth/*` sub-router is wrapped by `strip_body_for_logs`).
26 pub password: String,
27}
28
29/// Response body for `POST /api/v1/auth/token`.
30///
31/// Returned in exchange for a valid [`AuthTokenRequest`].
32///
33/// # Wire shape
34///
35/// ```json
36/// { "token": "eyJhbGciOi..." }
37/// ```
38#[derive(Debug, Deserialize, Serialize, ToSchema)]
39pub struct AuthTokenResponse {
40 /// Bearer token issued by the backend (CSM or OpenCHAMI Keycloak).
41 /// Pass this as `Authorization: Bearer <token>` on every
42 /// subsequent request.
43 pub token: String,
44}
45
46/// Request body for `POST /api/v1/auth/validate`.
47///
48/// Used to check a previously-issued [`AuthTokenResponse::token`]
49/// before relying on it. The server returns `200 OK` for a valid
50/// token and `401` otherwise — there is no dedicated response body.
51#[derive(Debug, Deserialize, Serialize, ToSchema)]
52pub struct ValidateTokenRequest {
53 /// Bearer token to validate against the backend.
54 pub token: String,
55}