Skip to main content

fastauth_plugin_jwt/
model.rs

1//! The `jwks` table.
2
3use fastauth_core::plugin_prelude::*;
4
5/// A row of `jwks`: one signing key pair. The public half is a JWK as JSON; the private half
6/// is a PKCS#8 key encrypted with the app secret (XChaCha20-Poly1305 under a key derived
7/// from it), so a database dump alone can't mint tokens.
8#[derive(Model, Clone)]
9#[model(table = "jwks")]
10pub struct JsonWebKey {
11    /// Also the `kid` of the key and of every token it signs.
12    #[model(id)]
13    pub id: Id,
14    /// The public JWK, as JSON: `{"kty":"OKP","crv":"Ed25519","x":"..."}`.
15    pub public_key: String,
16    /// The encrypted private key, base64url.
17    #[model(hidden)]
18    pub private_key: String,
19    #[model(default = now)]
20    pub created_at: OffsetDateTime,
21    /// After this the key no longer signs; the JWKS keeps listing it for the grace period.
22    pub expires_at: Option<OffsetDateTime>,
23    /// `EdDSA`, `ES256` or `RS256`.
24    pub alg: Option<String>,
25    /// `Ed25519` or `P-256`; none for RSA.
26    pub crv: Option<String>,
27}
28
29impl std::fmt::Debug for JsonWebKey {
30    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
31        f.debug_struct("JsonWebKey")
32            .field("id", &self.id)
33            .field("alg", &self.alg)
34            .field("created_at", &self.created_at)
35            .field("expires_at", &self.expires_at)
36            .finish_non_exhaustive()
37    }
38}