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
(DataFlex) Banco Inter OAuth2 Client CredentialsGenerate an OAuth2 access token needed to consume the Inter APIs. For more information, see https://developers.bancointer.com.br/reference/token-3
Use ChilkatAx-win32.pkg Procedure Test Handle hoHttp Boolean iSuccess Variant vCert Handle hoCert Variant vBdPrivKey Handle hoBdPrivKey Variant vPrivKey Handle hoPrivKey Variant vReq Handle hoReq Variant vResp Handle hoResp Variant vJResp Handle hoJResp Integer iRespStatusCode String sTemp1 Boolean bTemp1 // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. Get Create (RefClass(cComChilkatHttp)) To hoHttp If (Not(IsComObjectCreated(hoHttp))) Begin Send CreateComObject of hoHttp End // First load the certificate and private key, and set as the HTTP object's client certificate. Get Create (RefClass(cComChilkatCert)) To hoCert If (Not(IsComObjectCreated(hoCert))) Begin Send CreateComObject of hoCert End Get ComLoadFromFile Of hoCert "<nome arquivo certificado>.crt" To iSuccess If (iSuccess = False) Begin Get ComLastErrorText Of hoCert To sTemp1 Showln sTemp1 Procedure_Return End Get Create (RefClass(cComChilkatBinData)) To hoBdPrivKey If (Not(IsComObjectCreated(hoBdPrivKey))) Begin Send CreateComObject of hoBdPrivKey End Get ComLoadFile Of hoBdPrivKey "<nome arquivo chave privada>.key" To iSuccess If (iSuccess = False) Begin Showln "Failed to load <nome" Procedure_Return End Get Create (RefClass(cComChilkatPrivateKey)) To hoPrivKey If (Not(IsComObjectCreated(hoPrivKey))) Begin Send CreateComObject of hoPrivKey End Get pvComObject of hoBdPrivKey to vBdPrivKey Get ComLoadAnyFormat Of hoPrivKey vBdPrivKey "" To iSuccess If (iSuccess = False) Begin Get ComLastErrorText Of hoPrivKey To sTemp1 Showln sTemp1 Procedure_Return End Get pvComObject of hoPrivKey to vPrivKey Get ComSetPrivateKey Of hoCert vPrivKey To iSuccess If (iSuccess = False) Begin Get ComLastErrorText Of hoCert To sTemp1 Showln sTemp1 Procedure_Return End Get pvComObject of hoCert to vCert Get ComSetSslClientCert Of hoHttp vCert To iSuccess If (iSuccess = False) Begin Get ComLastErrorText Of hoHttp To sTemp1 Showln sTemp1 Procedure_Return End Get Create (RefClass(cComChilkatHttpRequest)) To hoReq If (Not(IsComObjectCreated(hoReq))) Begin Send CreateComObject of hoReq End Set ComHttpVerb Of hoReq To "POST" Set ComPath Of hoReq To "/oauth/v2/token" Set ComContentType Of hoReq To "application/x-www-form-urlencoded" Send ComAddParam To hoReq "grant_type" "client_credentials" // Requested scopes in OAuth2 are typically SPACE separated. Send ComAddParam To hoReq "scope" "boleto-cobranca.read boleto-cobranca.write" Send ComAddHeader To hoReq "accept" "application/json" Get pvComObject of hoReq to vReq Get ComPostUrlEncoded Of hoHttp "https://cdpj.partners.bancointer.com.br/oauth/v2/token" vReq To vResp If (IsComObject(vResp)) Begin Get Create (RefClass(cComChilkatHttpResponse)) To hoResp Set pvComObject Of hoResp To vResp End Get ComLastMethodSuccess Of hoHttp To bTemp1 If (bTemp1 = False) Begin Get ComLastErrorText Of hoHttp To sTemp1 Showln sTemp1 Procedure_Return End Get Create (RefClass(cComChilkatJsonObject)) To hoJResp If (Not(IsComObjectCreated(hoJResp))) Begin Send CreateComObject of hoJResp End Get pvComObject of hoJResp to vJResp Get ComGetBodyJson Of hoResp vJResp To iSuccess Set ComEmitCompact Of hoJResp To False Showln "Response Body:" Get ComEmit Of hoJResp To sTemp1 Showln sTemp1 Get ComStatusCode Of hoResp To iRespStatusCode Showln "Response Status Code = " iRespStatusCode If (iRespStatusCode >= 400) Begin Showln "Response Header:" Get ComHeader Of hoResp To sTemp1 Showln sTemp1 Showln "Failed." Send Destroy of hoResp Procedure_Return End Send Destroy of hoResp Get ComWriteFile Of hoJResp "qa_data/tokens/banco_inter_client_credentials.json" To iSuccess If (iSuccess = False) Begin Showln "Failed to save JSON access token file." Procedure_Return End Showln "Success." End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.