diff options
author | niliara-edu <nil.jimeno@estudiant.fjaverianas.com> | 2025-01-25 13:30:27 +0100 |
---|---|---|
committer | niliara-edu <nil.jimeno@estudiant.fjaverianas.com> | 2025-01-25 13:30:27 +0100 |
commit | ef604ccb6e86b77517a78547bb50cdf9b82e03f0 (patch) | |
tree | af490a61546a38ad1fbb40e43e985cc6ff82fd34 /src/extractors | |
parent | c2786c4b9d704128da80ce4ed6513b9f5507b680 (diff) |
add required authentication
Diffstat (limited to 'src/extractors')
-rw-r--r-- | src/extractors/auth_token.rs | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/extractors/auth_token.rs b/src/extractors/auth_token.rs index c505fdf..6ad2a45 100644 --- a/src/extractors/auth_token.rs +++ b/src/extractors/auth_token.rs @@ -16,8 +16,12 @@ impl FromRequest for AuthenticationToken { fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future { // get auth token from the authorization header - let auth_header: Option<&HeaderValue> = req.headers().get(http::header::AUTHORIZATION); - let auth_token: String = auth_header.unwrap().to_str().unwrap_or("").to_string(); // check errors later + let auth_header: &HeaderValue = match req.headers().get(http::header::AUTHORIZATION) { + Some(res) => res, + None => { return ready(Err(ErrorUnauthorized("No authorization token given")))}, + }; + + let auth_token: String = auth_header.to_str().unwrap_or("").to_string(); // check errors later // stop empty and weird (ascii, chinese...) auth_token strings: if auth_token.is_empty() { return ready(Err(ErrorUnauthorized("Invalid auth token!")))} let secret: String = req.app_data::<web::Data<AppState>>().unwrap().secret.to_string(); |