Improve auth

This commit is contained in:
Raphaël Thériault 2019-10-21 15:31:27 -04:00
parent 3ddff326f0
commit 967e8a30c6
1 changed files with 11 additions and 3 deletions

View File

@ -28,15 +28,23 @@ fn auth(
false => match request.headers().get("Authorization") {
Some(header) => match header.to_str() {
Ok(header) => {
let token: Vec<u8> = header.bytes().skip(7).collect();
let token = header.replace("Bearer ", "");
match setup::hash(&token).as_slice() == token_hash {
true => future::ok(()),
false => future::err(HttpResponse::Unauthorized().finish()),
false => future::err(
HttpResponse::Unauthorized()
.header("WWW-Authenticate", "Bearer")
.finish(),
),
}
}
Err(_) => future::err(HttpResponse::BadRequest().finish()),
},
None => future::err(HttpResponse::Unauthorized().finish()),
None => future::err(
HttpResponse::Unauthorized()
.header("WWW-Authenticate", "Bearer")
.finish(),
),
},
}
}