Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow admin token as auth header #5240

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/api/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,34 @@ impl<'r> FromRequest<'r> for AdminToken {
ip,
})
} else {
let header_authorization = request.headers().get_one("authorization");
if let Some(access_token) = header_authorization {
if crate::ratelimit::check_limit_admin(&ip.ip).is_err() {
return Outcome::Error((Status::Unauthorized, "Too many requests, try again later."));
}

let access_token = access_token.trim_start_matches("Bearer").trim();
let access_token = data_encoding::BASE64.decode(access_token.as_bytes());
let access_token = match access_token {
Ok(a) => String::from_utf8(a),
Err(_) => {
return Outcome::Error((Status::Unauthorized, "Invalid admin token, please try again."));
}
};
let access_token = match access_token {
Ok(a) => a,
Err(_) => {
return Outcome::Error((Status::Unauthorized, "Invalid admin token, please try again."));
}
};
if !_validate_token(&access_token) {
error!("Invalid admin token. IP: {}", ip.ip);
return Outcome::Error((Status::Unauthorized, "Invalid admin token, please try again."));
}
return Outcome::Success(Self {
ip,
});
}
let cookies = request.cookies();

let access_token = match cookies.get(COOKIE_NAME) {
Expand Down
Loading