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
(C) 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
#include <C_CkHttp.h> #include <C_CkCert.h> #include <C_CkBinData.h> #include <C_CkPrivateKey.h> #include <C_CkHttpRequest.h> #include <C_CkHttpResponse.h> #include <C_CkJsonObject.h> void ChilkatSample(void) { HCkHttp http; BOOL success; HCkCert cert; HCkBinData bdPrivKey; HCkPrivateKey privKey; HCkHttpRequest req; HCkHttpResponse resp; HCkJsonObject jResp; int respStatusCode; // 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) { printf("%s\n",CkCert_lastErrorText(cert)); CkHttp_Dispose(http); CkCert_Dispose(cert); return; } bdPrivKey = CkBinData_Create(); success = CkBinData_LoadFile(bdPrivKey,"<nome arquivo chave privada>.key"); if (success == FALSE) { printf("Failed to load <nome\n"); CkHttp_Dispose(http); CkCert_Dispose(cert); CkBinData_Dispose(bdPrivKey); return; } privKey = CkPrivateKey_Create(); success = CkPrivateKey_LoadAnyFormat(privKey,bdPrivKey,""); if (success == FALSE) { printf("%s\n",CkPrivateKey_lastErrorText(privKey)); CkHttp_Dispose(http); CkCert_Dispose(cert); CkBinData_Dispose(bdPrivKey); CkPrivateKey_Dispose(privKey); return; } success = CkCert_SetPrivateKey(cert,privKey); if (success == FALSE) { printf("%s\n",CkCert_lastErrorText(cert)); CkHttp_Dispose(http); CkCert_Dispose(cert); CkBinData_Dispose(bdPrivKey); CkPrivateKey_Dispose(privKey); return; } success = CkHttp_SetSslClientCert(http,cert); if (success == FALSE) { printf("%s\n",CkHttp_lastErrorText(http)); CkHttp_Dispose(http); CkCert_Dispose(cert); CkBinData_Dispose(bdPrivKey); CkPrivateKey_Dispose(privKey); return; } 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) { printf("%s\n",CkHttp_lastErrorText(http)); CkHttp_Dispose(http); CkCert_Dispose(cert); CkBinData_Dispose(bdPrivKey); CkPrivateKey_Dispose(privKey); CkHttpRequest_Dispose(req); return; } jResp = CkJsonObject_Create(); CkHttpResponse_GetBodyJson(resp,jResp); CkJsonObject_putEmitCompact(jResp,FALSE); printf("Response Body:\n"); printf("%s\n",CkJsonObject_emit(jResp)); respStatusCode = CkHttpResponse_getStatusCode(resp); printf("Response Status Code = %d\n",respStatusCode); if (respStatusCode >= 400) { printf("Response Header:\n"); printf("%s\n",CkHttpResponse_header(resp)); printf("Failed.\n"); CkHttpResponse_Dispose(resp); CkHttp_Dispose(http); CkCert_Dispose(cert); CkBinData_Dispose(bdPrivKey); CkPrivateKey_Dispose(privKey); CkHttpRequest_Dispose(req); CkJsonObject_Dispose(jResp); return; } CkHttpResponse_Dispose(resp); success = CkJsonObject_WriteFile(jResp,"qa_data/tokens/banco_inter_client_credentials.json"); if (success == FALSE) { printf("Failed to save JSON access token file.\n"); CkHttp_Dispose(http); CkCert_Dispose(cert); CkBinData_Dispose(bdPrivKey); CkPrivateKey_Dispose(privKey); CkHttpRequest_Dispose(req); CkJsonObject_Dispose(jResp); return; } printf("Success.\n"); CkHttp_Dispose(http); CkCert_Dispose(cert); CkBinData_Dispose(bdPrivKey); CkPrivateKey_Dispose(privKey); CkHttpRequest_Dispose(req); CkJsonObject_Dispose(jResp); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.