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
(Unicode C) Ibanity XS2A List Financial InstitutionsSee more Ibanity ExamplesDemonstrates how to send a request to get a list of financial institutions. For more information, see https://documentation.ibanity.com/xs2a/api/curl#authentication
#include <C_CkCertW.h> #include <C_CkDateTimeW.h> #include <C_CkCrypt2W.h> #include <C_CkStringBuilderW.h> #include <C_CkPrivateKeyW.h> #include <C_CkRsaW.h> #include <C_CkHttpW.h> #include <C_CkJsonObjectW.h> void ChilkatSample(void) { HCkCertW cert; BOOL success; HCkDateTimeW dtNow; const wchar_t *created; HCkCrypt2W crypt2; HCkStringBuilderW sbDigestHdrValue; const wchar_t *request_target; HCkStringBuilderW sbSigningString; const wchar_t *signed_headers_list; HCkPrivateKeyW privKey; HCkRsaW rsa; const wchar_t *sigBase64; HCkStringBuilderW sbSigHeaderValue; HCkHttpW http; HCkStringBuilderW sbResponseBody; HCkJsonObjectW jResp; int respStatusCode; const wchar_t *attributesBic; BOOL attributesBulkPaymentsEnabled; const wchar_t *attributesCountry; BOOL attributesFinancialInstitutionCustomerReferenceRequired; BOOL attributesFutureDatedPaymentsAllowed; const wchar_t *attributesLogoUrl; const wchar_t *attributesMaintenanceFrom; const wchar_t *attributesMaintenanceTo; const wchar_t *attributesMaintenanceType; const wchar_t *attributesMaxRequestedAccountReferences; int attributesMinRequestedAccountReferences; const wchar_t *attributesName; BOOL attributesPaymentsEnabled; BOOL attributesPeriodicPaymentsEnabled; const wchar_t *attributesPrimaryColor; BOOL attributesRequiresCredentialStorage; BOOL attributesRequiresCustomerIpAddress; BOOL attributesSandbox; const wchar_t *attributesSecondaryColor; const wchar_t *attributesSharedBrandName; const wchar_t *attributesSharedBrandReference; const wchar_t *attributesStatus; const wchar_t *id; const wchar_t *linksSelf; const wchar_t *v_type; int j; int count_j; const wchar_t *strVal; const wchar_t *linksFirst; int metaPagingLimit; int i; int count_i; // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. // Send the following request: // $ curl -X GET https://api.ibanity.com/xs2a/financial-institutions \ // --cert certificate.pem \ // --key private_key.pem \ // -H 'Signature: keyId="75b5d796-de5c-400a-81ce-e72371b01cbc",created=1599659223,algorithm="hs2019",headers="(request-target) digest (created) host",signature="BASE64(RSA-SHA256(SIGNING_STRING))"' \ // -H 'Digest: SHA-512=beDaRguyEb8fhh5wnl37bOTDtvhuYZyZNkTZ9LiC9Wc=' // Ibanity provides the certificate + private key in PFX format. This example will use the .pfx instead of the pair of PEM files. // (It is also possible to implement using Chilkat with the PEM files, but PFX is easier.) cert = CkCertW_Create(); success = CkCertW_LoadPfxFile(cert,L"qa_data/pfx/my_ibanity_certificate.pfx",L"my_pfx_password"); if (success == FALSE) { wprintf(L"%s\n",CkCertW_lastErrorText(cert)); CkCertW_Dispose(cert); return; } // We need to calculate the Digest and Signature header fields. // For a detailed explanation, see Calculate Ibanity HTTP Signature Example // We'll just write the code here as briefly as possible. dtNow = CkDateTimeW_Create(); CkDateTimeW_SetFromCurrentSystemTime(dtNow); created = CkDateTimeW_getAsUnixTimeStr(dtNow,FALSE); crypt2 = CkCrypt2W_Create(); CkCrypt2W_putHashAlgorithm(crypt2,L"sha512"); CkCrypt2W_putEncodingMode(crypt2,L"base64"); sbDigestHdrValue = CkStringBuilderW_Create(); CkStringBuilderW_Append(sbDigestHdrValue,L"SHA-512="); // GET requests have empty payloads. The SHA-512 hash of the empty string is the same for all GET requests. // Therefore all GET requests will use "z4PhNX7vuL3xVChQ1m2AB9Yg5AULVxXcg/SpIdNs6c5H0NE8XYXysP+DGNKHfuwvY7kxvUdBeoGlODJ6+SfaPg==" // You can eliminate the explicit hash computation (for GET requests) and simply use the above literal string. CkStringBuilderW_Append(sbDigestHdrValue,CkCrypt2W_hashStringENC(crypt2,L"")); wprintf(L"Generated Digest\n"); wprintf(L"%s\n",CkStringBuilderW_getAsString(sbDigestHdrValue)); request_target = L"get /xs2a/financial-institutions"; sbSigningString = CkStringBuilderW_Create(); CkStringBuilderW_Append(sbSigningString,L"(request-target): "); CkStringBuilderW_AppendLine(sbSigningString,request_target,FALSE); CkStringBuilderW_Append(sbSigningString,L"host: "); CkStringBuilderW_AppendLine(sbSigningString,L"api.ibanity.com",FALSE); CkStringBuilderW_Append(sbSigningString,L"digest: "); CkStringBuilderW_AppendLine(sbSigningString,CkStringBuilderW_getAsString(sbDigestHdrValue),FALSE); CkStringBuilderW_Append(sbSigningString,L"(created): "); CkStringBuilderW_Append(sbSigningString,created); // ibanity-idempotency-key is not used with GET requests. wprintf(L"Signing String:\n"); wprintf(L"%s\n",CkStringBuilderW_getAsString(sbSigningString)); signed_headers_list = L"(request-target) host digest (created)"; privKey = CkPrivateKeyW_Create(); success = CkPrivateKeyW_LoadEncryptedPemFile(privKey,L"my_ibanity_signature_private_key.pem",L"pem_password"); if (success == FALSE) { wprintf(L"%s\n",CkPrivateKeyW_lastErrorText(privKey)); CkCertW_Dispose(cert); CkDateTimeW_Dispose(dtNow); CkCrypt2W_Dispose(crypt2); CkStringBuilderW_Dispose(sbDigestHdrValue); CkStringBuilderW_Dispose(sbSigningString); CkPrivateKeyW_Dispose(privKey); return; } rsa = CkRsaW_Create(); CkRsaW_putPssSaltLen(rsa,32); CkRsaW_putEncodingMode(rsa,L"base64"); // Use the RSASSA-PSS signature algorithm CkRsaW_putOaepPadding(rsa,TRUE); success = CkRsaW_ImportPrivateKeyObj(rsa,privKey); if (success == FALSE) { wprintf(L"%s\n",CkRsaW_lastErrorText(rsa)); CkCertW_Dispose(cert); CkDateTimeW_Dispose(dtNow); CkCrypt2W_Dispose(crypt2); CkStringBuilderW_Dispose(sbDigestHdrValue); CkStringBuilderW_Dispose(sbSigningString); CkPrivateKeyW_Dispose(privKey); CkRsaW_Dispose(rsa); return; } // Sign the signing string. sigBase64 = CkRsaW_signStringENC(rsa,CkStringBuilderW_getAsString(sbSigningString),L"sha-256"); if (CkRsaW_getLastMethodSuccess(rsa) == FALSE) { wprintf(L"%s\n",CkRsaW_lastErrorText(rsa)); CkCertW_Dispose(cert); CkDateTimeW_Dispose(dtNow); CkCrypt2W_Dispose(crypt2); CkStringBuilderW_Dispose(sbDigestHdrValue); CkStringBuilderW_Dispose(sbSigningString); CkPrivateKeyW_Dispose(privKey); CkRsaW_Dispose(rsa); return; } wprintf(L"Signature:\n"); wprintf(L"%s\n",sigBase64); // Build the signature header value. sbSigHeaderValue = CkStringBuilderW_Create(); CkStringBuilderW_Append(sbSigHeaderValue,L"keyId=\""); // Use your identifier for the application's signature certificate, obtained from the Developer Portal CkStringBuilderW_Append(sbSigHeaderValue,L"a0ce296d-84c8-4bd5-8eb4-de0339950cfa"); CkStringBuilderW_Append(sbSigHeaderValue,L"\",created="); CkStringBuilderW_Append(sbSigHeaderValue,created); CkStringBuilderW_Append(sbSigHeaderValue,L",algorithm=\"hs2019\",headers=\""); CkStringBuilderW_Append(sbSigHeaderValue,signed_headers_list); CkStringBuilderW_Append(sbSigHeaderValue,L"\",signature=\""); CkStringBuilderW_Append(sbSigHeaderValue,sigBase64); CkStringBuilderW_Append(sbSigHeaderValue,L"\""); // Send the GET request.. http = CkHttpW_Create(); success = CkHttpW_SetSslClientCert(http,cert); if (success == FALSE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkCertW_Dispose(cert); CkDateTimeW_Dispose(dtNow); CkCrypt2W_Dispose(crypt2); CkStringBuilderW_Dispose(sbDigestHdrValue); CkStringBuilderW_Dispose(sbSigningString); CkPrivateKeyW_Dispose(privKey); CkRsaW_Dispose(rsa); CkStringBuilderW_Dispose(sbSigHeaderValue); CkHttpW_Dispose(http); return; } CkHttpW_SetRequestHeader(http,L"Signature",CkStringBuilderW_getAsString(sbSigHeaderValue)); CkHttpW_SetRequestHeader(http,L"Digest",CkStringBuilderW_getAsString(sbDigestHdrValue)); sbResponseBody = CkStringBuilderW_Create(); success = CkHttpW_QuickGetSb(http,L"https://api.ibanity.com/xs2a/financial-institutions",sbResponseBody); if (success == FALSE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkCertW_Dispose(cert); CkDateTimeW_Dispose(dtNow); CkCrypt2W_Dispose(crypt2); CkStringBuilderW_Dispose(sbDigestHdrValue); CkStringBuilderW_Dispose(sbSigningString); CkPrivateKeyW_Dispose(privKey); CkRsaW_Dispose(rsa); CkStringBuilderW_Dispose(sbSigHeaderValue); CkHttpW_Dispose(http); CkStringBuilderW_Dispose(sbResponseBody); return; } jResp = CkJsonObjectW_Create(); CkJsonObjectW_LoadSb(jResp,sbResponseBody); CkJsonObjectW_putEmitCompact(jResp,FALSE); wprintf(L"Response Body:\n"); wprintf(L"%s\n",CkJsonObjectW_emit(jResp)); respStatusCode = CkHttpW_getLastStatus(http); wprintf(L"Response Status Code = %d\n",respStatusCode); if (respStatusCode >= 400) { wprintf(L"Response Header:\n"); wprintf(L"%s\n",CkHttpW_lastHeader(http)); wprintf(L"Failed.\n"); CkCertW_Dispose(cert); CkDateTimeW_Dispose(dtNow); CkCrypt2W_Dispose(crypt2); CkStringBuilderW_Dispose(sbDigestHdrValue); CkStringBuilderW_Dispose(sbSigningString); CkPrivateKeyW_Dispose(privKey); CkRsaW_Dispose(rsa); CkStringBuilderW_Dispose(sbSigHeaderValue); CkHttpW_Dispose(http); CkStringBuilderW_Dispose(sbResponseBody); CkJsonObjectW_Dispose(jResp); return; } // Sample output: // (Sample code for parsing the JSON response is shown below) // { // "data": [ // { // "attributes": { // "authorizationModels": [ // "detailed", // "financialInstitutionOffered" // ], // "bic": "NBBEBEBB203", // "bulkPaymentsEnabled": true, // "bulkPaymentsProductTypes": [ // "sepaCreditTransfer" // ], // "country": null, // "financialInstitutionCustomerReferenceRequired": false, // "futureDatedPaymentsAllowed": true, // "logoUrl": "https://s3.eu-central-1.amazonaws.com/ibanity-production-financial-institution-assets/sandbox.png", // "maintenanceFrom": null, // "maintenanceTo": null, // "maintenanceType": null, // "maxRequestedAccountReferences": null, // "minRequestedAccountReferences": 0, // "name": "Bogus Financial", // "paymentsEnabled": true, // "paymentsProductTypes": [ // "sepaCreditTransfer" // ], // "periodicPaymentsEnabled": true, // "periodicPaymentsProductTypes": [ // "sepaCreditTransfer" // ], // "primaryColor": "#7d39ff", // "requiresCredentialStorage": false, // "requiresCustomerIpAddress": false, // "sandbox": true, // "secondaryColor": "#3DF2C2", // "sharedBrandName": null, // "sharedBrandReference": null, // "status": "beta" // }, // "id": "2d3d70a4-cb3c-477c-97e1-cbe495b82841", // "links": { // "self": "https://api.ibanity.com/xs2a/financial-institutions/2d3d70a4-cb3c-477c-97e1-cbe495b82841" // }, // "type": "financialInstitution" // }, // { // "attributes": { // "authorizationModels": [ // "detailed", // "financialInstitutionOffered" // ], // "bic": "NBBEBEBB203", // "bulkPaymentsEnabled": true, // "bulkPaymentsProductTypes": [ // "sepaCreditTransfer" // ], // "country": null, // "financialInstitutionCustomerReferenceRequired": false, // "futureDatedPaymentsAllowed": true, // "logoUrl": "https://s3.eu-central-1.amazonaws.com/ibanity-production-financial-institution-assets/sandbox.png", // "maintenanceFrom": null, // "maintenanceTo": null, // "maintenanceType": null, // "maxRequestedAccountReferences": null, // "minRequestedAccountReferences": 0, // "name": "XYZ Trust", // "paymentsEnabled": true, // "paymentsProductTypes": [ // "sepaCreditTransfer" // ], // "periodicPaymentsEnabled": true, // "periodicPaymentsProductTypes": [ // "sepaCreditTransfer" // ], // "primaryColor": "#7d39ff", // "requiresCredentialStorage": false, // "requiresCustomerIpAddress": false, // "sandbox": true, // "secondaryColor": "#3DF2C2", // "sharedBrandName": null, // "sharedBrandReference": null, // "status": "beta" // }, // "id": "d4100f28-936b-4379-a3f8-86314a2014fb", // "links": { // "self": "https://api.ibanity.com/xs2a/financial-institutions/d4100f28-936b-4379-a3f8-86314a2014fb" // }, // "type": "financialInstitution" // } // ], // "links": { // "first": "https://api.ibanity.com/xs2a/financial-institutions" // }, // "meta": { // "paging": { // "limit": 10 // } // } // } // Sample code for parsing the JSON response... // Use the following online tool to generate parsing code from sample JSON: // Generate Parsing Code from JSON // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat. // See this example explaining how this memory should be used: const char * functions. linksFirst = CkJsonObjectW_stringOf(jResp,L"links.first"); metaPagingLimit = CkJsonObjectW_IntOf(jResp,L"meta.paging.limit"); i = 0; count_i = CkJsonObjectW_SizeOfArray(jResp,L"data"); while (i < count_i) { CkJsonObjectW_putI(jResp,i); attributesBic = CkJsonObjectW_stringOf(jResp,L"data[i].attributes.bic"); attributesBulkPaymentsEnabled = CkJsonObjectW_BoolOf(jResp,L"data[i].attributes.bulkPaymentsEnabled"); attributesCountry = CkJsonObjectW_stringOf(jResp,L"data[i].attributes.country"); attributesFinancialInstitutionCustomerReferenceRequired = CkJsonObjectW_BoolOf(jResp,L"data[i].attributes.financialInstitutionCustomerReferenceRequired"); attributesFutureDatedPaymentsAllowed = CkJsonObjectW_BoolOf(jResp,L"data[i].attributes.futureDatedPaymentsAllowed"); attributesLogoUrl = CkJsonObjectW_stringOf(jResp,L"data[i].attributes.logoUrl"); attributesMaintenanceFrom = CkJsonObjectW_stringOf(jResp,L"data[i].attributes.maintenanceFrom"); attributesMaintenanceTo = CkJsonObjectW_stringOf(jResp,L"data[i].attributes.maintenanceTo"); attributesMaintenanceType = CkJsonObjectW_stringOf(jResp,L"data[i].attributes.maintenanceType"); attributesMaxRequestedAccountReferences = CkJsonObjectW_stringOf(jResp,L"data[i].attributes.maxRequestedAccountReferences"); attributesMinRequestedAccountReferences = CkJsonObjectW_IntOf(jResp,L"data[i].attributes.minRequestedAccountReferences"); attributesName = CkJsonObjectW_stringOf(jResp,L"data[i].attributes.name"); attributesPaymentsEnabled = CkJsonObjectW_BoolOf(jResp,L"data[i].attributes.paymentsEnabled"); attributesPeriodicPaymentsEnabled = CkJsonObjectW_BoolOf(jResp,L"data[i].attributes.periodicPaymentsEnabled"); attributesPrimaryColor = CkJsonObjectW_stringOf(jResp,L"data[i].attributes.primaryColor"); attributesRequiresCredentialStorage = CkJsonObjectW_BoolOf(jResp,L"data[i].attributes.requiresCredentialStorage"); attributesRequiresCustomerIpAddress = CkJsonObjectW_BoolOf(jResp,L"data[i].attributes.requiresCustomerIpAddress"); attributesSandbox = CkJsonObjectW_BoolOf(jResp,L"data[i].attributes.sandbox"); attributesSecondaryColor = CkJsonObjectW_stringOf(jResp,L"data[i].attributes.secondaryColor"); attributesSharedBrandName = CkJsonObjectW_stringOf(jResp,L"data[i].attributes.sharedBrandName"); attributesSharedBrandReference = CkJsonObjectW_stringOf(jResp,L"data[i].attributes.sharedBrandReference"); attributesStatus = CkJsonObjectW_stringOf(jResp,L"data[i].attributes.status"); id = CkJsonObjectW_stringOf(jResp,L"data[i].id"); linksSelf = CkJsonObjectW_stringOf(jResp,L"data[i].links.self"); v_type = CkJsonObjectW_stringOf(jResp,L"data[i].type"); j = 0; count_j = CkJsonObjectW_SizeOfArray(jResp,L"data[i].attributes.authorizationModels"); while (j < count_j) { CkJsonObjectW_putJ(jResp,j); strVal = CkJsonObjectW_stringOf(jResp,L"data[i].attributes.authorizationModels[j]"); j = j + 1; } j = 0; count_j = CkJsonObjectW_SizeOfArray(jResp,L"data[i].attributes.bulkPaymentsProductTypes"); while (j < count_j) { CkJsonObjectW_putJ(jResp,j); strVal = CkJsonObjectW_stringOf(jResp,L"data[i].attributes.bulkPaymentsProductTypes[j]"); j = j + 1; } j = 0; count_j = CkJsonObjectW_SizeOfArray(jResp,L"data[i].attributes.paymentsProductTypes"); while (j < count_j) { CkJsonObjectW_putJ(jResp,j); strVal = CkJsonObjectW_stringOf(jResp,L"data[i].attributes.paymentsProductTypes[j]"); j = j + 1; } j = 0; count_j = CkJsonObjectW_SizeOfArray(jResp,L"data[i].attributes.periodicPaymentsProductTypes"); while (j < count_j) { CkJsonObjectW_putJ(jResp,j); strVal = CkJsonObjectW_stringOf(jResp,L"data[i].attributes.periodicPaymentsProductTypes[j]"); j = j + 1; } i = i + 1; } CkCertW_Dispose(cert); CkDateTimeW_Dispose(dtNow); CkCrypt2W_Dispose(crypt2); CkStringBuilderW_Dispose(sbDigestHdrValue); CkStringBuilderW_Dispose(sbSigningString); CkPrivateKeyW_Dispose(privKey); CkRsaW_Dispose(rsa); CkStringBuilderW_Dispose(sbSigHeaderValue); CkHttpW_Dispose(http); CkStringBuilderW_Dispose(sbResponseBody); CkJsonObjectW_Dispose(jResp); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.