Lua
Lua
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 Lua Downloads
local chilkat = require("chilkat")
-- 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'
local cert = chilkat.Cert.new()
local success = cert:load_from_file("qa_data/certs/TPPCertificate.cer")
if not success then
print(cert.last_error_text)
return
end
local bdKey = chilkat.BinData.new()
success = bdKey:load_file("qa_data/certs/TPPprivateKey.key")
local privKey = chilkat.PrivateKey.new()
success = privKey:load_any_format(bdKey, "passwordIfNeeded")
if not success then
print(privKey.last_error_text)
return
end
success = cert:set_private_key(privKey)
if not success then
print(cert.last_error_text)
return
end
local http = chilkat.Http.new()
success = http:set_ssl_client_cert(cert)
if not success then
print(http.last_error_text)
return
end
local req = chilkat.HttpRequest.new()
req:add_param("grant_type", "client_credentials")
req:add_param("client_id", "TPP_test")
req:add_param("scope", "psd2:payment:sepa:write psd2:payment:sepa:read")
req.http_verb = "POST"
req.content_type = "application/x-www-form-urlencoded"
local resp = chilkat.HttpResponse.new()
success = http:http_req("https://auth-sandbox.connect.abnamro.com:8443/as/token.oauth2", req, resp)
if not success then
print(http.last_error_text)
return
end
if resp.status_code ~= 200 then
print(resp.body_str)
return
end
-- Get the JSON result:
-- {"access_token":"TIhycwl8rfrZPkXGw15mwldASAAK","token_type":"Bearer","expires_in":7200}
local json = chilkat.JsonObject.new()
json:load(resp.body_str)
print("access_token: " .. json:string_of("access_token"))
print("token_type: " .. json:string_of("token_type"))
print("expires_in: " .. json:string_of("expires_in"))