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
(PureBasic) 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
IncludeFile "CkBinData.pb" IncludeFile "CkPrivateKey.pb" IncludeFile "CkHttp.pb" IncludeFile "CkJsonObject.pb" IncludeFile "CkHttpRequest.pb" IncludeFile "CkHttpResponse.pb" IncludeFile "CkCert.pb" Procedure ChilkatExample() ; This example assumes the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. http.i = CkHttp::ckCreate() If http.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success.i ; First load the certificate and private key, and set as the HTTP object's client certificate. cert.i = CkCert::ckCreate() If cert.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success = CkCert::ckLoadFromFile(cert,"<nome arquivo certificado>.crt") If success = 0 Debug CkCert::ckLastErrorText(cert) CkHttp::ckDispose(http) CkCert::ckDispose(cert) ProcedureReturn EndIf bdPrivKey.i = CkBinData::ckCreate() If bdPrivKey.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success = CkBinData::ckLoadFile(bdPrivKey,"<nome arquivo chave privada>.key") If success = 0 Debug "Failed to load <nome" CkHttp::ckDispose(http) CkCert::ckDispose(cert) CkBinData::ckDispose(bdPrivKey) ProcedureReturn EndIf privKey.i = CkPrivateKey::ckCreate() If privKey.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success = CkPrivateKey::ckLoadAnyFormat(privKey,bdPrivKey,"") If success = 0 Debug CkPrivateKey::ckLastErrorText(privKey) CkHttp::ckDispose(http) CkCert::ckDispose(cert) CkBinData::ckDispose(bdPrivKey) CkPrivateKey::ckDispose(privKey) ProcedureReturn EndIf success = CkCert::ckSetPrivateKey(cert,privKey) If success = 0 Debug CkCert::ckLastErrorText(cert) CkHttp::ckDispose(http) CkCert::ckDispose(cert) CkBinData::ckDispose(bdPrivKey) CkPrivateKey::ckDispose(privKey) ProcedureReturn EndIf success = CkHttp::ckSetSslClientCert(http,cert) If success = 0 Debug CkHttp::ckLastErrorText(http) CkHttp::ckDispose(http) CkCert::ckDispose(cert) CkBinData::ckDispose(bdPrivKey) CkPrivateKey::ckDispose(privKey) ProcedureReturn EndIf req.i = CkHttpRequest::ckCreate() If req.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkHttpRequest::setCkHttpVerb(req, "POST") CkHttpRequest::setCkPath(req, "/oauth/v2/token") CkHttpRequest::setCkContentType(req, "application/x-www-form-urlencoded") CkHttpRequest::ckAddParam(req,"grant_type","client_credentials") ; Requested scopes in OAuth2 are typically SPACE separated. CkHttpRequest::ckAddParam(req,"scope","boleto-cobranca.read boleto-cobranca.write") CkHttpRequest::ckAddHeader(req,"accept","application/json") resp.i = CkHttp::ckPostUrlEncoded(http,"https://cdpj.partners.bancointer.com.br/oauth/v2/token",req) If CkHttp::ckLastMethodSuccess(http) = 0 Debug CkHttp::ckLastErrorText(http) CkHttp::ckDispose(http) CkCert::ckDispose(cert) CkBinData::ckDispose(bdPrivKey) CkPrivateKey::ckDispose(privKey) CkHttpRequest::ckDispose(req) ProcedureReturn EndIf jResp.i = CkJsonObject::ckCreate() If jResp.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkHttpResponse::ckGetBodyJson(resp,jResp) CkJsonObject::setCkEmitCompact(jResp, 0) Debug "Response Body:" Debug CkJsonObject::ckEmit(jResp) respStatusCode.i = CkHttpResponse::ckStatusCode(resp) Debug "Response Status Code = " + Str(respStatusCode) If respStatusCode >= 400 Debug "Response Header:" Debug CkHttpResponse::ckHeader(resp) Debug "Failed." CkHttpResponse::ckDispose(resp) CkHttp::ckDispose(http) CkCert::ckDispose(cert) CkBinData::ckDispose(bdPrivKey) CkPrivateKey::ckDispose(privKey) CkHttpRequest::ckDispose(req) CkJsonObject::ckDispose(jResp) ProcedureReturn EndIf CkHttpResponse::ckDispose(resp) success = CkJsonObject::ckWriteFile(jResp,"qa_data/tokens/banco_inter_client_credentials.json") If success = 0 Debug "Failed to save JSON access token file." CkHttp::ckDispose(http) CkCert::ckDispose(cert) CkBinData::ckDispose(bdPrivKey) CkPrivateKey::ckDispose(privKey) CkHttpRequest::ckDispose(req) CkJsonObject::ckDispose(jResp) ProcedureReturn EndIf Debug "Success." CkHttp::ckDispose(http) CkCert::ckDispose(cert) CkBinData::ckDispose(bdPrivKey) CkPrivateKey::ckDispose(privKey) CkHttpRequest::ckDispose(req) CkJsonObject::ckDispose(jResp) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.