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
(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_CkCert.h> #include <C_CkDateTime.h> #include <C_CkCrypt2.h> #include <C_CkStringBuilder.h> #include <C_CkPrivateKey.h> #include <C_CkRsa.h> #include <C_CkHttp.h> #include <C_CkJsonObject.h> void ChilkatSample(void) { HCkCert cert; BOOL success; HCkDateTime dtNow; const char *created; HCkCrypt2 crypt2; HCkStringBuilder sbDigestHdrValue; const char *request_target; HCkStringBuilder sbSigningString; const char *signed_headers_list; HCkPrivateKey privKey; HCkRsa rsa; const char *sigBase64; HCkStringBuilder sbSigHeaderValue; HCkHttp http; HCkStringBuilder sbResponseBody; HCkJsonObject jResp; int respStatusCode; const char *attributesBic; BOOL attributesBulkPaymentsEnabled; const char *attributesCountry; BOOL attributesFinancialInstitutionCustomerReferenceRequired; BOOL attributesFutureDatedPaymentsAllowed; const char *attributesLogoUrl; const char *attributesMaintenanceFrom; const char *attributesMaintenanceTo; const char *attributesMaintenanceType; const char *attributesMaxRequestedAccountReferences; int attributesMinRequestedAccountReferences; const char *attributesName; BOOL attributesPaymentsEnabled; BOOL attributesPeriodicPaymentsEnabled; const char *attributesPrimaryColor; BOOL attributesRequiresCredentialStorage; BOOL attributesRequiresCustomerIpAddress; BOOL attributesSandbox; const char *attributesSecondaryColor; const char *attributesSharedBrandName; const char *attributesSharedBrandReference; const char *attributesStatus; const char *id; const char *linksSelf; const char *v_type; int j; int count_j; const char *strVal; const char *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 = CkCert_Create(); success = CkCert_LoadPfxFile(cert,"qa_data/pfx/my_ibanity_certificate.pfx","my_pfx_password"); if (success == FALSE) { printf("%s\n",CkCert_lastErrorText(cert)); CkCert_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 = CkDateTime_Create(); CkDateTime_SetFromCurrentSystemTime(dtNow); created = CkDateTime_getAsUnixTimeStr(dtNow,FALSE); crypt2 = CkCrypt2_Create(); CkCrypt2_putHashAlgorithm(crypt2,"sha512"); CkCrypt2_putEncodingMode(crypt2,"base64"); sbDigestHdrValue = CkStringBuilder_Create(); CkStringBuilder_Append(sbDigestHdrValue,"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. CkStringBuilder_Append(sbDigestHdrValue,CkCrypt2_hashStringENC(crypt2,"")); printf("Generated Digest\n"); printf("%s\n",CkStringBuilder_getAsString(sbDigestHdrValue)); request_target = "get /xs2a/financial-institutions"; sbSigningString = CkStringBuilder_Create(); CkStringBuilder_Append(sbSigningString,"(request-target): "); CkStringBuilder_AppendLine(sbSigningString,request_target,FALSE); CkStringBuilder_Append(sbSigningString,"host: "); CkStringBuilder_AppendLine(sbSigningString,"api.ibanity.com",FALSE); CkStringBuilder_Append(sbSigningString,"digest: "); CkStringBuilder_AppendLine(sbSigningString,CkStringBuilder_getAsString(sbDigestHdrValue),FALSE); CkStringBuilder_Append(sbSigningString,"(created): "); CkStringBuilder_Append(sbSigningString,created); // ibanity-idempotency-key is not used with GET requests. printf("Signing String:\n"); printf("%s\n",CkStringBuilder_getAsString(sbSigningString)); signed_headers_list = "(request-target) host digest (created)"; privKey = CkPrivateKey_Create(); success = CkPrivateKey_LoadEncryptedPemFile(privKey,"my_ibanity_signature_private_key.pem","pem_password"); if (success == FALSE) { printf("%s\n",CkPrivateKey_lastErrorText(privKey)); CkCert_Dispose(cert); CkDateTime_Dispose(dtNow); CkCrypt2_Dispose(crypt2); CkStringBuilder_Dispose(sbDigestHdrValue); CkStringBuilder_Dispose(sbSigningString); CkPrivateKey_Dispose(privKey); return; } rsa = CkRsa_Create(); CkRsa_putPssSaltLen(rsa,32); CkRsa_putEncodingMode(rsa,"base64"); // Use the RSASSA-PSS signature algorithm CkRsa_putOaepPadding(rsa,TRUE); success = CkRsa_ImportPrivateKeyObj(rsa,privKey); if (success == FALSE) { printf("%s\n",CkRsa_lastErrorText(rsa)); CkCert_Dispose(cert); CkDateTime_Dispose(dtNow); CkCrypt2_Dispose(crypt2); CkStringBuilder_Dispose(sbDigestHdrValue); CkStringBuilder_Dispose(sbSigningString); CkPrivateKey_Dispose(privKey); CkRsa_Dispose(rsa); return; } // Sign the signing string. sigBase64 = CkRsa_signStringENC(rsa,CkStringBuilder_getAsString(sbSigningString),"sha-256"); if (CkRsa_getLastMethodSuccess(rsa) == FALSE) { printf("%s\n",CkRsa_lastErrorText(rsa)); CkCert_Dispose(cert); CkDateTime_Dispose(dtNow); CkCrypt2_Dispose(crypt2); CkStringBuilder_Dispose(sbDigestHdrValue); CkStringBuilder_Dispose(sbSigningString); CkPrivateKey_Dispose(privKey); CkRsa_Dispose(rsa); return; } printf("Signature:\n"); printf("%s\n",sigBase64); // Build the signature header value. sbSigHeaderValue = CkStringBuilder_Create(); CkStringBuilder_Append(sbSigHeaderValue,"keyId=\""); // Use your identifier for the application's signature certificate, obtained from the Developer Portal CkStringBuilder_Append(sbSigHeaderValue,"a0ce296d-84c8-4bd5-8eb4-de0339950cfa"); CkStringBuilder_Append(sbSigHeaderValue,"\",created="); CkStringBuilder_Append(sbSigHeaderValue,created); CkStringBuilder_Append(sbSigHeaderValue,",algorithm=\"hs2019\",headers=\""); CkStringBuilder_Append(sbSigHeaderValue,signed_headers_list); CkStringBuilder_Append(sbSigHeaderValue,"\",signature=\""); CkStringBuilder_Append(sbSigHeaderValue,sigBase64); CkStringBuilder_Append(sbSigHeaderValue,"\""); // Send the GET request.. http = CkHttp_Create(); success = CkHttp_SetSslClientCert(http,cert); if (success == FALSE) { printf("%s\n",CkHttp_lastErrorText(http)); CkCert_Dispose(cert); CkDateTime_Dispose(dtNow); CkCrypt2_Dispose(crypt2); CkStringBuilder_Dispose(sbDigestHdrValue); CkStringBuilder_Dispose(sbSigningString); CkPrivateKey_Dispose(privKey); CkRsa_Dispose(rsa); CkStringBuilder_Dispose(sbSigHeaderValue); CkHttp_Dispose(http); return; } CkHttp_SetRequestHeader(http,"Signature",CkStringBuilder_getAsString(sbSigHeaderValue)); CkHttp_SetRequestHeader(http,"Digest",CkStringBuilder_getAsString(sbDigestHdrValue)); sbResponseBody = CkStringBuilder_Create(); success = CkHttp_QuickGetSb(http,"https://api.ibanity.com/xs2a/financial-institutions",sbResponseBody); if (success == FALSE) { printf("%s\n",CkHttp_lastErrorText(http)); CkCert_Dispose(cert); CkDateTime_Dispose(dtNow); CkCrypt2_Dispose(crypt2); CkStringBuilder_Dispose(sbDigestHdrValue); CkStringBuilder_Dispose(sbSigningString); CkPrivateKey_Dispose(privKey); CkRsa_Dispose(rsa); CkStringBuilder_Dispose(sbSigHeaderValue); CkHttp_Dispose(http); CkStringBuilder_Dispose(sbResponseBody); return; } jResp = CkJsonObject_Create(); CkJsonObject_LoadSb(jResp,sbResponseBody); CkJsonObject_putEmitCompact(jResp,FALSE); printf("Response Body:\n"); printf("%s\n",CkJsonObject_emit(jResp)); respStatusCode = CkHttp_getLastStatus(http); printf("Response Status Code = %d\n",respStatusCode); if (respStatusCode >= 400) { printf("Response Header:\n"); printf("%s\n",CkHttp_lastHeader(http)); printf("Failed.\n"); CkCert_Dispose(cert); CkDateTime_Dispose(dtNow); CkCrypt2_Dispose(crypt2); CkStringBuilder_Dispose(sbDigestHdrValue); CkStringBuilder_Dispose(sbSigningString); CkPrivateKey_Dispose(privKey); CkRsa_Dispose(rsa); CkStringBuilder_Dispose(sbSigHeaderValue); CkHttp_Dispose(http); CkStringBuilder_Dispose(sbResponseBody); CkJsonObject_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 = CkJsonObject_stringOf(jResp,"links.first"); metaPagingLimit = CkJsonObject_IntOf(jResp,"meta.paging.limit"); i = 0; count_i = CkJsonObject_SizeOfArray(jResp,"data"); while (i < count_i) { CkJsonObject_putI(jResp,i); attributesBic = CkJsonObject_stringOf(jResp,"data[i].attributes.bic"); attributesBulkPaymentsEnabled = CkJsonObject_BoolOf(jResp,"data[i].attributes.bulkPaymentsEnabled"); attributesCountry = CkJsonObject_stringOf(jResp,"data[i].attributes.country"); attributesFinancialInstitutionCustomerReferenceRequired = CkJsonObject_BoolOf(jResp,"data[i].attributes.financialInstitutionCustomerReferenceRequired"); attributesFutureDatedPaymentsAllowed = CkJsonObject_BoolOf(jResp,"data[i].attributes.futureDatedPaymentsAllowed"); attributesLogoUrl = CkJsonObject_stringOf(jResp,"data[i].attributes.logoUrl"); attributesMaintenanceFrom = CkJsonObject_stringOf(jResp,"data[i].attributes.maintenanceFrom"); attributesMaintenanceTo = CkJsonObject_stringOf(jResp,"data[i].attributes.maintenanceTo"); attributesMaintenanceType = CkJsonObject_stringOf(jResp,"data[i].attributes.maintenanceType"); attributesMaxRequestedAccountReferences = CkJsonObject_stringOf(jResp,"data[i].attributes.maxRequestedAccountReferences"); attributesMinRequestedAccountReferences = CkJsonObject_IntOf(jResp,"data[i].attributes.minRequestedAccountReferences"); attributesName = CkJsonObject_stringOf(jResp,"data[i].attributes.name"); attributesPaymentsEnabled = CkJsonObject_BoolOf(jResp,"data[i].attributes.paymentsEnabled"); attributesPeriodicPaymentsEnabled = CkJsonObject_BoolOf(jResp,"data[i].attributes.periodicPaymentsEnabled"); attributesPrimaryColor = CkJsonObject_stringOf(jResp,"data[i].attributes.primaryColor"); attributesRequiresCredentialStorage = CkJsonObject_BoolOf(jResp,"data[i].attributes.requiresCredentialStorage"); attributesRequiresCustomerIpAddress = CkJsonObject_BoolOf(jResp,"data[i].attributes.requiresCustomerIpAddress"); attributesSandbox = CkJsonObject_BoolOf(jResp,"data[i].attributes.sandbox"); attributesSecondaryColor = CkJsonObject_stringOf(jResp,"data[i].attributes.secondaryColor"); attributesSharedBrandName = CkJsonObject_stringOf(jResp,"data[i].attributes.sharedBrandName"); attributesSharedBrandReference = CkJsonObject_stringOf(jResp,"data[i].attributes.sharedBrandReference"); attributesStatus = CkJsonObject_stringOf(jResp,"data[i].attributes.status"); id = CkJsonObject_stringOf(jResp,"data[i].id"); linksSelf = CkJsonObject_stringOf(jResp,"data[i].links.self"); v_type = CkJsonObject_stringOf(jResp,"data[i].type"); j = 0; count_j = CkJsonObject_SizeOfArray(jResp,"data[i].attributes.authorizationModels"); while (j < count_j) { CkJsonObject_putJ(jResp,j); strVal = CkJsonObject_stringOf(jResp,"data[i].attributes.authorizationModels[j]"); j = j + 1; } j = 0; count_j = CkJsonObject_SizeOfArray(jResp,"data[i].attributes.bulkPaymentsProductTypes"); while (j < count_j) { CkJsonObject_putJ(jResp,j); strVal = CkJsonObject_stringOf(jResp,"data[i].attributes.bulkPaymentsProductTypes[j]"); j = j + 1; } j = 0; count_j = CkJsonObject_SizeOfArray(jResp,"data[i].attributes.paymentsProductTypes"); while (j < count_j) { CkJsonObject_putJ(jResp,j); strVal = CkJsonObject_stringOf(jResp,"data[i].attributes.paymentsProductTypes[j]"); j = j + 1; } j = 0; count_j = CkJsonObject_SizeOfArray(jResp,"data[i].attributes.periodicPaymentsProductTypes"); while (j < count_j) { CkJsonObject_putJ(jResp,j); strVal = CkJsonObject_stringOf(jResp,"data[i].attributes.periodicPaymentsProductTypes[j]"); j = j + 1; } i = i + 1; } CkCert_Dispose(cert); CkDateTime_Dispose(dtNow); CkCrypt2_Dispose(crypt2); CkStringBuilder_Dispose(sbDigestHdrValue); CkStringBuilder_Dispose(sbSigningString); CkPrivateKey_Dispose(privKey); CkRsa_Dispose(rsa); CkStringBuilder_Dispose(sbSigHeaderValue); CkHttp_Dispose(http); CkStringBuilder_Dispose(sbResponseBody); CkJsonObject_Dispose(jResp); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.