Skip to content
This repository was archived by the owner on Jan 2, 2026. It is now read-only.

Commit 9035fd8

Browse files
author
bitfl0wer
committed
feat(squashme): getting closer to token-based auth!
1 parent 5c63798 commit 9035fd8

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/api/middlewares/mod.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,24 @@ impl<E: Endpoint> Endpoint for AuthenticationMiddlewareImpl<E> {
3131

3232
let token_store = req.data::<TokenStore>().unwrap();
3333
let hashed_user_token = hash_auth_token(auth);
34+
// We first get the serial_number of the cert that this token is associated with...
35+
let user_serial_number = token_store
36+
.get_token_serial_number(&hashed_user_token)
37+
.await
38+
.map_err(|_| poem::error::Error::from_status(StatusCode::INTERNAL_SERVER_ERROR))?
39+
.ok_or(poem::error::Error::from_status(StatusCode::UNAUTHORIZED))?;
40+
// ...then we check, if this token has not been invalidated
41+
let valid_token_in_db_for_user = token_store
42+
.get_token_userid(&user_serial_number)
43+
.await
44+
.map_err(|_| poem::error::Error::from_status(StatusCode::INTERNAL_SERVER_ERROR))?
45+
.ok_or(poem::error::Error::from_status(StatusCode::UNAUTHORIZED))?;
46+
// And then we compare the two!
47+
if valid_token_in_db_for_user.token == hashed_user_token.into() {
48+
// TODO: Get actor uaid, set in request
49+
} else {
50+
return Err(poem::error::Error::from_status(StatusCode::UNAUTHORIZED));
51+
}
3452

3553
self.ep.call(req).await
3654
}

0 commit comments

Comments
 (0)