pub struct FormTokenManager<TS, K, C, A> { /* private fields */ }Expand description
Manages form-token issuance and consumption (RFC-013 §3).
Implementations§
Source§impl<TS, K, C, A> FormTokenManager<TS, K, C, A>
impl<TS, K, C, A> FormTokenManager<TS, K, C, A>
Sourcepub fn new(
store: TS,
hasher: SecretHasher<K>,
clock: C,
audit: A,
ttl: Duration,
) -> Self
pub fn new( store: TS, hasher: SecretHasher<K>, clock: C, audit: A, ttl: Duration, ) -> Self
Construct a form-token manager with the given token TTL.
A TTL of one hour matches the source service’s FORM_TOKEN_TTL_SECONDS.
Sourcepub async fn issue<R: RandomSource>(
&self,
rng: &mut R,
subject: TokenSubject,
purpose: impl Into<String>,
bound_resource: Option<String>,
) -> Result<FormTokenSecret, FormTokenError>
pub async fn issue<R: RandomSource>( &self, rng: &mut R, subject: TokenSubject, purpose: impl Into<String>, bound_resource: Option<String>, ) -> Result<FormTokenSecret, FormTokenError>
Issue a new form token for subject and purpose.
Returns a FormTokenSecret (plaintext) to embed in the form or
a short-lived cookie. The secret is never persisted; only its HMAC
lookup key is stored (INV-1).
§Errors
Returns FormTokenError::Internal on RNG, hasher, or store failure.
Sourcepub async fn consume(
&self,
raw_token: &str,
subject: &TokenSubject,
purpose: &str,
bound_resource: Option<&str>,
) -> Result<Option<String>, FormTokenError>
pub async fn consume( &self, raw_token: &str, subject: &TokenSubject, purpose: &str, bound_resource: Option<&str>, ) -> Result<Option<String>, FormTokenError>
Consume a form token submitted by the client.
Returns Ok(None) on Proceed (first winner), Ok(Some(result_ref))
on Replay (idempotent second submit), or FormTokenError::Invalid
on any rejection.
Emits CodeAuthEvent::FormTokenReplay on replay.
§Errors
Returns FormTokenError::Invalid when the token is not accepted.
Returns FormTokenError::Internal on store/key failure.
Sourcepub async fn set_result(
&self,
raw_token: &str,
result_ref: &str,
) -> Result<(), FormTokenError>
pub async fn set_result( &self, raw_token: &str, result_ref: &str, ) -> Result<(), FormTokenError>
Store a result reference on a consumed token for idempotency replay.
§Errors
Returns FormTokenError::Internal on store failure.