feat: use custom middleware for authorization
All checks were successful
ci/woodpecker/push/build-and-publish Pipeline was successful
All checks were successful
ci/woodpecker/push/build-and-publish Pipeline was successful
This commit is contained in:
parent
dada230e08
commit
1ad88725bd
24 changed files with 157 additions and 365 deletions
|
@ -2,19 +2,12 @@ use std::sync::Arc;
|
|||
|
||||
use ::uuid::Uuid;
|
||||
use axum::{
|
||||
Json,
|
||||
extract::{Path, State},
|
||||
http::StatusCode,
|
||||
response::IntoResponse,
|
||||
};
|
||||
use axum_extra::{
|
||||
TypedHeader,
|
||||
headers::{Authorization, authorization::Bearer},
|
||||
extract::{Path, State}, http::StatusCode, response::IntoResponse, Extension, Json
|
||||
};
|
||||
|
||||
use crate::{
|
||||
AppState,
|
||||
api::v1::auth::check_access_token,
|
||||
api::v1::auth::CurrentUser,
|
||||
error::Error,
|
||||
objects::{Member, Role},
|
||||
utils::global_checks,
|
||||
|
@ -23,14 +16,12 @@ use crate::{
|
|||
pub async fn get(
|
||||
State(app_state): State<Arc<AppState>>,
|
||||
Path((guild_uuid, role_uuid)): Path<(Uuid, Uuid)>,
|
||||
TypedHeader(auth): TypedHeader<Authorization<Bearer>>,
|
||||
Extension(CurrentUser(uuid)): Extension<CurrentUser<Uuid>>,
|
||||
) -> Result<impl IntoResponse, Error> {
|
||||
let mut conn = app_state.pool.get().await?;
|
||||
|
||||
let uuid = check_access_token(auth.token(), &mut conn).await?;
|
||||
|
||||
global_checks(&app_state, uuid).await?;
|
||||
|
||||
let mut conn = app_state.pool.get().await?;
|
||||
|
||||
Member::check_membership(&mut conn, uuid, guild_uuid).await?;
|
||||
|
||||
if let Ok(cache_hit) = app_state.get_cache_key(format!("{role_uuid}")).await {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue