Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

AutoIt Web API Examples

Primary Categories

ABN AMRO
AWS Secrets Manager
AWS Security Token Service
AWS Translate
Activix CRM
Adyen
Alibaba Cloud OSS
Amazon Cognito
Amazon DynamoDB
Amazon MWS
Amazon Pay
Amazon Rekognition
Amazon SP-API
Amazon Voice ID
Aruba Fatturazione
Azure Maps
Azure Monitor
Azure OAuth2
Azure Storage Accounts
Backblaze S3
Banco Inter
Belgian eHealth Platform
Bitfinex v2 REST
Bluzone
BrickLink
Bunny CDN
CallRail
CardConnect
Cerved
ClickBank
Clickatell
Cloudfare
Constant Contact
DocuSign
Duo Auth MFA
ETrade
Ecwid
Egypt ITIDA
Egypt eReceipt
Etsy
Facebook
Faire
Frame.io
GeoOp
GetHarvest
Global Payments
Google People
Google Search Console
Google Translate
Google Vision
Hungary NAV Invoicing
IBM Text to Speech
Ibanity
IntakeQ
JCC Cyprus
Jira
Lightspeed
MYOB
Magento
Mailgun
Malaysia MyInvois

Mastercard
MedTunnel
MercadoLibre
MessageMedia
Microsoft Calendar
Microsoft Group
Microsoft Tasks and Plans
Microsoft Teams
Moody's
Okta OAuth/OIDC
OneLogin OIDC
OneNote
OpenAI ChatGPT
PRODA
PayPal
Paynow.pl
Peoplevox
Populi
QuickBooks
Rabobank
Refinitiv
Royal Mail OBA
SCiS Schools Catalogue
SII Chile
SMSAPI
SOAP finkok.com
Salesforce
SendGrid
Shippo
Shopify
Shopware
Shopware 6
SimpleTexting
Square
Stripe
SugarCRM
TicketBAI
TikTok Shop
Trello
Twilio
Twitter API v2
Twitter v1
UPS
UniPin
VoiceBase
Vonage
WaTrend
Walmart v3
Wasabi
WhatsApp
WiX
WooCommerce
WordPress
Xero
Yahoo Mail
Yapily
Yousign
ZATCA
Zendesk
Zoom
_Miscellaneous_
eBay
effectconnect
hacienda.go.cr

 

 

 

(AutoIt) ING Open Banking OAuth2 Client Credentials

Demonstrates 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

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

; This example requires the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.

$oCert = ObjCreate("Chilkat.Cert")
Local $bSuccess = $oCert.LoadFromFile("qa_data/certs_and_keys/ING/example_client_tls.cer")
If ($bSuccess = False) Then
    ConsoleWrite($oCert.LastErrorText & @CRLF)
    Exit
EndIf

$oBdPrivKey = ObjCreate("Chilkat.BinData")
$bSuccess = $oBdPrivKey.LoadFile("qa_data/certs_and_keys/ING/example_client_tls.key")
If ($bSuccess = False) Then
    ConsoleWrite("Failed to load example_client_tls.key" & @CRLF)
    Exit
EndIf

; 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.

$oPrivKey = ObjCreate("Chilkat.PrivateKey")
$bSuccess = $oPrivKey.LoadAnyFormat($oBdPrivKey,"")
If ($bSuccess = False) Then
    ConsoleWrite($oPrivKey.LastErrorText & @CRLF)
    Exit
EndIf

; Associate the private key with the certificate.
$bSuccess = $oCert.SetPrivateKey($oPrivKey)
If ($bSuccess = False) Then
    ConsoleWrite($oCert.LastErrorText & @CRLF)
    Exit
EndIf

$oHttp = ObjCreate("Chilkat.Http")

$bSuccess = $oHttp.SetSslClientCert($oCert)
If ($bSuccess = False) Then
    ConsoleWrite($oHttp.LastErrorText & @CRLF)
    Exit
EndIf

; 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
$oCrypt = ObjCreate("Chilkat.Crypt2")
$oCrypt.HashAlgorithm = "SHA256"
$oCrypt.EncodingMode = "base64"
Local $sPayload = "grant_type=client_credentials"
Local $sPayloadDigest = $oCrypt.HashStringENC($sPayload)

; 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")  
$oDt = ObjCreate("Chilkat.CkDateTime")
$oDt.SetFromCurrentSystemTime()
; The desire date/time format is the "RFC822" format.
$oHttp.SetRequestHeader "Date",$oDt.GetAsRfc822(False)

; 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`

Local $sHttpMethod = "POST"
Local $sReqPath = "/oauth2/token"

$oSbStringToSign = ObjCreate("Chilkat.StringBuilder")
$oSbStringToSign.Append("(request-target): ")
$oSbStringToSign.Append($sHttpMethod)
$oSbStringToSign.ToLowercase()
$oSbStringToSign.Append(" ")
$oSbStringToSign.AppendLine($sReqPath,False)

$oSbStringToSign.Append("date: ")
$oSbStringToSign.AppendLine($oDt.GetAsRfc822(False),False)

$oSbStringToSign.Append("digest: SHA-256=")
$oSbStringToSign.Append($sPayloadDigest)

$oSigningPrivKey = ObjCreate("Chilkat.PrivateKey")
$bSuccess = $oSigningPrivKey.LoadPemFile("qa_data/certs_and_keys/ING/example_client_signing.key")
If ($bSuccess = False) Then
    ConsoleWrite($oSigningPrivKey.LastErrorText & @CRLF)
    Exit
EndIf

$oRsa = ObjCreate("Chilkat.Rsa")
$bSuccess = $oRsa.ImportPrivateKeyObj($oSigningPrivKey)
If ($bSuccess = False) Then
    ConsoleWrite($oRsa.LastErrorText & @CRLF)
    Exit
EndIf

$oRsa.EncodingMode = "base64"
Local $sB64Signature = $oRsa.SignStringENC($oSbStringToSign.GetAsString(),"SHA256")

$oSbAuthHdrVal = ObjCreate("Chilkat.StringBuilder")
$oSbAuthHdrVal.Append("Signature keyId=""e77d776b-90af-4684-bebc-521e5b2614dd"",")
$oSbAuthHdrVal.Append("algorithm=""rsa-sha256"",")
$oSbAuthHdrVal.Append("headers=""(request-target) date digest"",")
$oSbAuthHdrVal.Append("signature=""")
$oSbAuthHdrVal.Append($sB64Signature)
$oSbAuthHdrVal.Append("""")

$oSbDigestHdrVal = ObjCreate("Chilkat.StringBuilder")
$oSbDigestHdrVal.Append("SHA-256=")
$oSbDigestHdrVal.Append($sPayloadDigest)

; 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"

$oReq = ObjCreate("Chilkat.HttpRequest")
$oReq.AddParam "grant_type","client_credentials"
$oReq.AddHeader "Accept","application/json"
$oReq.AddHeader "Date",$oDt.GetAsRfc822(False)
$oReq.AddHeader "Digest",$oSbDigestHdrVal.GetAsString()
$oReq.AddHeader "Authorization",$oSbAuthHdrVal.GetAsString()
Local $oResp = $oHttp.PostUrlEncoded("https://api.sandbox.ing.com/oauth2/token",$oReq)
If ($oHttp.LastMethodSuccess = False) Then
    ConsoleWrite($oHttp.LastErrorText & @CRLF)
    Exit
EndIf

; If successful, the status code = 200
ConsoleWrite("Response Status Code: " & $oResp.StatusCode & @CRLF)
ConsoleWrite($oResp.BodyStr & @CRLF)

$oJson = ObjCreate("Chilkat.JsonObject")
$oJson.Load($oResp.BodyStr)

$oJson.EmitCompact = False
ConsoleWrite($oJson.Emit() & @CRLF)

; 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

Local $sKty
Local $sN
Local $sE
Local $sUse
Local $sAlg
Local $sX5t

Local $sAccess_token = $oJson.StringOf("access_token")
Local $iExpires_in = $oJson.IntOf("expires_in")
Local $scope = $oJson.StringOf("scope")
Local $sToken_type = $oJson.StringOf("token_type")
Local $sClient_id = $oJson.StringOf("client_id")
Local $i = 0
Local $iCount_i = $oJson.SizeOfArray("keys")
While $i < $iCount_i
    $oJson.I = $i
    $sKty = $oJson.StringOf("keys[i].kty")
    $sN = $oJson.StringOf("keys[i].n")
    $sE = $oJson.StringOf("keys[i].e")
    $sUse = $oJson.StringOf("keys[i].use")
    $sAlg = $oJson.StringOf("keys[i].alg")
    $sX5t = $oJson.StringOf("keys[i].x5t")
    $i = $i + 1
Wend

; 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.
$oJson.WriteFile("qa_data/tokens/ing_access_token.json")

 

© 2000-2024 Chilkat Software, Inc. All Rights Reserved.