pub enum StateGuard {
Session(SessionState),
Sealed(SealedState),
}Expand description
Issues the state, and checks it when the visitor comes back.
Both modes bind the PKCE verifier to the state, so recovering one recovers the other and a caller cannot accidentally exchange a code against a verifier from a different flow.
Variants§
Session(SessionState)
The state is a random nonce; the nonce and the verifier live in the session. Prefer this: the entry is deleted when it is checked, so a state works exactly once.
Sealed(SealedState)
The state is sealed with a key derived from APP_KEY and carries the
verifier and its own issue time. Nothing is stored server-side, which is
what a fleet with no shared session store needs.
Implementations§
Source§impl StateGuard
impl StateGuard
Sourcepub fn session(session: &SessionHandle) -> StateGuard
pub fn session(session: &SessionHandle) -> StateGuard
The stateful mode, on the request’s session.
Sourcepub fn sealed(key: &AppKey) -> StateGuard
pub fn sealed(key: &AppKey) -> StateGuard
The stateless mode, keyed off the application key.
Sourcepub fn issue(&self, pkce: &Pkce) -> Result<String, OAuthError>
pub fn issue(&self, pkce: &Pkce) -> Result<String, OAuthError>
A fresh state committing to pkce.
Sourcepub fn verify(&self, presented: Option<&str>) -> Result<Pkce, StateError>
pub fn verify(&self, presented: Option<&str>) -> Result<Pkce, StateError>
Check what came back, and recover the verifier it was issued with.
None is the missing case rather than an error the caller has to spell
out, because “the query string had no state” is the most common shape
of the attack and must not be reachable by forgetting a check.
Sourcepub fn lifetime(self, lifetime: Duration) -> StateGuard
pub fn lifetime(self, lifetime: Duration) -> StateGuard
How long an issued state stays valid.