scufflecloud_video_api/middleware/
auth.rs

1use axum::{extract::Request, http::StatusCode, middleware::Next, response::Response};
2
3#[derive(Clone, Debug)]
4pub(crate) enum Authentication {
5    Internal,
6    External,
7}
8
9pub(crate) async fn auth<G: video_api_traits::Global>(mut req: Request, next: Next) -> Result<Response, StatusCode> {
10    let tls_client_identity: Option<&scuffle_http::extensions::ClientIdentity> = req.extensions().get();
11
12    if tls_client_identity.is_some() {
13        req.extensions_mut()
14            .insert(Authentication::Internal);
15    } else {
16        req.extensions_mut()
17            .insert(Authentication::External);
18    }
19
20    Ok(next.run(req).await)
21}