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)) Ok(Json(results))
} }
#[get("/token/info")]
pub fn token_info(tok: paseto::Token) -> Json<paseto::Token> {
Json(tok)
}
#[derive(serde::Serialize)] #[derive(serde::Serialize)]
pub struct FrontChange { pub struct FrontChange {
pub id: String, pub id: String,

View File

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

View File

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