aboutsummaryrefslogtreecommitdiffstats
path: root/src/auth.rs
diff options
context:
space:
mode:
authorYigit Sever2021-04-10 14:44:40 +0300
committerYigit Sever2021-04-10 14:44:40 +0300
commitc03321bc059ed733970d8a696acb461428b1d284 (patch)
treea79e48c3a55ac1957932a9b80ce25b39088a9253 /src/auth.rs
parented53fbc9097370feeda1c5507878933643a9bcc5 (diff)
downloadgradecoin-c03321bc059ed733970d8a696acb461428b1d284.tar.gz
gradecoin-c03321bc059ed733970d8a696acb461428b1d284.tar.bz2
gradecoin-c03321bc059ed733970d8a696acb461428b1d284.zip
dunno
Diffstat (limited to 'src/auth.rs')
-rw-r--r--src/auth.rs25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/auth.rs b/src/auth.rs
index e22262c..95f2378 100644
--- a/src/auth.rs
+++ b/src/auth.rs
@@ -1,12 +1,14 @@
1use crate::error::Error; 1use crate::error::Error;
2use crate::schema::{Db, Transaction}; 2use crate::schema::{Db, Transaction};
3use anyhow::{anyhow, Context, Result};
3use jsonwebtoken::{decode, Algorithm, DecodingKey, Validation}; 4use jsonwebtoken::{decode, Algorithm, DecodingKey, Validation};
4use serde::{Deserialize, Serialize}; 5use serde::{Deserialize, Serialize};
6use thiserror::Error;
5use warp::header::headers_cloned; 7use warp::header::headers_cloned;
6use warp::http::header::{HeaderMap, HeaderValue, AUTHORIZATION}; 8use warp::http::header::{HeaderMap, HeaderValue, AUTHORIZATION};
7use warp::{reject, Filter, Rejection}; 9use warp::reject;
8use thiserror::Error; 10use warp::reject::Reject;
9use anyhow::*; 11use warp::{Filter, Rejection};
10 12
11const BEARER: &str = "Bearer "; 13const BEARER: &str = "Bearer ";
12const PUBLIC_KEY_PEM: &str = "-----BEGIN PUBLIC KEY----- 14const PUBLIC_KEY_PEM: &str = "-----BEGIN PUBLIC KEY-----
@@ -65,6 +67,18 @@ struct Claims {
65// found: String, 67// found: String,
66// }, 68// },
67// } 69// }
70// impl warp::reject::Reject for Nope {}
71
72#[derive(Debug)]
73struct LessThanTenError {}
74
75impl Reject for LessThanTenError {}
76
77// impl From<LessThanTenError> for Rejection {
78// fn from(other: LessThanTenError) -> Self {
79// warp::reject::custom(other)
80// }
81// }
68 82
69pub fn with_auth( 83pub fn with_auth(
70 db: Db, 84 db: Db,
@@ -75,8 +89,6 @@ pub fn with_auth(
75 .and_then(authorize) 89 .and_then(authorize)
76} 90}
77 91
78impl warp::reject::Reject for Nope {}
79
80async fn authorize((db, headers): (Db, HeaderMap<HeaderValue>)) -> Result<String, Error> { 92async fn authorize((db, headers): (Db, HeaderMap<HeaderValue>)) -> Result<String, Error> {
81 match jwt_from_header(&headers) { 93 match jwt_from_header(&headers) {
82 Ok(jwt) => { 94 Ok(jwt) => {
@@ -92,7 +104,8 @@ async fn authorize((db, headers): (Db, HeaderMap<HeaderValue>)) -> Result<String
92 104
93 Ok(decoded.claims.puk) 105 Ok(decoded.claims.puk)
94 } 106 }
95 Err(e) => return Err(anyhow!("missing!")); 107 Err(e) => return Err(anyhow!("missing!")),
108 // warp error
96 } 109 }
97} 110}
98 111