mirror of
https://github.com/spacedriveapp/spacedrive
synced 2024-07-04 13:23:28 +00:00
parent
10df655fba
commit
d9b31a90b3
|
@ -29,19 +29,20 @@ async fn basic_auth<B>(
|
||||||
request: Request<B>,
|
request: Request<B>,
|
||||||
next: Next<B>,
|
next: Next<B>,
|
||||||
) -> Response {
|
) -> Response {
|
||||||
let (mut parts, body) = request.into_parts();
|
let request = if state.auth.len() != 0 {
|
||||||
let Ok(TypedHeader(Authorization(hdr))) =
|
let (mut parts, body) = request.into_parts();
|
||||||
TypedHeader::<Authorization<Basic>>::from_request_parts(&mut parts, &()).await
|
|
||||||
else {
|
let Ok(TypedHeader(Authorization(hdr))) =
|
||||||
return Response::builder()
|
TypedHeader::<Authorization<Basic>>::from_request_parts(&mut parts, &()).await
|
||||||
.status(401)
|
else {
|
||||||
.header("WWW-Authenticate", "Basic realm=\"Spacedrive\"")
|
return Response::builder()
|
||||||
.body("Unauthorized".into_response().into_body())
|
.status(401)
|
||||||
.expect("hardcoded response will be valid");
|
.header("WWW-Authenticate", "Basic realm=\"Spacedrive\"")
|
||||||
};
|
.body("Unauthorized".into_response().into_body())
|
||||||
let request = Request::from_parts(parts, body);
|
.expect("hardcoded response will be valid");
|
||||||
|
};
|
||||||
|
let request = Request::from_parts(parts, body);
|
||||||
|
|
||||||
if state.auth.len() != 0 {
|
|
||||||
if state
|
if state
|
||||||
.auth
|
.auth
|
||||||
.get(hdr.username())
|
.get(hdr.username())
|
||||||
|
@ -54,7 +55,11 @@ async fn basic_auth<B>(
|
||||||
.body("Unauthorized".into_response().into_body())
|
.body("Unauthorized".into_response().into_body())
|
||||||
.expect("hardcoded response will be valid");
|
.expect("hardcoded response will be valid");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
request
|
||||||
|
} else {
|
||||||
|
request
|
||||||
|
};
|
||||||
|
|
||||||
next.run(request).await
|
next.run(request).await
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue