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
(PowerBuilder) ING Open Banking OAuth2 Client CredentialsDemonstrates how to get an access token for the ING Open Banking APIs using client credentials. For more information, see https://developer.ing.com/openbanking/get-started/openbanking
integer li_rc oleobject loo_Cert integer li_Success oleobject loo_BdPrivKey oleobject loo_PrivKey oleobject loo_Http oleobject loo_Crypt string ls_Payload string ls_PayloadDigest oleobject loo_Dt string ls_HttpMethod string ls_ReqPath oleobject loo_SbStringToSign oleobject loo_SigningPrivKey oleobject loo_Rsa string ls_B64Signature oleobject loo_SbAuthHdrVal oleobject loo_SbDigestHdrVal oleobject loo_Req oleobject loo_Resp oleobject loo_Json string ls_Kty string n string e string ls_Use string ls_Alg string ls_X5t string ls_Access_token integer li_Expires_in string ls_Scope string ls_Token_type string ls_Client_id integer i integer li_Count_i // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. loo_Cert = create oleobject // Use "Chilkat_9_5_0.Cert" for versions of Chilkat < 10.0.0 li_rc = loo_Cert.ConnectToNewObject("Chilkat.Cert") if li_rc < 0 then destroy loo_Cert MessageBox("Error","Connecting to COM object failed") return end if li_Success = loo_Cert.LoadFromFile("qa_data/certs_and_keys/ING/example_client_tls.cer") if li_Success = 0 then Write-Debug loo_Cert.LastErrorText destroy loo_Cert return end if loo_BdPrivKey = create oleobject // Use "Chilkat_9_5_0.BinData" for versions of Chilkat < 10.0.0 li_rc = loo_BdPrivKey.ConnectToNewObject("Chilkat.BinData") li_Success = loo_BdPrivKey.LoadFile("qa_data/certs_and_keys/ING/example_client_tls.key") if li_Success = 0 then Write-Debug "Failed to load example_client_tls.key" destroy loo_Cert destroy loo_BdPrivKey return end if // 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. loo_PrivKey = create oleobject // Use "Chilkat_9_5_0.PrivateKey" for versions of Chilkat < 10.0.0 li_rc = loo_PrivKey.ConnectToNewObject("Chilkat.PrivateKey") li_Success = loo_PrivKey.LoadAnyFormat(loo_BdPrivKey,"") if li_Success = 0 then Write-Debug loo_PrivKey.LastErrorText destroy loo_Cert destroy loo_BdPrivKey destroy loo_PrivKey return end if // Associate the private key with the certificate. li_Success = loo_Cert.SetPrivateKey(loo_PrivKey) if li_Success = 0 then Write-Debug loo_Cert.LastErrorText destroy loo_Cert destroy loo_BdPrivKey destroy loo_PrivKey return end if loo_Http = create oleobject // Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0 li_rc = loo_Http.ConnectToNewObject("Chilkat.Http") li_Success = loo_Http.SetSslClientCert(loo_Cert) if li_Success = 0 then Write-Debug loo_Http.LastErrorText destroy loo_Cert destroy loo_BdPrivKey destroy loo_PrivKey destroy loo_Http return end if // Calculate the Digest and add the "Digest" header. Do the equivalent of this: // payload="grant_type=client_credentials" // payloadDigest=`echo -n "$payload" | openssl dgst -binary -sha256 | openssl base64` // digest=SHA-256=$payloadDigest loo_Crypt = create oleobject // Use "Chilkat_9_5_0.Crypt2" for versions of Chilkat < 10.0.0 li_rc = loo_Crypt.ConnectToNewObject("Chilkat.Crypt2") loo_Crypt.HashAlgorithm = "SHA256" loo_Crypt.EncodingMode = "base64" ls_Payload = "grant_type=client_credentials" ls_PayloadDigest = loo_Crypt.HashStringENC(ls_Payload) // Calculate the current date/time and add the Date header. // reqDate=$(LC_TIME=en_US.UTF-8 date -u "+%a, %d %b %Y %H:%M:%S GMT") loo_Dt = create oleobject // Use "Chilkat_9_5_0.CkDateTime" for versions of Chilkat < 10.0.0 li_rc = loo_Dt.ConnectToNewObject("Chilkat.CkDateTime") loo_Dt.SetFromCurrentSystemTime() // The desire date/time format is the "RFC822" format. loo_Http.SetRequestHeader("Date",loo_Dt.GetAsRfc822(0)) // Calculate signature for signing your request // Duplicate the following code: // httpMethod="post" // reqPath="/oauth2/token" // signingString="(request-target): $httpMethod $reqPath // date: $reqDate // digest: $digest" // signature=`printf "$signingString" | openssl dgst -sha256 -sign "${certPath}example_client_signing.key" -passin "pass:changeit" | openssl base64 -A` ls_HttpMethod = "POST" ls_ReqPath = "/oauth2/token" loo_SbStringToSign = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_SbStringToSign.ConnectToNewObject("Chilkat.StringBuilder") loo_SbStringToSign.Append("(request-target): ") loo_SbStringToSign.Append(ls_HttpMethod) loo_SbStringToSign.ToLowercase() loo_SbStringToSign.Append(" ") loo_SbStringToSign.AppendLine(ls_ReqPath,0) loo_SbStringToSign.Append("date: ") loo_SbStringToSign.AppendLine(loo_Dt.GetAsRfc822(0),0) loo_SbStringToSign.Append("digest: SHA-256=") loo_SbStringToSign.Append(ls_PayloadDigest) loo_SigningPrivKey = create oleobject // Use "Chilkat_9_5_0.PrivateKey" for versions of Chilkat < 10.0.0 li_rc = loo_SigningPrivKey.ConnectToNewObject("Chilkat.PrivateKey") li_Success = loo_SigningPrivKey.LoadPemFile("qa_data/certs_and_keys/ING/example_client_signing.key") if li_Success = 0 then Write-Debug loo_SigningPrivKey.LastErrorText destroy loo_Cert destroy loo_BdPrivKey destroy loo_PrivKey destroy loo_Http destroy loo_Crypt destroy loo_Dt destroy loo_SbStringToSign destroy loo_SigningPrivKey return end if loo_Rsa = create oleobject // Use "Chilkat_9_5_0.Rsa" for versions of Chilkat < 10.0.0 li_rc = loo_Rsa.ConnectToNewObject("Chilkat.Rsa") li_Success = loo_Rsa.ImportPrivateKeyObj(loo_SigningPrivKey) if li_Success = 0 then Write-Debug loo_Rsa.LastErrorText destroy loo_Cert destroy loo_BdPrivKey destroy loo_PrivKey destroy loo_Http destroy loo_Crypt destroy loo_Dt destroy loo_SbStringToSign destroy loo_SigningPrivKey destroy loo_Rsa return end if loo_Rsa.EncodingMode = "base64" ls_B64Signature = loo_Rsa.SignStringENC(loo_SbStringToSign.GetAsString(),"SHA256") loo_SbAuthHdrVal = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_SbAuthHdrVal.ConnectToNewObject("Chilkat.StringBuilder") loo_SbAuthHdrVal.Append("Signature keyId=~"e77d776b-90af-4684-bebc-521e5b2614dd~",") loo_SbAuthHdrVal.Append("algorithm=~"rsa-sha256~",") loo_SbAuthHdrVal.Append("headers=~"(request-target) date digest~",") loo_SbAuthHdrVal.Append("signature=~"") loo_SbAuthHdrVal.Append(ls_B64Signature) loo_SbAuthHdrVal.Append("~"") loo_SbDigestHdrVal = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_SbDigestHdrVal.ConnectToNewObject("Chilkat.StringBuilder") loo_SbDigestHdrVal.Append("SHA-256=") loo_SbDigestHdrVal.Append(ls_PayloadDigest) // Do the following CURL statement: // curl -i -X POST "${httpHost}${reqPath}" \ // -H 'Accept: application/json' \ // -H 'Content-Type: application/x-www-form-urlencoded' \ // -H "Digest: ${digest}" \ // -H "Date: ${reqDate}" \ // -H "authorization: Signature keyId=\"$keyId\",algorithm=\"rsa-sha256\",headers=\"(request-target) date digest\",signature=\"$signature\"" \ // -d "${payload}" \ // --cert "${certPath}tlsCert.crt" \ // --key "${certPath}tlsCert.key" loo_Req = create oleobject // Use "Chilkat_9_5_0.HttpRequest" for versions of Chilkat < 10.0.0 li_rc = loo_Req.ConnectToNewObject("Chilkat.HttpRequest") loo_Req.AddParam("grant_type","client_credentials") loo_Req.AddHeader("Accept","application/json") loo_Req.AddHeader("Date",loo_Dt.GetAsRfc822(0)) loo_Req.AddHeader("Digest",loo_SbDigestHdrVal.GetAsString()) loo_Req.AddHeader("Authorization",loo_SbAuthHdrVal.GetAsString()) loo_Resp = loo_Http.PostUrlEncoded("https://api.sandbox.ing.com/oauth2/token",loo_Req) if loo_Http.LastMethodSuccess = 0 then Write-Debug loo_Http.LastErrorText destroy loo_Cert destroy loo_BdPrivKey destroy loo_PrivKey destroy loo_Http destroy loo_Crypt destroy loo_Dt destroy loo_SbStringToSign destroy loo_SigningPrivKey destroy loo_Rsa destroy loo_SbAuthHdrVal destroy loo_SbDigestHdrVal destroy loo_Req return end if // If successful, the status code = 200 Write-Debug "Response Status Code: " + string(loo_Resp.StatusCode) Write-Debug loo_Resp.BodyStr loo_Json = create oleobject // Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject") loo_Json.Load(loo_Resp.BodyStr) destroy loo_Resp loo_Json.EmitCompact = 0 Write-Debug loo_Json.Emit() // A successful response contains an access token such as: // { // "access_token": "eyJhbGc ... bxI_SoPOBH9xmoM", // "expires_in": 905, // "scope": "payment-requests:view payment-requests:create payment-requests:close greetings:view virtual-ledger-accounts:fund-reservation:create virtual-ledger-accounts:fund-reservation:delete virtual-ledger-accounts:balance:view", // "token_type": "Bearer", // "keys": [ // { // "kty": "RSA", // "n": "3l3rdz4...04VPkdV", // "e": "AQAB", // "use": "sig", // "alg": "RS256", // "x5t": "3c396700fc8cd709cf9cb5452a22bcde76985851" // } // ], // "client_id": "e77d776b-90af-4684-bebc-521e5b2614dd" // } // Use this online tool to generate parsing code from sample JSON: // Generate Parsing Code from JSON ls_Access_token = loo_Json.StringOf("access_token") li_Expires_in = loo_Json.IntOf("expires_in") ls_Scope = loo_Json.StringOf("scope") ls_Token_type = loo_Json.StringOf("token_type") ls_Client_id = loo_Json.StringOf("client_id") i = 0 li_Count_i = loo_Json.SizeOfArray("keys") do while i < li_Count_i loo_Json.I = i ls_Kty = loo_Json.StringOf("keys[i].kty") n = loo_Json.StringOf("keys[i].n") e = loo_Json.StringOf("keys[i].e") ls_Use = loo_Json.StringOf("keys[i].use") ls_Alg = loo_Json.StringOf("keys[i].alg") ls_X5t = loo_Json.StringOf("keys[i].x5t") i = i + 1 loop // This example will save the JSON containing the access key to a file so that // a subsequent example can load it and then use the access key for a request, such as to create a payment request. loo_Json.WriteFile("qa_data/tokens/ing_access_token.json") destroy loo_Cert destroy loo_BdPrivKey destroy loo_PrivKey destroy loo_Http destroy loo_Crypt destroy loo_Dt destroy loo_SbStringToSign destroy loo_SigningPrivKey destroy loo_Rsa destroy loo_SbAuthHdrVal destroy loo_SbDigestHdrVal destroy loo_Req destroy loo_Json |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.