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) ABN AMRO OAuth2 Client Credentials AuthenticationDemonstrates how to obtain an access token for an ABN AMRO online API using OAuth2 with the Client Credentials flow. For more information, see https://developer.abnamro.com/api/payment-initiation-v1/payment-initiation-tutorial
#include <C_CkCertW.h> #include <C_CkBinDataW.h> #include <C_CkPrivateKeyW.h> #include <C_CkHttpW.h> #include <C_CkHttpRequestW.h> #include <C_CkHttpResponseW.h> #include <C_CkJsonObjectW.h> void ChilkatSample(void) { HCkCertW cert; BOOL success; HCkBinDataW bdKey; HCkPrivateKeyW privKey; HCkHttpW http; HCkHttpRequestW req; HCkHttpResponseW resp; HCkJsonObjectW json; // 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' cert = CkCertW_Create(); success = CkCertW_LoadFromFile(cert,L"qa_data/certs/TPPCertificate.cer"); if (success != TRUE) { wprintf(L"%s\n",CkCertW_lastErrorText(cert)); CkCertW_Dispose(cert); return; } bdKey = CkBinDataW_Create(); success = CkBinDataW_LoadFile(bdKey,L"qa_data/certs/TPPprivateKey.key"); privKey = CkPrivateKeyW_Create(); success = CkPrivateKeyW_LoadAnyFormat(privKey,bdKey,L"passwordIfNeeded"); if (success != TRUE) { wprintf(L"%s\n",CkPrivateKeyW_lastErrorText(privKey)); CkCertW_Dispose(cert); CkBinDataW_Dispose(bdKey); CkPrivateKeyW_Dispose(privKey); return; } success = CkCertW_SetPrivateKey(cert,privKey); if (success != TRUE) { wprintf(L"%s\n",CkCertW_lastErrorText(cert)); CkCertW_Dispose(cert); CkBinDataW_Dispose(bdKey); CkPrivateKeyW_Dispose(privKey); return; } http = CkHttpW_Create(); success = CkHttpW_SetSslClientCert(http,cert); if (success != TRUE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkCertW_Dispose(cert); CkBinDataW_Dispose(bdKey); CkPrivateKeyW_Dispose(privKey); CkHttpW_Dispose(http); return; } req = CkHttpRequestW_Create(); CkHttpRequestW_AddParam(req,L"grant_type",L"client_credentials"); CkHttpRequestW_AddParam(req,L"client_id",L"TPP_test"); CkHttpRequestW_AddParam(req,L"scope",L"psd2:payment:sepa:write psd2:payment:sepa:read"); resp = CkHttpW_PostUrlEncoded(http,L"https://auth-sandbox.connect.abnamro.com:8443/as/token.oauth2",req); if (CkHttpW_getLastMethodSuccess(http) == FALSE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkCertW_Dispose(cert); CkBinDataW_Dispose(bdKey); CkPrivateKeyW_Dispose(privKey); CkHttpW_Dispose(http); CkHttpRequestW_Dispose(req); return; } if (CkHttpResponseW_getStatusCode(resp) != 200) { wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp)); CkHttpResponseW_Dispose(resp); CkCertW_Dispose(cert); CkBinDataW_Dispose(bdKey); CkPrivateKeyW_Dispose(privKey); CkHttpW_Dispose(http); CkHttpRequestW_Dispose(req); return; } // Get the JSON result: // {"access_token":"TIhycwl8rfrZPkXGw15mwldASAAK","token_type":"Bearer","expires_in":7200} json = CkJsonObjectW_Create(); CkJsonObjectW_Load(json,CkHttpResponseW_bodyStr(resp)); wprintf(L"access_token: %s\n",CkJsonObjectW_stringOf(json,L"access_token")); wprintf(L"token_type: %s\n",CkJsonObjectW_stringOf(json,L"token_type")); wprintf(L"expires_in: %s\n",CkJsonObjectW_stringOf(json,L"expires_in")); CkHttpResponseW_Dispose(resp); CkCertW_Dispose(cert); CkBinDataW_Dispose(bdKey); CkPrivateKeyW_Dispose(privKey); CkHttpW_Dispose(http); CkHttpRequestW_Dispose(req); CkJsonObjectW_Dispose(json); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.