diff --git a/src/web/extractors.rs b/src/web/extractors.rs index 708655d328..35d4d73c24 100644 --- a/src/web/extractors.rs +++ b/src/web/extractors.rs @@ -13,8 +13,6 @@ use actix_web::{ web::{Data, Json, Query}, Error, FromRequest, HttpMessage, HttpRequest, }; -use actix_web_httpauth::extractors::bearer::BearerAuth; -use actix_web_httpauth::headers::authorization; use futures::future::{self, FutureExt, LocalBoxFuture, Ready, TryFutureExt}; @@ -1757,28 +1755,6 @@ where Ok(None) } -// Tokenserver extractor -#[derive(Debug, Default, Clone, Deserialize)] -pub struct TokenServerRequest { - auth: String, - // TODO extract required headers from the request into this struct. -} - -impl FromRequest for TokenServerRequest { - type Config = (); - type Error = Error; - type Future = LocalBoxFuture<'static, Result>; - - /// Extract and validate the precondition headers - fn from_request(req: &HttpRequest, _payload: &mut Payload) -> Self::Future { - Box::pin(async move { - Ok(Self { - auth: "asdf".to_string(), - }) - }) - } -} - #[cfg(test)] mod tests { use actix_http::h1; diff --git a/src/web/tokenserver.rs b/src/web/tokenserver.rs index 27522d7341..f8f1656919 100644 --- a/src/web/tokenserver.rs +++ b/src/web/tokenserver.rs @@ -4,20 +4,17 @@ use actix_web::HttpResponse; use actix_web_httpauth::extractors::bearer::BearerAuth; use futures::future::{Future, TryFutureExt}; -use futures::TryStreamExt; use crate::error::{ApiError, ApiErrorKind}; -use crate::web::extractors::TokenServerRequest; use diesel::mysql::MysqlConnection; use diesel::prelude::*; use diesel::sql_types::*; -use diesel::{QueryDsl, RunQueryDsl}; +use diesel::RunQueryDsl; use std::env; -use jsonwebtoken::errors::ErrorKind; use jsonwebtoken::{ - decode, encode, Algorithm, DecodingKey, EncodingKey, Header, TokenData, Validation, + decode, Algorithm, DecodingKey, Validation, }; use pyo3::prelude::*; use pyo3::types::IntoPyDict; @@ -73,10 +70,9 @@ pub struct Claims { } pub fn get( - request: TokenServerRequest, auth: BearerAuth, ) -> impl Future>> { - block(move || get_sync(request, &auth).map_err(Into::into)).map_ok(move |result| { + block(move || get_sync(&auth).map_err(Into::into)).map_ok(move |result| { HttpResponse::Ok() .content_type("application/json") .body(serde_json::to_string(&result).unwrap()) @@ -84,7 +80,6 @@ pub fn get( } pub fn get_sync( - _request: TokenServerRequest, auth: &BearerAuth, ) -> Result { // the public rsa components come from @@ -106,7 +101,7 @@ pub fn get_sync( env::var("TOKENSERVER_DATABASE_URL").expect("TOKENSERVER_DATABASE_URL must be set"); let connection = MysqlConnection::establish(&database_url) - .expect(&format!("Error connecting to {}", database_url)); + .unwrap_or_else(|_| panic!("Error connecting to {}", database_url)); let user_record = diesel::sql_query( "select users.uid, services.pattern, users.email, users.generation, users.client_state, users.created_at, users.replaced_at, nodes.node, users.keys_changed_at from users, services, nodes where users.email = ? and services.id = users.service and nodes.id = users.nodeid and nodes.service = services.id") .bind::(email) @@ -165,10 +160,10 @@ def get_derived_secret(plaintext, shared_secret): println!("python result {:}", python_result); let api_endpoint = format!("{:}/1.5/{:}/", user_record[0].node, token_data.claims.sub); Ok(TokenServerResult { - id: python_result.to_string(), - key: python_derived_result.to_string(), + id: python_result, + key: python_derived_result, uid: token_data.claims.sub, - api_endpoint: api_endpoint, + api_endpoint, duration: "300".to_string(), }) }