aboutsummaryrefslogtreecommitdiffstats
path: root/src/auth.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/auth.rs')
-rw-r--r--src/auth.rs17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/auth.rs b/src/auth.rs
index 03930f0..65d639b 100644
--- a/src/auth.rs
+++ b/src/auth.rs
@@ -66,18 +66,25 @@ struct Claims {
66#[derive(Debug)] 66#[derive(Debug)]
67struct RateLimited; 67struct RateLimited;
68 68
69#[derive(Debug, Clone)]
70pub struct Pubkey {
71 a: String,
72}
73
69impl Reject for RateLimited {} 74impl Reject for RateLimited {}
70 75
71pub fn with_auth( 76pub fn with_auth(
72 db: Db, 77 db: Db,
73 t: Transaction, 78 t: Transaction,
74) -> impl Filter<Extract = (String,), Error = Rejection> + Clone { 79) -> impl Filter<Extract = (Pubkey,), Error = Rejection> + Clone {
75 headers_cloned() 80 headers_cloned()
76 .map(move |headers: HeaderMap<HeaderValue>| (db.clone(), headers)) 81 .map(move |headers: HeaderMap<HeaderValue>| (db.clone(), headers, t.source.clone()))
77 .and_then(authorize) 82 .and_then(authorize)
78} 83}
79 84
80async fn authorize((db, headers): (Db, HeaderMap<HeaderValue>)) -> Result<String, Rejection> { 85async fn authorize(
86 (db, headers, source): (Db, HeaderMap<HeaderValue>, String),
87) -> Result<Pubkey, Rejection> {
81 match jwt_from_header(&headers) { 88 match jwt_from_header(&headers) {
82 Ok(jwt) => { 89 Ok(jwt) => {
83 let decoded = decode::<Claims>( 90 let decoded = decode::<Claims>(
@@ -89,7 +96,9 @@ async fn authorize((db, headers): (Db, HeaderMap<HeaderValue>)) -> Result<String
89 .map_err(|_| reject::custom(Error::JWTTokenError)) 96 .map_err(|_| reject::custom(Error::JWTTokenError))
90 .unwrap(); 97 .unwrap();
91 98
92 Ok(decoded.claims.puk) 99 Ok(Pubkey {
100 a: decoded.claims.puk,
101 })
93 } 102 }
94 Err(e) => return Err(warp::reject::custom(RateLimited)), 103 Err(e) => return Err(warp::reject::custom(RateLimited)),
95 } 104 }