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
(Delphi DLL) 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
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 http: HCkHttp; success: Boolean; cert: HCkCert; bdPrivKey: HCkBinData; privKey: HCkPrivateKey; req: HCkHttpRequest; resp: HCkHttpResponse; jResp: HCkJsonObject; respStatusCode: Integer; begin // 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 := CkHttp_PostUrlEncoded(http,'https://cdpj.partners.bancointer.com.br/oauth/v2/token',req); if (CkHttp_getLastMethodSuccess(http) = 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.'); CkHttpResponse_Dispose(resp); Exit; end; CkHttpResponse_Dispose(resp); 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); CkJsonObject_Dispose(jResp); end; |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.