rustfmt and simplify

This commit is contained in:
Cadey Ratio 2020-04-15 22:18:22 -04:00
parent 6022dd7cf7
commit a406f059e3
3 changed files with 6 additions and 8 deletions

View File

@ -11,7 +11,8 @@ struct Claims {
pub async fn validate_token(token: &str) -> Result<bool, ServiceError> { pub async fn validate_token(token: &str) -> Result<bool, ServiceError> {
let domain = std::env::var("DOMAIN").expect("DOMAIN must be set"); let domain = std::env::var("DOMAIN").expect("DOMAIN must be set");
let jwks = fetch_jwks(&format!("{}{}", domain.as_str(), ".well-known/jwks.json")).await let jwks = fetch_jwks(&format!("{}{}", domain.as_str(), ".well-known/jwks.json"))
.await
.expect("failed to fetch jwks"); .expect("failed to fetch jwks");
let validations = vec![Validation::Issuer(domain), Validation::SubjectPresent]; let validations = vec![Validation::Issuer(domain), Validation::SubjectPresent];
let kid = match token_kid(&token) { let kid = match token_kid(&token) {
@ -24,7 +25,5 @@ pub async fn validate_token(token: &str) -> Result<bool, ServiceError> {
} }
async fn fetch_jwks(uri: &str) -> anyhow::Result<JWKS> { async fn fetch_jwks(uri: &str) -> anyhow::Result<JWKS> {
let res = reqwest::get(uri).await?; Ok(reqwest::get(uri).await?.json::<JWKS>().await?)
let val = res.json::<JWKS>().await?;
return Ok(val);
} }

View File

@ -17,9 +17,9 @@ pub struct InputUser {
pub async fn get_users(db: web::Data<Pool>) -> Result<HttpResponse, Error> { pub async fn get_users(db: web::Data<Pool>) -> Result<HttpResponse, Error> {
Ok(web::block(move || get_all_users(db)) Ok(web::block(move || get_all_users(db))
.await .await
.map(|user| HttpResponse::Ok().json(user)) .map(|user| HttpResponse::Ok().json(user))
.map_err(|_| HttpResponse::InternalServerError())?) .map_err(|_| HttpResponse::InternalServerError())?)
} }
fn get_all_users(pool: web::Data<Pool>) -> Result<Vec<User>, diesel::result::Error> { fn get_all_users(pool: web::Data<Pool>) -> Result<Vec<User>, diesel::result::Error> {

View File

@ -18,4 +18,3 @@ pub struct NewUser<'a> {
pub email: &'a str, pub email: &'a str,
pub created_at: chrono::NaiveDateTime, pub created_at: chrono::NaiveDateTime,
} }