fix auth bug

This commit is contained in:
Bevan Hunt 2020-01-06 03:00:44 -08:00
parent 67ac28aa8f
commit 008d328349
3 changed files with 15 additions and 9 deletions

2
Cargo.lock generated
View File

@ -386,7 +386,7 @@ dependencies = [
[[package]]
name = "broker"
version = "0.4.1"
version = "0.4.2"
dependencies = [
"actix-cors 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"actix-rt 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",

View File

@ -1,6 +1,6 @@
[package]
name = "broker"
version = "0.4.1"
version = "0.4.2"
authors = ["Bevan Hunt <bevan@bevanhunt.com>"]
edition = "2018"
license = "MIT"

View File

@ -77,14 +77,16 @@ async fn collection(data: web::Data<MyData>, path: web::Path<Path>, req: HttpReq
for part in parts {
if part != "Bearer" {
let _ = match decode::<Claims>(&part, secret.as_ref(), &Validation::default()) {
Ok(c) => c,
Ok(c) => {
check = check + 1;
c
},
Err(err) => match *err.kind() {
_ => return Ok(HttpResponse::Unauthorized().json(""))
},
};
}
}
check = check + 1;
}
}
@ -167,14 +169,16 @@ async fn insert(data: web::Data<MyData>, json: web::Json<JSON>, req: HttpRequest
for part in parts {
if part != "Bearer" {
let _ = match decode::<Claims>(&part, secret.as_ref(), &Validation::default()) {
Ok(c) => c,
Ok(c) => {
check = check + 1;
c
},
Err(err) => match *err.kind() {
_ => return Ok(HttpResponse::Unauthorized().json(""))
},
};
}
}
check = check + 1;
}
}
@ -214,17 +218,19 @@ async fn cancel(data: web::Data<MyData>, path: web::Path<Path>, req: HttpRequest
for part in parts {
if part != "Bearer" {
let _ = match decode::<Claims>(&part, secret.as_ref(), &Validation::default()) {
Ok(c) => c,
Ok(c) => {
check = check + 1;
c
},
Err(err) => match *err.kind() {
_ => return Ok(HttpResponse::Unauthorized().json(""))
},
};
}
}
check = check + 1;
}
}
// if no auth header
if check == 0 {
return Ok(HttpResponse::Unauthorized().json(""))