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
(Tcl) 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
load ./chilkat.dll # This example assumes the Chilkat API to have been previously unlocked. # See Global Unlock Sample for sample code. set http [new_CkHttp] # First load the certificate and private key, and set as the HTTP object's client certificate. set cert [new_CkCert] set success [CkCert_LoadFromFile $cert "<nome arquivo certificado>.crt"] if {$success == 0} then { puts [CkCert_lastErrorText $cert] delete_CkHttp $http delete_CkCert $cert exit } set bdPrivKey [new_CkBinData] set success [CkBinData_LoadFile $bdPrivKey "<nome arquivo chave privada>.key"] if {$success == 0} then { puts "Failed to load <nome" delete_CkHttp $http delete_CkCert $cert delete_CkBinData $bdPrivKey exit } set privKey [new_CkPrivateKey] set success [CkPrivateKey_LoadAnyFormat $privKey $bdPrivKey ""] if {$success == 0} then { puts [CkPrivateKey_lastErrorText $privKey] delete_CkHttp $http delete_CkCert $cert delete_CkBinData $bdPrivKey delete_CkPrivateKey $privKey exit } set success [CkCert_SetPrivateKey $cert $privKey] if {$success == 0} then { puts [CkCert_lastErrorText $cert] delete_CkHttp $http delete_CkCert $cert delete_CkBinData $bdPrivKey delete_CkPrivateKey $privKey exit } set success [CkHttp_SetSslClientCert $http $cert] if {$success == 0} then { puts [CkHttp_lastErrorText $http] delete_CkHttp $http delete_CkCert $cert delete_CkBinData $bdPrivKey delete_CkPrivateKey $privKey exit } set req [new_CkHttpRequest] CkHttpRequest_put_HttpVerb $req "POST" CkHttpRequest_put_Path $req "/oauth/v2/token" CkHttpRequest_put_ContentType $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 is a CkHttpResponse set resp [CkHttp_PostUrlEncoded $http "https://cdpj.partners.bancointer.com.br/oauth/v2/token" $req] if {[CkHttp_get_LastMethodSuccess $http] == 0} then { puts [CkHttp_lastErrorText $http] delete_CkHttp $http delete_CkCert $cert delete_CkBinData $bdPrivKey delete_CkPrivateKey $privKey delete_CkHttpRequest $req exit } set jResp [new_CkJsonObject] CkHttpResponse_GetBodyJson $resp $jResp CkJsonObject_put_EmitCompact $jResp 0 puts "Response Body:" puts [CkJsonObject_emit $jResp] set respStatusCode [CkHttpResponse_get_StatusCode $resp] puts "Response Status Code = $respStatusCode" if {$respStatusCode >= 400} then { puts "Response Header:" puts [CkHttpResponse_header $resp] puts "Failed." delete_CkHttpResponse $resp delete_CkHttp $http delete_CkCert $cert delete_CkBinData $bdPrivKey delete_CkPrivateKey $privKey delete_CkHttpRequest $req delete_CkJsonObject $jResp exit } delete_CkHttpResponse $resp set success [CkJsonObject_WriteFile $jResp "qa_data/tokens/banco_inter_client_credentials.json"] if {$success == 0} then { puts "Failed to save JSON access token file." delete_CkHttp $http delete_CkCert $cert delete_CkBinData $bdPrivKey delete_CkPrivateKey $privKey delete_CkHttpRequest $req delete_CkJsonObject $jResp exit } puts "Success." delete_CkHttp $http delete_CkCert $cert delete_CkBinData $bdPrivKey delete_CkPrivateKey $privKey delete_CkHttpRequest $req delete_CkJsonObject $jResp |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.