pub struct JwtConfig { /* private fields */ }Expand description
Cheap-to-clone JWT configuration. Wrap with Arc internally so all
clones share the same active-key + history view.
Implementations§
Source§impl JwtConfig
impl JwtConfig
Sourcepub fn new(issuer: String, audience: Vec<String>) -> Self
pub fn new(issuer: String, audience: Vec<String>) -> Self
Empty configuration — no keys yet. Caller must populate via
JwtConfig::load_from_postgres / JwtConfig::load_from_sqlite
or JwtConfig::set_active before issuing tokens.
Sourcepub fn set_active(&self, active: ActiveKey, history: Vec<HistoryKey>)
pub fn set_active(&self, active: ActiveKey, history: Vec<HistoryKey>)
Replace the in-memory active key + history. Useful in tests where we want a single ephemeral keypair without round-tripping the DB.
Sourcepub fn issue<T: Serialize>(&self, claims: &T) -> Result<String>
pub fn issue<T: Serialize>(&self, claims: &T) -> Result<String>
Sign claims with the active key. The active key’s kid is
written into the JWT header so verify can look it up.
Sourcepub fn verify<T: DeserializeOwned>(&self, token: &str) -> Result<TokenData<T>>
pub fn verify<T: DeserializeOwned>(&self, token: &str) -> Result<TokenData<T>>
Verify token and decode its claims. Looks up the decoding key
by header kid (active first, then history), validates iss and
the audience list against the in-memory configuration.
Sourcepub fn active_kid(&self) -> Option<String>
pub fn active_kid(&self) -> Option<String>
Borrow the active key’s kid (cheap clone). Useful in tests and
for telemetry.
Sourcepub fn issuer(&self) -> String
pub fn issuer(&self) -> String
Configured issuer string. Plan-locked: every JWT this config
signs must carry this iss claim. Useful for downstream callers
(e.g. the BW-compat shim in assay-vault) that mint their own
claim shapes but still need verify to accept the token.
Sourcepub async fn load_from_postgres(&self, pool: &PgPool) -> Result<()>
pub async fn load_from_postgres(&self, pool: &PgPool) -> Result<()>
Load every key from auth.jwks_keys into memory. The row with
rotated_at IS NULL becomes active; the rest become history.
private_pem_encrypted is treated as plaintext PEM for now —
encryption-at-rest is a later phase.
Sourcepub async fn load_from_sqlite(&self, pool: &SqlitePool) -> Result<()>
pub async fn load_from_sqlite(&self, pool: &SqlitePool) -> Result<()>
SQLite mirror of JwtConfig::load_from_postgres.
Sourcepub async fn rotate_postgres(&self, pool: &PgPool) -> Result<String>
pub async fn rotate_postgres(&self, pool: &PgPool) -> Result<String>
Generate a fresh Ed25519 keypair, INSERT it into auth.jwks_keys
as the new active row, mark the prior active row rotated, and
swap the in-memory state. Returns the new kid.
Sourcepub async fn rotate_sqlite(&self, pool: &SqlitePool) -> Result<String>
pub async fn rotate_sqlite(&self, pool: &SqlitePool) -> Result<String>
SQLite mirror of JwtConfig::rotate_postgres.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for JwtConfig
impl !RefUnwindSafe for JwtConfig
impl Send for JwtConfig
impl Sync for JwtConfig
impl Unpin for JwtConfig
impl UnsafeUnpin for JwtConfig
impl !UnwindSafe for JwtConfig
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more