Compare commits
10 Commits
0b56d77364
...
5ef5f48654
Author | SHA1 | Date |
---|---|---|
Franklin | 5ef5f48654 | |
Franklin | 5f81817f32 | |
Franklin | 065921c0b5 | |
Franklin | 0ac5d17824 | |
Franklin | 1736e2d14d | |
Franklin | 72a11741b8 | |
Franklin | 6733e07a4f | |
Franklin | b255a01774 | |
franklinblanco | de30a033ec | |
franklinblanco | 20dd8f1dee |
10
Cargo.toml
10
Cargo.toml
|
@ -4,9 +4,13 @@ version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
proc-macro = true
|
#proc-macro = true
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
syn = "1.0"
|
syn = "1.0"
|
||||||
quote = "1.0"
|
#quote = "1.0"
|
||||||
|
#proc-macro2 = "1.0"
|
||||||
|
|
||||||
|
dev-dtos = { git = "https://github.com/franklinblanco/user-svc-dtos-rust.git" }
|
||||||
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
serde_json = { version = "1" }
|
50
src/lib.rs
50
src/lib.rs
|
@ -1,12 +1,46 @@
|
||||||
use proc_macro::TokenStream;
|
mod auth;
|
||||||
use quote::{quote};
|
|
||||||
|
|
||||||
|
/*#[proc_macro_attribute]
|
||||||
|
pub fn authenticated_route(_: TokenStream, mut input: TokenStream) -> TokenStream {
|
||||||
|
let tt_to_add = TokenStream::from(quote::quote!{
|
||||||
|
let header_conversion_result: dev_dtos::dtos::user::user_dtos::UserAuthHeader = match serde_json::from_str(match request.headers().get("authentication") {
|
||||||
|
Some(auth_header) => match auth_header.to_str() {
|
||||||
|
Ok(string) => string,
|
||||||
|
Err(_) => return actix_web_utils::extensions::typed_response::TypedHttpResponse::return_standard_error(400, err::MessageResource::new_from_str("Auth header in incorrect format.")),
|
||||||
|
},
|
||||||
|
None => return actix_web_utils::extensions::typed_response::TypedHttpResponse::return_standard_error(401, err::MessageResource::new_from_str("No auth header present.")),
|
||||||
|
}) {
|
||||||
|
Ok(user_for_authentication) => user_for_authentication,
|
||||||
|
Err(error) => return actix_web_utils::extensions::typed_response::TypedHttpResponse::return_standard_error(401, err::MessageResource::new_from_string(error.to_string())),
|
||||||
|
};
|
||||||
|
let authenticated_user = match dev_communicators::middleware::user_svc::user_service::authenticate_user_with_token(&client, &header_conversion_result.into()).await {
|
||||||
|
Ok(authed_user) => authed_user,
|
||||||
|
Err(error) => return actix_web_utils::extensions::typed_response::TypedHttpResponse::return_standard_error(401, err::MessageResource::new_from_string(error.to_string())),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
input.extend(tt_to_add);
|
||||||
|
input
|
||||||
|
}*/
|
||||||
|
|
||||||
#[proc_macro]
|
#[allow(unused_macros)]
|
||||||
pub fn nigga(_input: TokenStream) -> TokenStream {
|
#[macro_export]
|
||||||
TokenStream::from(quote!(
|
macro_rules! authenticate_route {
|
||||||
fn deez() -> i32 {
|
($request:expr, $client:expr) => {
|
||||||
122
|
match serde_json::from_str::<dev_dtos::dtos::user::user_dtos::UserAuthHeader>(match $request.headers().get("authentication") {
|
||||||
|
Some(auth_header) => match auth_header.to_str() {
|
||||||
|
Ok(string) => string,
|
||||||
|
Err(_) => return actix_web_utils::extensions::typed_response::TypedHttpResponse::return_standard_error(400, err::MessageResource::new_from_str("Auth header in incorrect format.")),
|
||||||
|
},
|
||||||
|
None => return actix_web_utils::extensions::typed_response::TypedHttpResponse::return_standard_error(401, err::MessageResource::new_from_str("No auth header present.")),
|
||||||
|
}) {
|
||||||
|
Ok(user_for_authentication) => {
|
||||||
|
match dev_communicators::middleware::user_svc::user_service::authenticate_user_with_token($client, &user_for_authentication.into()).await {
|
||||||
|
Ok(authed_user) => authed_user,
|
||||||
|
Err(error) => return actix_web_utils::extensions::typed_response::TypedHttpResponse::return_standard_error(401, err::MessageResource::new_from_string(error.to_string())),
|
||||||
}
|
}
|
||||||
))
|
},
|
||||||
|
Err(error) => return actix_web_utils::extensions::typed_response::TypedHttpResponse::return_standard_error(401, err::MessageResource::new_from_string(error.to_string())),
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
}
|
}
|
Loading…
Reference in New Issue