diff --git a/src/oauth.rs b/src/oauth.rs index 474eb9b988fa1044692e785f308807f43933a8e0..0b6715674e856a8a381dc0ebb958d54c9edf16fd 100644 --- a/src/oauth.rs +++ b/src/oauth.rs @@ -45,6 +45,9 @@ use reqwest; use serde_json; use jq_rs; +/// Construct a configuration key from parts +/// +/// Simply joins all elements of the passed array with a '.' fn full_key(parts: Vec<&str>) -> String { parts.join(".") } @@ -136,17 +139,24 @@ pub fn get_access_token_password<E: Copy>(conf: &Config, prefix: &str, username: } } +/// Retrieve text data from a configured URL endpoint +/// +/// Takes the same arguments as `get_data_jq`. fn get_data(conf: &Config, prefix: &str, endpoint: &str, param: String, token: &BasicTokenResponse) -> Result<String, Box<dyn error::Error>> { + /// Extract token as string from deserialized access token let access_token = token.access_token().secret(); + let token_type = "Bearer".to_string(); // FIXME Probably we need to handle other token types + // Retreieve endpoint URL from configuration let mut endpoint_url: String = get_or_error(&conf, &full_key(vec![prefix, "urls", endpoint]), "")?; endpoint_url = endpoint_url.replace("{}", ¶m); - debug!("Loading text data from {}", endpoint_url); + + // Send off request to server let client = reqwest::blocking::Client::new(); Ok(client .get(&endpoint_url) - .header(reqwest::header::AUTHORIZATION, format!("Bearer {}", access_token)) + .header(reqwest::header::AUTHORIZATION, format!("{} {}", token_type, access_token)) .send()? .text()?) }