Sample code for 30+ languages & platforms
Rust

ABN AMRO OAuth2 Client Credentials Authentication

See more ABN AMRO Examples

Demonstrates how to obtain an access token for an ABN AMRO online API using OAuth2 with the Client Credentials flow.

Chilkat Rust Downloads

Rust

// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

// This example sends the following CURL request:

// 	curl -X POST -k https://auth-sandbox.connect.abnamro.com:8443/as/token.oauth2 \
// 	-v \
// 	--cert TPPCertificate.crt \
// 	--key TPPprivateKey.key \
// 	-H 'Cache-Control: no-cache' \
// 	-H 'Content-Type: application/x-www-form-urlencoded' \
// 	-d 'grant_type=client_credentials&client_id=TPP_test&scope=psd2:payment:sepa:write psd2:payment:sepa:read'

let cert = chilkat::Cert::new();
if cert.load_from_file("qa_data/certs/TPPCertificate.cer").is_err() {
    println!("{}", cert.last_error_text());
    return;
}

let bd_key = chilkat::BinData::new();
let _ = bd_key.load_file("qa_data/certs/TPPprivateKey.key").is_ok();

let priv_key = chilkat::PrivateKey::new();
if priv_key.load_any_format(&bd_key, "passwordIfNeeded").is_err() {
    println!("{}", priv_key.last_error_text());
    return;
}

if cert.set_private_key(&priv_key).is_err() {
    println!("{}", cert.last_error_text());
    return;
}

let http = chilkat::Http::new();

if http.set_ssl_client_cert(&cert).is_err() {
    println!("{}", http.last_error_text());
    return;
}

let req = chilkat::HttpRequest::new();
req.add_param("grant_type", "client_credentials");
req.add_param("client_id", "TPP_test");
req.add_param("scope", "psd2:payment:sepa:write psd2:payment:sepa:read");

req.set_http_verb("POST");
req.set_content_type("application/x-www-form-urlencoded");

let resp = chilkat::HttpResponse::new();
if http.http_req("https://auth-sandbox.connect.abnamro.com:8443/as/token.oauth2", &req, &resp).is_err() {
    println!("{}", http.last_error_text());
    return;
}

if resp.status_code() != 200 {
    println!("{}", resp.body_str());
    return;
}

// Get the JSON result:
// {"access_token":"TIhycwl8rfrZPkXGw15mwldASAAK","token_type":"Bearer","expires_in":7200}
let json = chilkat::JsonObject::new();
let _ = json.load(&resp.body_str());
println!("access_token: {}", json.string_of("access_token").unwrap_or_default());
println!("token_type: {}", json.string_of("token_type").unwrap_or_default());
println!("expires_in: {}", json.string_of("expires_in").unwrap_or_default());