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
(PureBasic) 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
IncludeFile "CkBinData.pb" IncludeFile "CkPrivateKey.pb" IncludeFile "CkHttp.pb" IncludeFile "CkJsonObject.pb" IncludeFile "CkHttpRequest.pb" IncludeFile "CkHttpResponse.pb" IncludeFile "CkCert.pb" Procedure ChilkatExample() ; 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.i = CkCert::ckCreate() If cert.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success.i = CkCert::ckLoadFromFile(cert,"qa_data/certs/TPPCertificate.cer") If success <> 1 Debug CkCert::ckLastErrorText(cert) CkCert::ckDispose(cert) ProcedureReturn EndIf bdKey.i = CkBinData::ckCreate() If bdKey.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success = CkBinData::ckLoadFile(bdKey,"qa_data/certs/TPPprivateKey.key") privKey.i = CkPrivateKey::ckCreate() If privKey.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success = CkPrivateKey::ckLoadAnyFormat(privKey,bdKey,"passwordIfNeeded") If success <> 1 Debug CkPrivateKey::ckLastErrorText(privKey) CkCert::ckDispose(cert) CkBinData::ckDispose(bdKey) CkPrivateKey::ckDispose(privKey) ProcedureReturn EndIf success = CkCert::ckSetPrivateKey(cert,privKey) If success <> 1 Debug CkCert::ckLastErrorText(cert) CkCert::ckDispose(cert) CkBinData::ckDispose(bdKey) CkPrivateKey::ckDispose(privKey) ProcedureReturn EndIf http.i = CkHttp::ckCreate() If http.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success = CkHttp::ckSetSslClientCert(http,cert) If success <> 1 Debug CkHttp::ckLastErrorText(http) CkCert::ckDispose(cert) CkBinData::ckDispose(bdKey) CkPrivateKey::ckDispose(privKey) CkHttp::ckDispose(http) ProcedureReturn EndIf req.i = CkHttpRequest::ckCreate() If req.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkHttpRequest::ckAddParam(req,"grant_type","client_credentials") CkHttpRequest::ckAddParam(req,"client_id","TPP_test") CkHttpRequest::ckAddParam(req,"scope","psd2:payment:sepa:write psd2:payment:sepa:read") resp.i = CkHttp::ckPostUrlEncoded(http,"https://auth-sandbox.connect.abnamro.com:8443/as/token.oauth2",req) If CkHttp::ckLastMethodSuccess(http) = 0 Debug CkHttp::ckLastErrorText(http) CkCert::ckDispose(cert) CkBinData::ckDispose(bdKey) CkPrivateKey::ckDispose(privKey) CkHttp::ckDispose(http) CkHttpRequest::ckDispose(req) ProcedureReturn EndIf If CkHttpResponse::ckStatusCode(resp) <> 200 Debug CkHttpResponse::ckBodyStr(resp) CkHttpResponse::ckDispose(resp) CkCert::ckDispose(cert) CkBinData::ckDispose(bdKey) CkPrivateKey::ckDispose(privKey) CkHttp::ckDispose(http) CkHttpRequest::ckDispose(req) ProcedureReturn EndIf ; Get the JSON result: ; {"access_token":"TIhycwl8rfrZPkXGw15mwldASAAK","token_type":"Bearer","expires_in":7200} json.i = CkJsonObject::ckCreate() If json.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::ckLoad(json,CkHttpResponse::ckBodyStr(resp)) Debug "access_token: " + CkJsonObject::ckStringOf(json,"access_token") Debug "token_type: " + CkJsonObject::ckStringOf(json,"token_type") Debug "expires_in: " + CkJsonObject::ckStringOf(json,"expires_in") CkHttpResponse::ckDispose(resp) CkCert::ckDispose(cert) CkBinData::ckDispose(bdKey) CkPrivateKey::ckDispose(privKey) CkHttp::ckDispose(http) CkHttpRequest::ckDispose(req) CkJsonObject::ckDispose(json) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.