Skip to content

Commit

Permalink
✨ Add debug route to list revoked tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
RemiBardon committed Aug 10, 2024
1 parent 8aa142a commit 34f4817
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/orangutan-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ enum Error {
UpdateContentError(#[from] update_content_routes::Error),
#[error("Unauthorized")]
Unauthorized,
#[error("Forbidden")]
Forbidden,
#[cfg(feature = "templating")]
#[error("Templating error: {0}")]
TemplatingError(#[from] templating::Error),
Expand Down
17 changes: 17 additions & 0 deletions src/orangutan-server/src/routes/debug_routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use chrono::{DateTime, Utc};
use lazy_static::lazy_static;
use rocket::{get, http::CookieJar, routes, Route};

use super::auth_routes::REVOKED_TOKENS;
use crate::{request_guards::Token, Error};

lazy_static! {
Expand All @@ -24,6 +25,7 @@ pub(super) fn routes() -> Vec<Route> {
get_user_info,
errors,
access_logs,
revoked_tokens,
];
#[cfg(feature = "token-generator")]
let routes = vec![routes, routes![
Expand Down Expand Up @@ -137,6 +139,21 @@ pub fn log_access(
})
}

#[get("/_revoked-tokens")]
fn revoked_tokens(token: Token) -> Result<String, Error> {
if !token.profiles().contains(&"*".to_owned()) {
Err(Error::Forbidden)?
}

let mut res = String::new();
for token in REVOKED_TOKENS.read().unwrap().iter() {
res.push_str(std::str::from_utf8(token).unwrap_or("<cannot parse>"));
res.push('\n');
}

Ok(res)
}

#[cfg(feature = "token-generator")]
pub mod token_generator {
use orangutan_refresh_token::RefreshToken;
Expand Down

0 comments on commit 34f4817

Please sign in to comment.