stuff
This commit is contained in:
+66
@@ -0,0 +1,66 @@
|
||||
use rustsf_auth::{authenticate_sfdx_url, SalesforceAuthConfig};
|
||||
use anyhow::{Context, Result};
|
||||
|
||||
use reqwest::header::{AUTHORIZATION, HeaderMap, HeaderValue};
|
||||
pub const CONNECT_TIMEOUT: u64 = 15;
|
||||
pub const REQUEST_TIMEOUT: u64 = 30;
|
||||
|
||||
pub fn get_http_client() -> Result<reqwest::Client> {
|
||||
Ok(reqwest::Client::builder()
|
||||
.redirect(reqwest::redirect::Policy::none())
|
||||
.connect_timeout(std::time::Duration::from_secs(CONNECT_TIMEOUT))
|
||||
.timeout(std::time::Duration::from_secs(REQUEST_TIMEOUT))
|
||||
.build()
|
||||
.context("Failed to build HTTP client")?)
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
println!("Hello, world!");
|
||||
|
||||
let url = "https://computing-platform-9537--qa.sandbox.my.salesforce.com/";
|
||||
let customer_id = "3MVG9xj60O9CjKHpQMaI0gAqe_BibSxfGHYQBII24Bif2Nri7ewsMsz3kEbMr4vch36.q4I.B37EpwOOtg90e";
|
||||
let customer_secret = "68182180245EEBC7C54804536914BBEA32C0C347D83A67EB43A6225D342C95B9";
|
||||
|
||||
let sfdx_auth_url = "force://PlatformCLI::5Aep8618kS0Qqf3GEL4qVTX2VSz2qiUtn3Grl0qSlJjRoSGz03Uv86qbbx2MOhcIyj.OTqFKFH.olbk5LdlYEAv@computing-platform-9537--qa.sandbox.my.salesforce.com";
|
||||
|
||||
|
||||
/// let config = SalesforceAuthConfig::client_credentials(
|
||||
/// "https://login.salesforce.com",
|
||||
/// "client-id",
|
||||
/// "client-secret",
|
||||
/// );
|
||||
///
|
||||
/// let session = config.authenticate().await?;
|
||||
/// println!("{}", session.access_token);
|
||||
/// # Ok(())
|
||||
|
||||
let config = SalesforceAuthConfig::sfdx_url(sfdx_auth_url);
|
||||
|
||||
let session = config.connect().await.unwrap();
|
||||
|
||||
println!("{}", session.access_token);
|
||||
|
||||
|
||||
let mut headers = HeaderMap::new();
|
||||
let auth_value = format!("Bearer {}", session.access_token);
|
||||
headers.insert(AUTHORIZATION, HeaderValue::from_str(&auth_value).unwrap());
|
||||
|
||||
//Default header
|
||||
headers.insert("Accept", HeaderValue::from_static("application/json"));
|
||||
|
||||
|
||||
let response = get_http_client().unwrap()
|
||||
.get(format!("{}/services/data", session.instance_url))
|
||||
.headers(headers)
|
||||
.send()
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
||||
if response.status().is_success() {
|
||||
println!("SUCCESS Response: {:?}", response.text().await.unwrap());
|
||||
} else {
|
||||
println!("ERROR Response: {:?}", response.text().await.unwrap());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user