1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
use reqwest::header::{HeaderValue, CONTENT_TYPE}; #[derive(Debug, Serialize, Deserialize)] pub struct Token { pub access_token: String, pub token_type: String, pub session_state: String, pub scope: String, } pub async fn get_token(path: &str, payload: serde_json::Value) -> Result<Token, reqwest::Error> { let client = reqwest::Client::new(); let k_res = client .post(path) .header(CONTENT_TYPE, HeaderValue::from_static("application/json")) .form(&payload) .send() .await?.error_for_status()?; k_res.json().await } pub async fn introspect_token( path: &str, payload: serde_json::Value, ) -> Result<String, reqwest::Error> { let client = reqwest::Client::new(); let k_res = client .post(path) .header(CONTENT_TYPE, HeaderValue::from_static("application/json")) .form(&payload) .send() .await?.error_for_status()?; k_res.text().await }