mirror of
https://github.com/Xevion/dynamic-preauth.git
synced 2026-01-31 04:24:10 -06:00
Add token request step to demo with reqwest
This commit is contained in:
Generated
+1181
File diff suppressed because it is too large
Load Diff
@@ -7,6 +7,7 @@ build = "build.rs"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
chrono = "0.4.39"
|
chrono = "0.4.39"
|
||||||
hex = "0.4.3"
|
hex = "0.4.3"
|
||||||
|
reqwest = { version = "0.12.9", features = ["blocking", "json"] }
|
||||||
serde = { version = "1.0.216", features = ["derive"] }
|
serde = { version = "1.0.216", features = ["derive"] }
|
||||||
serde_json = "1.0.134"
|
serde_json = "1.0.134"
|
||||||
sha2 = "0.10.8"
|
sha2 = "0.10.8"
|
||||||
|
|||||||
+51
-2
@@ -26,11 +26,60 @@ fn main() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Use token to make request
|
|
||||||
|
|
||||||
// Check the hash of the value
|
// Check the hash of the value
|
||||||
let value_hash = sha2::Sha256::digest(key_data.value.as_bytes());
|
let value_hash = sha2::Sha256::digest(key_data.value.as_bytes());
|
||||||
let hash_match = hex::encode(value_hash) == key_data.value_hash;
|
let hash_match = hex::encode(value_hash) == key_data.value_hash;
|
||||||
|
|
||||||
|
// if hash_match {
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// TODO: Use token to make request
|
||||||
|
let client = reqwest::blocking::Client::new();
|
||||||
|
let response = client
|
||||||
|
.post(&format!(
|
||||||
|
"http://localhost:5800/notify?key={}",
|
||||||
|
key_data.value
|
||||||
|
))
|
||||||
|
.send();
|
||||||
|
|
||||||
|
match response {
|
||||||
|
Ok(resp) => {
|
||||||
|
if resp.status().is_success() {
|
||||||
|
println!("Request successful");
|
||||||
|
} else {
|
||||||
|
println!("Request failed with status: {}", resp.status());
|
||||||
|
|
||||||
|
if resp
|
||||||
|
.headers()
|
||||||
|
.get(reqwest::header::CONTENT_TYPE)
|
||||||
|
.map(|v| v == "application/json")
|
||||||
|
.unwrap_or(false)
|
||||||
|
{
|
||||||
|
match resp.json::<serde_json::Value>() {
|
||||||
|
Ok(json_body) => {
|
||||||
|
println!(
|
||||||
|
"Response JSON: {}",
|
||||||
|
serde_json::to_string_pretty(&json_body).unwrap()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
println!("Failed to parse JSON response: {}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
println!(
|
||||||
|
"Response body: {}",
|
||||||
|
resp.text()
|
||||||
|
.unwrap_or_else(|_| "Failed to read response body".to_string())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
println!("Request error: {}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
println!("Hash match: {}", hash_match);
|
println!("Hash match: {}", hash_match);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user