1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//! Scoped access-token management DTOs.
//!
//! Request/response shapes for the token-management API, which mints
//! scoped, time-boxed bearer tokens (e.g. for CI runners / least-privilege
//! automation). The raw JWT is returned exactly once, in
//! [`CreateTokenResponse::token`].
use serde::{Deserialize, Serialize};
use crate::storage::TokenScope;
/// Request body for minting a scoped access token.
#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)]
pub struct CreateTokenRequest {
/// Human-friendly label for the token (e.g. `"ci-runner"`).
pub name: String,
/// Scopes to bake into the token. The caller may only request scopes that
/// fall within their own authority.
#[serde(default)]
pub scopes: Vec<TokenScope>,
/// Role claims to carry on the token. Only admins may request privileged
/// roles (`admin`/`operator`); for least-privilege tokens this is empty.
#[serde(default)]
pub roles: Vec<String>,
/// Time-to-live in seconds. Defaults to 1h and is hard-capped at 365d.
#[serde(default)]
pub ttl_secs: Option<u64>,
}
/// Response returned once at token creation.
///
/// The `token` field is the raw JWT and is never persisted nor returned again.
#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)]
pub struct CreateTokenResponse {
/// UUID identifier — also the JWT `jti` claim (the revocation handle).
pub id: String,
/// The raw JWT bearer token. Shown only once; store it securely.
pub token: String,
/// The human-friendly label echoed back from the request.
pub name: String,
/// The scopes baked into the token.
pub scopes: Vec<TokenScope>,
/// When the token expires.
#[schema(value_type = String, example = "2026-04-15T12:00:00Z")]
pub expires_at: chrono::DateTime<chrono::Utc>,
}