Fix: add FromRequestParts impl for security AuthenticatedUser extractor
All checks were successful
BotServer CI / build (push) Successful in 11m32s
All checks were successful
BotServer CI / build (push) Successful in 11m32s
This commit is contained in:
parent
49e9f419f3
commit
c0b619b58f
1 changed files with 22 additions and 0 deletions
|
|
@ -489,3 +489,25 @@ impl AuthenticatedUser {
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[axum::async_trait]
|
||||||
|
impl<S> axum::extract::FromRequestParts<S> for AuthenticatedUser
|
||||||
|
where
|
||||||
|
S: Send + Sync,
|
||||||
|
{
|
||||||
|
type Rejection = (axum::http::StatusCode, axum::Json<serde_json::Value>);
|
||||||
|
|
||||||
|
async fn from_request_parts(
|
||||||
|
parts: &mut axum::http::request::Parts,
|
||||||
|
_state: &S,
|
||||||
|
) -> Result<Self, Self::Rejection> {
|
||||||
|
parts
|
||||||
|
.extensions
|
||||||
|
.get::<AuthenticatedUser>()
|
||||||
|
.cloned()
|
||||||
|
.ok_or((
|
||||||
|
axum::http::StatusCode::UNAUTHORIZED,
|
||||||
|
axum::Json(serde_json::json!({"error": "Authentication required"})),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue