diff options
Diffstat (limited to 'src/auth.rs')
| -rw-r--r-- | src/auth.rs | 17 |
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)] |
| 67 | struct RateLimited; | 67 | struct RateLimited; |
| 68 | 68 | ||
| 69 | #[derive(Debug, Clone)] | ||
| 70 | pub struct Pubkey { | ||
| 71 | a: String, | ||
| 72 | } | ||
| 73 | |||
| 69 | impl Reject for RateLimited {} | 74 | impl Reject for RateLimited {} |
| 70 | 75 | ||
| 71 | pub fn with_auth( | 76 | pub 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 | ||
| 80 | async fn authorize((db, headers): (Db, HeaderMap<HeaderValue>)) -> Result<String, Rejection> { | 85 | async 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 | } |
