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

Visual FoxPro 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
Jira
Lightspeed
MYOB
Magento
Mailgun

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
SendGrid
Shippo
Shopify
Shopware
Shopware 6
SimpleTexting
Square
Stripe
SugarCRM
TicketBAI
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

 

 

 

(Visual FoxPro) 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

LOCAL loCert
LOCAL lnSuccess
LOCAL loBdPrivKey
LOCAL loPrivKey
LOCAL loHttp
LOCAL loCrypt
LOCAL lcPayload
LOCAL lcPayloadDigest
LOCAL loDt
LOCAL lcHttpMethod
LOCAL lcReqPath
LOCAL loSbStringToSign
LOCAL loSigningPrivKey
LOCAL loRsa
LOCAL lcB64Signature
LOCAL loSbAuthHdrVal
LOCAL loSbDigestHdrVal
LOCAL loReq
LOCAL loResp
LOCAL loJson
LOCAL lcKty
LOCAL n
LOCAL e
LOCAL lcUse
LOCAL lcAlg
LOCAL lcX5t
LOCAL lcAccess_token
LOCAL lnExpires_in
LOCAL lcScope
LOCAL lcToken_type
LOCAL lcClient_id
LOCAL i
LOCAL lnCount_i

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

loCert = CreateObject('Chilkat_9_5_0.Cert')
lnSuccess = loCert.LoadFromFile("qa_data/certs_and_keys/ING/example_client_tls.cer")
IF (lnSuccess = 0) THEN
    ? loCert.LastErrorText
    RELEASE loCert
    CANCEL
ENDIF

loBdPrivKey = CreateObject('Chilkat_9_5_0.BinData')
lnSuccess = loBdPrivKey.LoadFile("qa_data/certs_and_keys/ING/example_client_tls.key")
IF (lnSuccess = 0) THEN
    ? "Failed to load example_client_tls.key"
    RELEASE loCert
    RELEASE loBdPrivKey
    CANCEL
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.

loPrivKey = CreateObject('Chilkat_9_5_0.PrivateKey')
lnSuccess = loPrivKey.LoadAnyFormat(loBdPrivKey,"")
IF (lnSuccess = 0) THEN
    ? loPrivKey.LastErrorText
    RELEASE loCert
    RELEASE loBdPrivKey
    RELEASE loPrivKey
    CANCEL
ENDIF

* Associate the private key with the certificate.
lnSuccess = loCert.SetPrivateKey(loPrivKey)
IF (lnSuccess = 0) THEN
    ? loCert.LastErrorText
    RELEASE loCert
    RELEASE loBdPrivKey
    RELEASE loPrivKey
    CANCEL
ENDIF

loHttp = CreateObject('Chilkat_9_5_0.Http')

lnSuccess = loHttp.SetSslClientCert(loCert)
IF (lnSuccess = 0) THEN
    ? loHttp.LastErrorText
    RELEASE loCert
    RELEASE loBdPrivKey
    RELEASE loPrivKey
    RELEASE loHttp
    CANCEL
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
loCrypt = CreateObject('Chilkat_9_5_0.Crypt2')
loCrypt.HashAlgorithm = "SHA256"
loCrypt.EncodingMode = "base64"
lcPayload = "grant_type=client_credentials"
lcPayloadDigest = loCrypt.HashStringENC(lcPayload)

* 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")  
loDt = CreateObject('Chilkat_9_5_0.CkDateTime')
loDt.SetFromCurrentSystemTime()
* The desire date/time format is the "RFC822" format.
loHttp.SetRequestHeader("Date",loDt.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`

lcHttpMethod = "POST"
lcReqPath = "/oauth2/token"

loSbStringToSign = CreateObject('Chilkat_9_5_0.StringBuilder')
loSbStringToSign.Append("(request-target): ")
loSbStringToSign.Append(lcHttpMethod)
loSbStringToSign.ToLowercase()
loSbStringToSign.Append(" ")
loSbStringToSign.AppendLine(lcReqPath,0)

loSbStringToSign.Append("date: ")
loSbStringToSign.AppendLine(loDt.GetAsRfc822(0),0)

loSbStringToSign.Append("digest: SHA-256=")
loSbStringToSign.Append(lcPayloadDigest)

loSigningPrivKey = CreateObject('Chilkat_9_5_0.PrivateKey')
lnSuccess = loSigningPrivKey.LoadPemFile("qa_data/certs_and_keys/ING/example_client_signing.key")
IF (lnSuccess = 0) THEN
    ? loSigningPrivKey.LastErrorText
    RELEASE loCert
    RELEASE loBdPrivKey
    RELEASE loPrivKey
    RELEASE loHttp
    RELEASE loCrypt
    RELEASE loDt
    RELEASE loSbStringToSign
    RELEASE loSigningPrivKey
    CANCEL
ENDIF

loRsa = CreateObject('Chilkat_9_5_0.Rsa')
lnSuccess = loRsa.ImportPrivateKeyObj(loSigningPrivKey)
IF (lnSuccess = 0) THEN
    ? loRsa.LastErrorText
    RELEASE loCert
    RELEASE loBdPrivKey
    RELEASE loPrivKey
    RELEASE loHttp
    RELEASE loCrypt
    RELEASE loDt
    RELEASE loSbStringToSign
    RELEASE loSigningPrivKey
    RELEASE loRsa
    CANCEL
ENDIF

loRsa.EncodingMode = "base64"
lcB64Signature = loRsa.SignStringENC(loSbStringToSign.GetAsString(),"SHA256")

loSbAuthHdrVal = CreateObject('Chilkat_9_5_0.StringBuilder')
loSbAuthHdrVal.Append('Signature keyId="e77d776b-90af-4684-bebc-521e5b2614dd",')
loSbAuthHdrVal.Append('algorithm="rsa-sha256",')
loSbAuthHdrVal.Append('headers="(request-target) date digest",')
loSbAuthHdrVal.Append('signature="')
loSbAuthHdrVal.Append(lcB64Signature)
loSbAuthHdrVal.Append('"')

loSbDigestHdrVal = CreateObject('Chilkat_9_5_0.StringBuilder')
loSbDigestHdrVal.Append("SHA-256=")
loSbDigestHdrVal.Append(lcPayloadDigest)

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

loReq = CreateObject('Chilkat_9_5_0.HttpRequest')
loReq.AddParam("grant_type","client_credentials")
loReq.AddHeader("Accept","application/json")
loReq.AddHeader("Date",loDt.GetAsRfc822(0))
loReq.AddHeader("Digest",loSbDigestHdrVal.GetAsString())
loReq.AddHeader("Authorization",loSbAuthHdrVal.GetAsString())
loResp = loHttp.PostUrlEncoded("https://api.sandbox.ing.com/oauth2/token",loReq)
IF (loHttp.LastMethodSuccess = 0) THEN
    ? loHttp.LastErrorText
    RELEASE loCert
    RELEASE loBdPrivKey
    RELEASE loPrivKey
    RELEASE loHttp
    RELEASE loCrypt
    RELEASE loDt
    RELEASE loSbStringToSign
    RELEASE loSigningPrivKey
    RELEASE loRsa
    RELEASE loSbAuthHdrVal
    RELEASE loSbDigestHdrVal
    RELEASE loReq
    CANCEL
ENDIF

* If successful, the status code = 200
? "Response Status Code: " + STR(loResp.StatusCode)
? loResp.BodyStr

loJson = CreateObject('Chilkat_9_5_0.JsonObject')
loJson.Load(loResp.BodyStr)

RELEASE loResp

loJson.EmitCompact = 0
? loJson.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

lcAccess_token = loJson.StringOf("access_token")
lnExpires_in = loJson.IntOf("expires_in")
lcScope = loJson.StringOf("scope")
lcToken_type = loJson.StringOf("token_type")
lcClient_id = loJson.StringOf("client_id")
i = 0
lnCount_i = loJson.SizeOfArray("keys")
DO WHILE i < lnCount_i
    loJson.I = i
    lcKty = loJson.StringOf("keys[i].kty")
    n = loJson.StringOf("keys[i].n")
    e = loJson.StringOf("keys[i].e")
    lcUse = loJson.StringOf("keys[i].use")
    lcAlg = loJson.StringOf("keys[i].alg")
    lcX5t = loJson.StringOf("keys[i].x5t")
    i = i + 1
ENDDO

* 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.
loJson.WriteFile("qa_data/tokens/ing_access_token.json")

RELEASE loCert
RELEASE loBdPrivKey
RELEASE loPrivKey
RELEASE loHttp
RELEASE loCrypt
RELEASE loDt
RELEASE loSbStringToSign
RELEASE loSigningPrivKey
RELEASE loRsa
RELEASE loSbAuthHdrVal
RELEASE loSbDigestHdrVal
RELEASE loReq
RELEASE loJson


 

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