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
(SQL Server) ABN AMRO OAuth2 Client Credentials AuthenticationDemonstrates how to obtain an access token for an ABN AMRO online API using OAuth2 with the Client Credentials flow. For more information, see https://developer.abnamro.com/api/payment-initiation-v1/payment-initiation-tutorial
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls. -- CREATE PROCEDURE ChilkatSample AS BEGIN DECLARE @hr int DECLARE @iTmp0 int -- Important: Do not use nvarchar(max). See the warning about using nvarchar(max). DECLARE @sTmp0 nvarchar(4000) -- 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' DECLARE @cert int -- Use "Chilkat_9_5_0.Cert" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.Cert', @cert OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END DECLARE @success int EXEC sp_OAMethod @cert, 'LoadFromFile', @success OUT, 'qa_data/certs/TPPCertificate.cer' IF @success <> 1 BEGIN EXEC sp_OAGetProperty @cert, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @cert RETURN END DECLARE @bdKey int -- Use "Chilkat_9_5_0.BinData" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.BinData', @bdKey OUT EXEC sp_OAMethod @bdKey, 'LoadFile', @success OUT, 'qa_data/certs/TPPprivateKey.key' DECLARE @privKey int -- Use "Chilkat_9_5_0.PrivateKey" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.PrivateKey', @privKey OUT EXEC sp_OAMethod @privKey, 'LoadAnyFormat', @success OUT, @bdKey, 'passwordIfNeeded' IF @success <> 1 BEGIN EXEC sp_OAGetProperty @privKey, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @cert EXEC @hr = sp_OADestroy @bdKey EXEC @hr = sp_OADestroy @privKey RETURN END EXEC sp_OAMethod @cert, 'SetPrivateKey', @success OUT, @privKey IF @success <> 1 BEGIN EXEC sp_OAGetProperty @cert, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @cert EXEC @hr = sp_OADestroy @bdKey EXEC @hr = sp_OADestroy @privKey RETURN END DECLARE @http int -- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT EXEC sp_OAMethod @http, 'SetSslClientCert', @success OUT, @cert IF @success <> 1 BEGIN EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @cert EXEC @hr = sp_OADestroy @bdKey EXEC @hr = sp_OADestroy @privKey EXEC @hr = sp_OADestroy @http RETURN END DECLARE @req int -- Use "Chilkat_9_5_0.HttpRequest" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.HttpRequest', @req OUT EXEC sp_OAMethod @req, 'AddParam', NULL, 'grant_type', 'client_credentials' EXEC sp_OAMethod @req, 'AddParam', NULL, 'client_id', 'TPP_test' EXEC sp_OAMethod @req, 'AddParam', NULL, 'scope', 'psd2:payment:sepa:write psd2:payment:sepa:read' DECLARE @resp int EXEC sp_OAMethod @http, 'PostUrlEncoded', @resp OUT, 'https://auth-sandbox.connect.abnamro.com:8443/as/token.oauth2', @req EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT IF @iTmp0 = 0 BEGIN EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @cert EXEC @hr = sp_OADestroy @bdKey EXEC @hr = sp_OADestroy @privKey EXEC @hr = sp_OADestroy @http EXEC @hr = sp_OADestroy @req RETURN END EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT IF @iTmp0 <> 200 BEGIN EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @resp EXEC @hr = sp_OADestroy @cert EXEC @hr = sp_OADestroy @bdKey EXEC @hr = sp_OADestroy @privKey EXEC @hr = sp_OADestroy @http EXEC @hr = sp_OADestroy @req RETURN END -- Get the JSON result: -- {"access_token":"TIhycwl8rfrZPkXGw15mwldASAAK","token_type":"Bearer","expires_in":7200} DECLARE @json int -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT EXEC sp_OAMethod @json, 'Load', @success OUT, @sTmp0 EXEC sp_OAMethod @json, 'StringOf', @sTmp0 OUT, 'access_token' PRINT 'access_token: ' + @sTmp0 EXEC sp_OAMethod @json, 'StringOf', @sTmp0 OUT, 'token_type' PRINT 'token_type: ' + @sTmp0 EXEC sp_OAMethod @json, 'StringOf', @sTmp0 OUT, 'expires_in' PRINT 'expires_in: ' + @sTmp0 EXEC @hr = sp_OADestroy @resp EXEC @hr = sp_OADestroy @cert EXEC @hr = sp_OADestroy @bdKey EXEC @hr = sp_OADestroy @privKey EXEC @hr = sp_OADestroy @http EXEC @hr = sp_OADestroy @req EXEC @hr = sp_OADestroy @json END GO |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.