diff options
| author | Owen Jacobson <owen@grimoire.ca> | 2024-09-11 21:52:57 -0400 |
|---|---|---|
| committer | Owen Jacobson <owen@grimoire.ca> | 2024-09-11 21:54:57 -0400 |
| commit | b16742b0e782bc795fa748d46c3eb6438fb19adc (patch) | |
| tree | 4e31515c57cc896fcdca953c73d62828ac303d1e /src/login/extract/login.rs | |
| parent | 4563f221bf61123b15f9608bb14e8f46db05e4f6 (diff) | |
Expire tokens based on when they were last used, not based on when they were issued.
This lets us shorten the expiry interval - by quite a bit. Tokens in regular use will now live indefinitely, while tokens that go unused for _one week_ will be invalidated and deleted. This will reduce the number of "dead" tokens (still valid, but _de facto_ no longer in use) stored in the table, and limit the exposure period if a token is leaked and then not used immediately.
It's also much less likely to produce surprise logouts three months after installation. You'll either stay logged in, or have to log in again much, much sooner, making it feel a lot more regular and less surprising.
Diffstat (limited to 'src/login/extract/login.rs')
| -rw-r--r-- | src/login/extract/login.rs | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/login/extract/login.rs b/src/login/extract/login.rs index b756fa6..405aea8 100644 --- a/src/login/extract/login.rs +++ b/src/login/extract/login.rs @@ -27,14 +27,14 @@ impl FromRequestParts<SqlitePool> for Login { // // let Ok(identity_token) = IdentityToken::from_request_parts(parts, state).await; let identity_token = IdentityToken::from_request_parts(parts, state).await?; - let requested_at = RequestedAt::from_request_parts(parts, state).await?; + let RequestedAt(requested_at) = RequestedAt::from_request_parts(parts, state).await?; let token = identity_token.token().ok_or(LoginError::Forbidden)?; let db = State::<SqlitePool>::from_request_parts(parts, state).await?; let mut tx = db.begin().await?; - tx.tokens().expire(requested_at.timestamp()).await?; - let login = tx.tokens().validate(token).await?; + tx.tokens().expire(requested_at).await?; + let login = tx.tokens().validate(token, requested_at).await?; tx.commit().await?; login.ok_or(LoginError::Forbidden) |
