PowerBuilder
PowerBuilder
ABN AMRO OAuth2 Client Credentials Authentication
See more ABN AMRO Examples
Demonstrates how to obtain an access token for an ABN AMRO online API using OAuth2 with the Client Credentials flow.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Cert
oleobject loo_BdKey
oleobject loo_PrivKey
oleobject loo_Http
oleobject loo_Req
oleobject loo_Resp
oleobject loo_Json
li_Success = 0
// 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'
loo_Cert = create oleobject
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/TPPCertificate.cer")
if li_Success = 0 then
Write-Debug loo_Cert.LastErrorText
destroy loo_Cert
return
end if
loo_BdKey = create oleobject
li_rc = loo_BdKey.ConnectToNewObject("Chilkat.BinData")
li_Success = loo_BdKey.LoadFile("qa_data/certs/TPPprivateKey.key")
loo_PrivKey = create oleobject
li_rc = loo_PrivKey.ConnectToNewObject("Chilkat.PrivateKey")
li_Success = loo_PrivKey.LoadAnyFormat(loo_BdKey,"passwordIfNeeded")
if li_Success = 0 then
Write-Debug loo_PrivKey.LastErrorText
destroy loo_Cert
destroy loo_BdKey
destroy loo_PrivKey
return
end if
li_Success = loo_Cert.SetPrivateKey(loo_PrivKey)
if li_Success = 0 then
Write-Debug loo_Cert.LastErrorText
destroy loo_Cert
destroy loo_BdKey
destroy loo_PrivKey
return
end if
loo_Http = create oleobject
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_BdKey
destroy loo_PrivKey
destroy loo_Http
return
end if
loo_Req = create oleobject
li_rc = loo_Req.ConnectToNewObject("Chilkat.HttpRequest")
loo_Req.AddParam("grant_type","client_credentials")
loo_Req.AddParam("client_id","TPP_test")
loo_Req.AddParam("scope","psd2:payment:sepa:write psd2:payment:sepa:read")
loo_Req.HttpVerb = "POST"
loo_Req.ContentType = "application/x-www-form-urlencoded"
loo_Resp = create oleobject
li_rc = loo_Resp.ConnectToNewObject("Chilkat.HttpResponse")
li_Success = loo_Http.HttpReq("https://auth-sandbox.connect.abnamro.com:8443/as/token.oauth2",loo_Req,loo_Resp)
if li_Success = 0 then
Write-Debug loo_Http.LastErrorText
destroy loo_Cert
destroy loo_BdKey
destroy loo_PrivKey
destroy loo_Http
destroy loo_Req
destroy loo_Resp
return
end if
if loo_Resp.StatusCode <> 200 then
Write-Debug loo_Resp.BodyStr
destroy loo_Cert
destroy loo_BdKey
destroy loo_PrivKey
destroy loo_Http
destroy loo_Req
destroy loo_Resp
return
end if
// Get the JSON result:
// {"access_token":"TIhycwl8rfrZPkXGw15mwldASAAK","token_type":"Bearer","expires_in":7200}
loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")
loo_Json.Load(loo_Resp.BodyStr)
Write-Debug "access_token: " + loo_Json.StringOf("access_token")
Write-Debug "token_type: " + loo_Json.StringOf("token_type")
Write-Debug "expires_in: " + loo_Json.StringOf("expires_in")
destroy loo_Cert
destroy loo_BdKey
destroy loo_PrivKey
destroy loo_Http
destroy loo_Req
destroy loo_Resp
destroy loo_Json