diff options
| author | benj <benj@rse8.com> | 2022-12-29 00:09:27 -0800 |
|---|---|---|
| committer | benj <benj@rse8.com> | 2022-12-29 00:09:27 -0800 |
| commit | f0ea9ecd17b03605d747044874a26e1bd52c0ee1 (patch) | |
| tree | c42b94f530ab64dad19eecdfefc9aa53c08f3097 /crates | |
| parent | c2268c285648ef02ece04de0d9df0813c6d70ff8 (diff) | |
| download | secdiam-f0ea9ecd17b03605d747044874a26e1bd52c0ee1.tar secdiam-f0ea9ecd17b03605d747044874a26e1bd52c0ee1.tar.gz secdiam-f0ea9ecd17b03605d747044874a26e1bd52c0ee1.tar.bz2 secdiam-f0ea9ecd17b03605d747044874a26e1bd52c0ee1.tar.lz secdiam-f0ea9ecd17b03605d747044874a26e1bd52c0ee1.tar.xz secdiam-f0ea9ecd17b03605d747044874a26e1bd52c0ee1.tar.zst secdiam-f0ea9ecd17b03605d747044874a26e1bd52c0ee1.zip | |
revoke session (+ some cleanup)
Diffstat (limited to '')
| -rw-r--r-- | crates/secd/src/client/store/mod.rs | 7 | ||||
| -rw-r--r-- | crates/secd/src/command/authn.rs | 10 | ||||
| -rw-r--r-- | crates/secd/src/util/mod.rs | 1 | ||||
| -rw-r--r-- | crates/secd/store/pg/sql/write_session.sql | 3 | ||||
| -rw-r--r-- | crates/secd/store/sqlite/sql/write_session.sql | 3 |
5 files changed, 13 insertions, 11 deletions
diff --git a/crates/secd/src/client/store/mod.rs b/crates/secd/src/client/store/mod.rs index b93fd84..8a076c4 100644 --- a/crates/secd/src/client/store/mod.rs +++ b/crates/secd/src/client/store/mod.rs @@ -1,15 +1,10 @@ pub(crate) mod sql_db; -use email_address::EmailAddress; use sqlx::{Postgres, Sqlite}; use std::sync::Arc; -use time::OffsetDateTime; use uuid::Uuid; -use crate::{ - util, Address, AddressType, AddressValidation, Identity, IdentityId, PhoneNumber, Session, - SessionToken, -}; +use crate::{util, Address, AddressType, AddressValidation, Identity, IdentityId, Session}; use self::sql_db::SqlClient; diff --git a/crates/secd/src/command/authn.rs b/crates/secd/src/command/authn.rs index 5590e8c..1d3b2d5 100644 --- a/crates/secd/src/command/authn.rs +++ b/crates/secd/src/command/authn.rs @@ -8,8 +8,8 @@ use crate::{ }, }, util, Address, AddressType, AddressValidation, AddressValidationId, AddressValidationMethod, - Credential, CredentialType, Identity, IdentityId, PhoneNumber, Secd, SecdError, Session, - SessionToken, ADDRESSS_VALIDATION_CODE_SIZE, ADDRESS_VALIDATION_ALLOWS_ATTEMPTS, + Credential, CredentialType, Identity, PhoneNumber, Secd, SecdError, Session, SessionToken, + ADDRESSS_VALIDATION_CODE_SIZE, ADDRESS_VALIDATION_ALLOWS_ATTEMPTS, ADDRESS_VALIDATION_IDENTITY_SURJECTION, EMAIL_VALIDATION_DURATION, }; use email_address::EmailAddress; @@ -278,4 +278,10 @@ impl Secd { Ok(i.swap_remove(0)) } } + + pub async fn revoke_session(&self, session: &mut Session) -> Result<(), SecdError> { + session.revoked_at = Some(OffsetDateTime::now_utc()); + session.write(self.store.clone()).await?; + Ok(()) + } } diff --git a/crates/secd/src/util/mod.rs b/crates/secd/src/util/mod.rs index 6677c2f..c26986d 100644 --- a/crates/secd/src/util/mod.rs +++ b/crates/secd/src/util/mod.rs @@ -1,6 +1,5 @@ pub(crate) mod from; -use rand::distributions::Alphanumeric; use rand::{thread_rng, Rng}; use sha2::{Digest, Sha256}; use time::OffsetDateTime; diff --git a/crates/secd/store/pg/sql/write_session.sql b/crates/secd/store/pg/sql/write_session.sql index 18dc1f1..aa9c0a1 100644 --- a/crates/secd/store/pg/sql/write_session.sql +++ b/crates/secd/store/pg/sql/write_session.sql @@ -7,4 +7,5 @@ insert into secd.session ( ) values ( (select identity_id from secd.identity where identity_public_id = $1) , $2, $3, $4, $5 -); +) on conflict (token_hash) do update + set revoked_at = excluded.revoked_at; diff --git a/crates/secd/store/sqlite/sql/write_session.sql b/crates/secd/store/sqlite/sql/write_session.sql index 4679912..9ffb105 100644 --- a/crates/secd/store/sqlite/sql/write_session.sql +++ b/crates/secd/store/sqlite/sql/write_session.sql @@ -7,4 +7,5 @@ insert into session ( ) values ( (select identity_id from identity where identity_public_id = $1) , $2, $3, $4, $5 -); +) on conflict (token_hash) do update + set revoked_at = excluded.revoked_at; |
