Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Delphi DLL) Rabobank GET /v3/accountsDemonstrates a call to a Rabobank API. Specifically this makes a call to the "Accounts AIS sb" API to deliver all the consented payments accounts for a specific Rabobank customer. (This includes source code to for signing requests for PSD2 APIs) For more information, see https://developer-sandbox.rabobank.nl/reference/accounts-ais-sb/3-0-8
uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Http, CkDateTime, Rsa, StringBuilder, JsonObject, PrivateKey, Cert, Crypt2, BinData; ... procedure TForm1.Button1Click(Sender: TObject); var http: HCkHttp; success: Boolean; jsonToken: HCkJsonObject; sbTppCert: HCkStringBuilder; crypt: HCkCrypt2; xRequestId: PWideChar; dt: HCkDateTime; dateHdrVal: PWideChar; payload: PWideChar; payloadDigest: PWideChar; sbDigestHdrVal: HCkStringBuilder; sbStringToSign: HCkStringBuilder; sbPrivKey: HCkStringBuilder; privKey: HCkPrivateKey; rsa: HCkRsa; b64Signature: PWideChar; cert: HCkCert; sbSigHdrVal: HCkStringBuilder; tlsCert: HCkCert; bdPrivKey: HCkBinData; tlsPrivKey: HCkPrivateKey; sbResponseBody: HCkStringBuilder; jResp: HCkJsonObject; respStatusCode: Integer; v_linksAccount: PWideChar; v_linksBalances: PWideChar; v_linksTransactions: PWideChar; currency: PWideChar; iban: PWideChar; name: PWideChar; resourceId: PWideChar; status: PWideChar; i: Integer; count_i: Integer; begin // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. http := CkHttp_Create(); // Implements the following CURL command: // curl --request GET \ // --url https://api-sandbox.rabobank.nl/openapi/sandbox/payments/account-information/ais/v3/accounts \ // --header 'accept: application/json' \ // --header 'authorization: Bearer REPLACE_BEARER_TOKEN' \ // --header 'date: REPLACE_THIS_VALUE' \ // --header 'digest: REPLACE_THIS_VALUE' \ // --header 'psu-ip-address: OPTIONAL' \ // --header 'signature: REPLACE_THIS_VALUE' \ // --header 'tpp-signature-certificate: MIIDkDCCAnigA ... cwE6gUl0rMA==' \ // --header 'x-ibm-client-id: Client ID' \ // --header 'x-request-id: REPLACE_THIS_VALUE' // Load the previously fetched OAuth2 access token. jsonToken := CkJsonObject_Create(); success := CkJsonObject_LoadFile(jsonToken,'qa_data/tokens/rabobank.json'); if (success = False) then begin Memo1.Lines.Add(CkJsonObject__lastErrorText(jsonToken)); Exit; end; // This adds the "authorization: Bearer REPLACE_BEARER_TOKEN" header. CkHttp_putAuthToken(http,CkJsonObject__stringOf(jsonToken,'access_token')); // This is the TTP Signature certificate: The certificate used for signing the request. sbTppCert := CkStringBuilder_Create(); CkStringBuilder_Append(sbTppCert,'MIIDkDCCAnigAwIBAgIEWs3AJDANBgkqhkiG9w0BAQsFADCBiTELMAkGA1UEBhMC'); CkStringBuilder_Append(sbTppCert,'TkwxEDAOBgNVBAgMB1V0cmVjaHQxEDAOBgNVBAcMB1V0cmVjaHQxETAPBgNVBAoM'); CkStringBuilder_Append(sbTppCert,'CFJhYm9iYW5rMRwwGgYDVQQLDBNPbmxpbmUgVHJhbnNhY3Rpb25zMSUwIwYDVQQD'); CkStringBuilder_Append(sbTppCert,'DBxQU0QyIEFQSSBQSSBTZXJ2aWNlcyBTYW5kYm94MB4XDTE4MDQxMTA3NTgyOFoX'); CkStringBuilder_Append(sbTppCert,'DTIzMDQxMTA3NTgyOFowgYkxCzAJBgNVBAYTAk5MMRAwDgYDVQQIDAdVdHJlY2h0'); CkStringBuilder_Append(sbTppCert,'MRAwDgYDVQQHDAdVdHJlY2h0MREwDwYDVQQKDAhSYWJvYmFuazEcMBoGA1UECwwT'); CkStringBuilder_Append(sbTppCert,'T25saW5lIFRyYW5zYWN0aW9uczElMCMGA1UEAwwcUFNEMiBBUEkgUEkgU2Vydmlj'); CkStringBuilder_Append(sbTppCert,'ZXMgU2FuZGJveDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANoAjqGW'); CkStringBuilder_Append(sbTppCert,'UgCIm2F+0sBSEwLal+T3u+uldLikpxHCB8iL1GD7FrRjcA+MVsxhvHly7vRsHK+t'); CkStringBuilder_Append(sbTppCert,'QyMSaeK782RHpY33qxPLc8LmoQLb2EuiQxXj9POYkYBQ74qkrZnvKVlR3WoyQWeD'); CkStringBuilder_Append(sbTppCert,'OXnSY2wbNFfkP8ET4ElwyuIIEriwYhab0OIrnnrO8X82/SPZxHwEd3aQjQ6uhiw8'); CkStringBuilder_Append(sbTppCert,'paDspJbS5WjEfuwY16KVVUYlhbtAwGjvc6aK0NBm+LH9fMLpAE6gfGZNy0gzMDor'); CkStringBuilder_Append(sbTppCert,'VNbkQK1IoAGD8p9ZHdB0F3FwkILEjUiQW6nK+/fKDNJ0TBbpgZUpY8bR460qzxKd'); CkStringBuilder_Append(sbTppCert,'eZ1yPDqX2Cjh6fkCAwEAATANBgkqhkiG9w0BAQsFAAOCAQEAYL4iD6noMJAt63kD'); CkStringBuilder_Append(sbTppCert,'ED4RB2mII/lssvHhcxuDpOm3Ims9urubFWEpvV5TgIBAxy9PBinOdjhO1kGJJnYi'); CkStringBuilder_Append(sbTppCert,'7F1jv1qnZwTV1JhYbvxv3+vk0jaiu7Ew7G3ASlzruXyMhN6t6jk9MpaWGl5Uw1T+'); CkStringBuilder_Append(sbTppCert,'gNRUcWQRR44g3ahQRIS/UHkaV+vcpOa8j186/1X0ULHfbcVQk4LMmJeXqNs8sBAU'); CkStringBuilder_Append(sbTppCert,'dKU/c6ssvj8jfJ4SfrurcBhY5UBTOdQOXTPY85aU3iFloerx7Oi9EHewxInOrU5X'); CkStringBuilder_Append(sbTppCert,'zqqTz2AQPXezexVeAQxP27lzqCmYC7CFiam6QBr06VebkmnPLfs76n8CDc1cwE6g'); CkStringBuilder_Append(sbTppCert,'Ul0rMA=='); CkHttp_SetRequestHeader(http,'tpp-signature-certificate',CkStringBuilder__getAsString(sbTppCert)); // ---------------------------------------------------------------- // We're not going to add the psu-ip-address header in this example. // ---------------------------------------------------------------- // X-Request-ID header... // Generate a UUID v4. crypt := CkCrypt2_Create(); xRequestId := CkCrypt2__generateUuid(crypt); CkHttp_SetRequestHeader(http,'x-request-id',xRequestId); // ---------------------------------------------------------------- // Date header... dt := CkDateTime_Create(); CkDateTime_SetFromCurrentSystemTime(dt); dateHdrVal := CkDateTime__getAsRfc822(dt,False); // The desire date/time format is the "RFC822" format. CkHttp_SetRequestHeader(http,'Date',dateHdrVal); // ---------------------------------------------------------------- // Digest header... CkCrypt2_putHashAlgorithm(crypt,'SHA256'); CkCrypt2_putEncodingMode(crypt,'base64'); // A GET request has no HTTP request body. Therefore the payload is the empty string. payload := ''; payloadDigest := CkCrypt2__hashStringENC(crypt,payload); sbDigestHdrVal := CkStringBuilder_Create(); CkStringBuilder_Append(sbDigestHdrVal,'SHA-256='); CkStringBuilder_Append(sbDigestHdrVal,payloadDigest); CkHttp_SetRequestHeader(http,'digest',CkStringBuilder__getAsString(sbDigestHdrVal)); // ---------------------------------------------------------------- // The HTTP request needs to be signed for PSD2 API's... // Create the signing string (to use in signing the HTTP request). // See https://developer.rabobank.nl/signing-requests-psd2-apis // // For "account information" HTTP requests, we must use the following headers in the signing string. // date // digest // x-request-id sbStringToSign := CkStringBuilder_Create(); CkStringBuilder_Append(sbStringToSign,'date: '); CkStringBuilder_AppendLine(sbStringToSign,dateHdrVal,False); CkStringBuilder_Append(sbStringToSign,'digest: '); CkStringBuilder_AppendLine(sbStringToSign,CkStringBuilder__getAsString(sbDigestHdrVal),False); CkStringBuilder_Append(sbStringToSign,'x-request-id: '); CkStringBuilder_Append(sbStringToSign,xRequestId); // ---------------------------------------------------------------- // Sign with our private key... sbPrivKey := CkStringBuilder_Create(); CkStringBuilder_Append(sbPrivKey,'MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDaAI6hllIAiJth'); CkStringBuilder_Append(sbPrivKey,'ftLAUhMC2pfk97vrpXS4pKcRwgfIi9Rg+xa0Y3APjFbMYbx5cu70bByvrUMjEmni'); CkStringBuilder_Append(sbPrivKey,'u/NkR6WN96sTy3PC5qEC29hLokMV4/TzmJGAUO+KpK2Z7ylZUd1qMkFngzl50mNs'); CkStringBuilder_Append(sbPrivKey,'GzRX5D/BE+BJcMriCBK4sGIWm9DiK556zvF/Nv0j2cR8BHd2kI0OroYsPKWg7KSW'); CkStringBuilder_Append(sbPrivKey,'0uVoxH7sGNeilVVGJYW7QMBo73OmitDQZvix/XzC6QBOoHxmTctIMzA6K1TW5ECt'); CkStringBuilder_Append(sbPrivKey,'SKABg/KfWR3QdBdxcJCCxI1IkFupyvv3ygzSdEwW6YGVKWPG0eOtKs8SnXmdcjw6'); CkStringBuilder_Append(sbPrivKey,'l9go4en5AgMBAAECggEAB8nsTqalwGIhFw8mbXuhNUFlGuek/arYLD6pv28swwQH'); CkStringBuilder_Append(sbPrivKey,'7v0ZlxFUcCHF+iBl0PsDwZTZQ4ePtgGS6ehoLkWHCzb1lEv5E1YVG5qKNE2UUwRl'); CkStringBuilder_Append(sbPrivKey,'fIyPakO6AzyV/UF3uzq7C+/GuXGNTKZxKewg5yD/DCFvKoCOpxu9u36FyqP/hw0S'); CkStringBuilder_Append(sbPrivKey,'ADVlmp35/zoPDPZzu1j4FiCo0pJ9LwJcHxeJHopNAKDw9k6I4z/grskdgupsGzK2'); CkStringBuilder_Append(sbPrivKey,'BiGiQ/+wmmO68/6Xa6KWfpr1PQ6ODJHgzZsdGCVi6Ebaqlj6BbsYWxP6h3lrsGt+'); CkStringBuilder_Append(sbPrivKey,'LmHBaN2jCD6cDp+lihqFgnm8hfdv0lmbPilp71EDfwKBgQD6U8PBzZtN8yXm5WuS'); CkStringBuilder_Append(sbPrivKey,'NL+/8q5GjNmeTJBSo1gM6Y8vOT4QAE147LbVuVBDwyHPoSrNejePae6Q14PswjBy'); CkStringBuilder_Append(sbPrivKey,'T7B8DZ0OeQyGa3trrFg/ib7Vv4ZMvJqX9+WzBrzZsxTg7oCKHzmCR4vIRItKHH3z'); CkStringBuilder_Append(sbPrivKey,'Wnnhqlo8ic2AZ2O43cdJosbO1wKBgQDe8UODOLu0vnHohOKeUqF3w/ZOB2+83/js'); CkStringBuilder_Append(sbPrivKey,'YyUbSkzsGvHIwTjObuMUFTQvdMZ6IkIyJdfnDZIbvlBSD8tzL5iKFTNCK2nL1i4G'); CkStringBuilder_Append(sbPrivKey,'iFr0CYLaHAlhJ5GEbTrTMDoJeBPerZq83HPrSa/Wb0xO18QTWsoVQPFfPFbbcQyI'); CkStringBuilder_Append(sbPrivKey,'9ryJ2iIDrwKBgQC6kuAefG46ZPVk6K2KZUJdgDUgZC52a75NuW0RAqszmUiGiJM1'); CkStringBuilder_Append(sbPrivKey,'g8ip9tq6BqAWrprGV0c93shusBKlzf5p1LdHXqYmeVY6gbWVhPipMrNHgN5KJ3BZ'); CkStringBuilder_Append(sbPrivKey,'v+w1yNnMsErpcxne2HL2hPjMJTpj3GSLkm2xIlTrNhIyl9ydlr7IRUhENQKBgQCv'); CkStringBuilder_Append(sbPrivKey,'i6HxbXa/90WSJTCcIcxqla8X+dsOCf3jhJ3vQy4Wq5C+1wZ35fCAG8Ifq/+so9Uj'); CkStringBuilder_Append(sbPrivKey,'z5CVqqXlmpF8TFuSs2OVNuRJsg14J4nOMwgLKIIUZAcurQ10DN5I9Kx+UEK1EFXL'); CkStringBuilder_Append(sbPrivKey,'aHsORdNjMfgQDO2jn9WHrr9gkg6CdB2+qyoCEfS+mQKBgBW08lcy9V5RzRWb/v/j'); CkStringBuilder_Append(sbPrivKey,'xsc7ovmgAhCJhDeV7dPbx4HbFeoQJlbA8g1thdcFlcatSGyNDbvNE1GPSd4NhkpR'); CkStringBuilder_Append(sbPrivKey,'Y6Hfv53kdEzjVkEtU8lUdL7HNVJqX7bU7oZlfbYcwxWQ1Gg8C1oLIAyEt71slQtd'); CkStringBuilder_Append(sbPrivKey,'RiNYBRZTQe2F0wxbXnuUqLAw'); privKey := CkPrivateKey_Create(); success := CkPrivateKey_LoadPem(privKey,CkStringBuilder__getAsString(sbPrivKey)); if (success = False) then begin Memo1.Lines.Add(CkPrivateKey__lastErrorText(privKey)); Exit; end; rsa := CkRsa_Create(); success := CkRsa_ImportPrivateKeyObj(rsa,privKey); if (success = False) then begin Memo1.Lines.Add(CkRsa__lastErrorText(rsa)); Exit; end; CkRsa_putEncodingMode(rsa,'base64'); b64Signature := CkRsa__signStringENC(rsa,CkStringBuilder__getAsString(sbStringToSign),'SHA256'); // ---------------------------------------------------------------- // Add the "signature" header. // // The signature header will look like this: // signature: keyId="1523433508",algorithm="rsa-sha512",headers="date digest x-request-id",signature="y5o7gKxmfA6AT6...blE1A9Q==" // // The keyId is the serial number of the certificate as defined in 'TPP-Signing-Certificate' header, the format should be Integer not hex. cert := CkCert_Create(); success := CkCert_SetFromEncoded(cert,CkStringBuilder__getAsString(sbTppCert)); if (success = False) then begin Memo1.Lines.Add(CkCert__lastErrorText(cert)); Exit; end; sbSigHdrVal := CkStringBuilder_Create(); CkStringBuilder_Append(sbSigHdrVal,'keyId="'); CkStringBuilder_Append(sbSigHdrVal,CkCert__serialDecimal(cert)); CkStringBuilder_Append(sbSigHdrVal,'",'); CkStringBuilder_Append(sbSigHdrVal,'algorithm="rsa-sha256",'); CkStringBuilder_Append(sbSigHdrVal,'headers="date digest x-request-id",'); CkStringBuilder_Append(sbSigHdrVal,'signature="'); CkStringBuilder_Append(sbSigHdrVal,b64Signature); CkStringBuilder_Append(sbSigHdrVal,'"'); CkHttp_SetRequestHeader(http,'signature',CkStringBuilder__getAsString(sbSigHdrVal)); // ---------------------------------------------------------------- // Add remaining headers... CkHttp_SetRequestHeader(http,'x-ibm-client-id','YOUR_APP_CLIENT_ID'); CkHttp_SetRequestHeader(http,'accept','application/json'); // ---------------------------------------------------------------- // Add our certificate and key for mutual TLS // (provide a registered X509 client certificate during TLS handhake) tlsCert := CkCert_Create(); success := CkCert_LoadFromFile(tlsCert,'qa_data/certs_and_keys/ING/example_client_tls.cer'); if (success = False) then begin Memo1.Lines.Add(CkCert__lastErrorText(tlsCert)); Exit; end; bdPrivKey := CkBinData_Create(); success := CkBinData_LoadFile(bdPrivKey,'qa_data/certs_and_keys/ING/example_client_tls.key'); if (success = False) then begin Memo1.Lines.Add('Failed to load example_client_tls.key'); Exit; end; // The OAuth 2.0 client_id for these certificates is e77d776b-90af-4684-bebc-521e5b2614dd. // Please note down this client_id since you will need it in the next steps to call the API. tlsPrivKey := CkPrivateKey_Create(); success := CkPrivateKey_LoadAnyFormat(tlsPrivKey,bdPrivKey,''); if (success = False) then begin Memo1.Lines.Add(CkPrivateKey__lastErrorText(tlsPrivKey)); Exit; end; // Associate the private key with the certificate. success := CkCert_SetPrivateKey(tlsCert,tlsPrivKey); if (success = False) then begin Memo1.Lines.Add(CkCert__lastErrorText(tlsCert)); Exit; end; success := CkHttp_SetSslClientCert(http,tlsCert); if (success = False) then begin Memo1.Lines.Add(CkHttp__lastErrorText(http)); Exit; end; // ---------------------------------------------------------------- // Finally, send the request... sbResponseBody := CkStringBuilder_Create(); success := CkHttp_QuickGetSb(http,'https://api-sandbox.rabobank.nl/openapi/sandbox/payments/account-information/ais/v3/accounts',sbResponseBody); if (success = False) then begin Memo1.Lines.Add(CkHttp__lastErrorText(http)); Memo1.Lines.Add(CkStringBuilder__getAsString(sbResponseBody)); Exit; end; jResp := CkJsonObject_Create(); CkJsonObject_LoadSb(jResp,sbResponseBody); CkJsonObject_putEmitCompact(jResp,False); Memo1.Lines.Add('Response Body:'); Memo1.Lines.Add(CkJsonObject__emit(jResp)); respStatusCode := CkHttp_getLastStatus(http); Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode)); if (respStatusCode >= 400) then begin Memo1.Lines.Add('Response Header:'); Memo1.Lines.Add(CkHttp__lastHeader(http)); Memo1.Lines.Add('Failed.'); Exit; end; // Sample JSON response: // (Sample code for parsing the JSON response is shown below) // { // "accounts": [ // { // "_links": { // "account": "/v3/accounts/dW9od2VIVUhGVypIZHVpaGRhdWR3OGRoY", // "balances": "/v3/accounts/dW9od2VIVUhGVypIZHVpaGRhdWR3OGRoY/balances", // "transactions": "/v3/accounts/dW9od2VIVUhGVypIZHVpaGRhdWR3OGRoY/transactions" // }, // "currency": "EUR", // "iban": "NL05RABO0812836782", // "name": "Rosie Roy", // "resourceId": "dW9od2VIVUhGVypIZHVpaGRhdWR3OGRoY", // "status": "enabled" // } // ] // } // Sample code for parsing the JSON response... // Use the following online tool to generate parsing code from sample JSON: // Generate Parsing Code from JSON i := 0; count_i := CkJsonObject_SizeOfArray(jResp,'accounts'); while i < count_i do begin CkJsonObject_putI(jResp,i); v_linksAccount := CkJsonObject__stringOf(jResp,'accounts[i]._links.account'); v_linksBalances := CkJsonObject__stringOf(jResp,'accounts[i]._links.balances'); v_linksTransactions := CkJsonObject__stringOf(jResp,'accounts[i]._links.transactions'); currency := CkJsonObject__stringOf(jResp,'accounts[i].currency'); iban := CkJsonObject__stringOf(jResp,'accounts[i].iban'); name := CkJsonObject__stringOf(jResp,'accounts[i].name'); resourceId := CkJsonObject__stringOf(jResp,'accounts[i].resourceId'); status := CkJsonObject__stringOf(jResp,'accounts[i].status'); i := i + 1; end; CkHttp_Dispose(http); CkJsonObject_Dispose(jsonToken); CkStringBuilder_Dispose(sbTppCert); CkCrypt2_Dispose(crypt); CkDateTime_Dispose(dt); CkStringBuilder_Dispose(sbDigestHdrVal); CkStringBuilder_Dispose(sbStringToSign); CkStringBuilder_Dispose(sbPrivKey); CkPrivateKey_Dispose(privKey); CkRsa_Dispose(rsa); CkCert_Dispose(cert); CkStringBuilder_Dispose(sbSigHdrVal); CkCert_Dispose(tlsCert); CkBinData_Dispose(bdPrivKey); CkPrivateKey_Dispose(tlsPrivKey); CkStringBuilder_Dispose(sbResponseBody); CkJsonObject_Dispose(jResp); end; |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.