aboutsummaryrefslogtreecommitdiffstats
path: root/src/auth.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/auth.rs')
-rw-r--r--src/auth.rs31
1 files changed, 5 insertions, 26 deletions
diff --git a/src/auth.rs b/src/auth.rs
index ced9e8e..03930f0 100644
--- a/src/auth.rs
+++ b/src/auth.rs
@@ -63,29 +63,10 @@ struct Claims {
63 puk: String, 63 puk: String,
64} 64}
65 65
66// #[derive(Error, Debug)] 66#[derive(Debug)]
67// pub enum Nope { 67struct RateLimited;
68// #[error("Invalid header")]
69// InvalidHeader {
70// expected: String,
71// found: String,
72// },
73// }
74// impl warp::reject::Reject for Nope {}
75 68
76#[derive(Error, Debug)] 69impl Reject for RateLimited {}
77pub enum DataStoreError {
78 #[error("invalid header")]
79 InvalidHeader {},
80}
81
82impl Reject for DataStoreError {}
83
84// impl From<LessThanTenError> for Rejection {
85// fn from(other: LessThanTenError) -> Self {
86// warp::reject::custom(other)
87// }
88// }
89 70
90pub fn with_auth( 71pub fn with_auth(
91 db: Db, 72 db: Db,
@@ -94,10 +75,9 @@ pub fn with_auth(
94 headers_cloned() 75 headers_cloned()
95 .map(move |headers: HeaderMap<HeaderValue>| (db.clone(), headers)) 76 .map(move |headers: HeaderMap<HeaderValue>| (db.clone(), headers))
96 .and_then(authorize) 77 .and_then(authorize)
97 .recover(handle_rejection())
98} 78}
99 79
100async fn authorize((db, headers): (Db, HeaderMap<HeaderValue>)) -> Result<String, Infallible> { 80async fn authorize((db, headers): (Db, HeaderMap<HeaderValue>)) -> Result<String, Rejection> {
101 match jwt_from_header(&headers) { 81 match jwt_from_header(&headers) {
102 Ok(jwt) => { 82 Ok(jwt) => {
103 let decoded = decode::<Claims>( 83 let decoded = decode::<Claims>(
@@ -111,8 +91,7 @@ async fn authorize((db, headers): (Db, HeaderMap<HeaderValue>)) -> Result<String
111 91
112 Ok(decoded.claims.puk) 92 Ok(decoded.claims.puk)
113 } 93 }
114 Err(e) => return (StatusCode::UNAUTHORIZED, e.to_string()), 94 Err(e) => return Err(warp::reject::custom(RateLimited)),
115 // warp error
116 } 95 }
117} 96}
118 97