![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Delphi DLL) Banco Inter OAuth2 Client CredentialsGenerate an OAuth2 access token needed to consume the Inter APIs. Note: This example requires Chilkat v11.0.0 or greater. For more information, see https://developers.bancointer.com.br/reference/token-3
uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, HttpResponse, JsonObject, HttpRequest, BinData, PrivateKey, Cert, Http; ... procedure TForm1.Button1Click(Sender: TObject); var success: Boolean; http: HCkHttp; cert: HCkCert; bdPrivKey: HCkBinData; privKey: HCkPrivateKey; req: HCkHttpRequest; resp: HCkHttpResponse; jResp: HCkJsonObject; respStatusCode: Integer; begin success := False; // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. http := CkHttp_Create(); // First load the certificate and private key, and set as the HTTP object's client certificate. cert := CkCert_Create(); success := CkCert_LoadFromFile(cert,'<nome arquivo certificado>.crt'); if (success = False) then begin Memo1.Lines.Add(CkCert__lastErrorText(cert)); Exit; end; bdPrivKey := CkBinData_Create(); success := CkBinData_LoadFile(bdPrivKey,'<nome arquivo chave privada>.key'); if (success = False) then begin Memo1.Lines.Add('Failed to load <nome'); Exit; end; privKey := CkPrivateKey_Create(); success := CkPrivateKey_LoadAnyFormat(privKey,bdPrivKey,''); if (success = False) then begin Memo1.Lines.Add(CkPrivateKey__lastErrorText(privKey)); Exit; end; success := CkCert_SetPrivateKey(cert,privKey); if (success = False) then begin Memo1.Lines.Add(CkCert__lastErrorText(cert)); Exit; end; success := CkHttp_SetSslClientCert(http,cert); if (success = False) then begin Memo1.Lines.Add(CkHttp__lastErrorText(http)); Exit; end; req := CkHttpRequest_Create(); CkHttpRequest_putHttpVerb(req,'POST'); CkHttpRequest_putPath(req,'/oauth/v2/token'); CkHttpRequest_putContentType(req,'application/x-www-form-urlencoded'); CkHttpRequest_AddParam(req,'grant_type','client_credentials'); // Requested scopes in OAuth2 are typically SPACE separated. CkHttpRequest_AddParam(req,'scope','boleto-cobranca.read boleto-cobranca.write'); CkHttpRequest_AddHeader(req,'accept','application/json'); resp := CkHttpResponse_Create(); success := CkHttp_HttpReq(http,'https://cdpj.partners.bancointer.com.br/oauth/v2/token',req,resp); if (success = False) then begin Memo1.Lines.Add(CkHttp__lastErrorText(http)); Exit; end; jResp := CkJsonObject_Create(); CkHttpResponse_GetBodyJson(resp,jResp); CkJsonObject_putEmitCompact(jResp,False); Memo1.Lines.Add('Response Body:'); Memo1.Lines.Add(CkJsonObject__emit(jResp)); respStatusCode := CkHttpResponse_getStatusCode(resp); Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode)); if (respStatusCode >= 400) then begin Memo1.Lines.Add('Response Header:'); Memo1.Lines.Add(CkHttpResponse__header(resp)); Memo1.Lines.Add('Failed.'); Exit; end; success := CkJsonObject_WriteFile(jResp,'qa_data/tokens/banco_inter_client_credentials.json'); if (success = False) then begin Memo1.Lines.Add('Failed to save JSON access token file.'); Exit; end; Memo1.Lines.Add('Success.'); CkHttp_Dispose(http); CkCert_Dispose(cert); CkBinData_Dispose(bdPrivKey); CkPrivateKey_Dispose(privKey); CkHttpRequest_Dispose(req); CkHttpResponse_Dispose(resp); CkJsonObject_Dispose(jResp); end; |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.