log paseto ids

This commit is contained in:
Cadey Ratio 2020-11-04 07:09:41 -05:00
parent b241a3ebd1
commit 5da977443d
3 changed files with 13 additions and 7 deletions

View File

@ -25,6 +25,11 @@ pub fn get_members(tok: paseto::Token, conn: MainDatabase) -> Result<Json<Vec<mo
Ok(Json(results))
}
#[get("/token/info")]
pub fn token_info(tok: paseto::Token) -> Json<paseto::Token> {
Json(tok)
}
#[derive(serde::Serialize)]
pub struct FrontChange {
pub id: String,

View File

@ -54,7 +54,8 @@ fn main() -> Result<()> {
api::get_switches,
api::get_switch,
api::get_current_front,
api::make_switch
api::make_switch,
api::token_info
],
)
.launch();

View File

@ -31,19 +31,18 @@ pub fn ed25519_keypair() -> AdHoc {
.unwrap();
debug!("token: {}", token);
Ok(rocket
.manage(Ed25519KeyPair::from_seed_and_public_key(&private, &public).unwrap())
.manage(PasetoPublicKey::ED25519KeyPair(
Ok(rocket.manage(PasetoPublicKey::ED25519KeyPair(
Ed25519KeyPair::from_seed_and_public_key(&private, &public).unwrap(),
)))
})
}
#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Serialize)]
pub struct Token {
pub jti: String,
pub sub: String,
pub aud: String,
pub iss: String,
}
impl<'a, 'r> FromRequest<'a, 'r> for Token {
@ -59,6 +58,7 @@ impl<'a, 'r> FromRequest<'a, 'r> for Token {
match validate_public_token(tok, None, &paseto_key) {
Ok(val) => {
let tok: Token = serde_json::from_value(val).unwrap();
info!(id = &tok.jti[..], "token used");
Outcome::Success(tok)
}
Err(why) => {