Tcl Fatturazione Elettronica Aruba IT: signin (Get an access_token)

Back to Index

Il metodo serve a richiedere un token di autenticazione. Tale token รจ necessario per invocare i metodi dei vari server della Fatturazione Elettronica (Resource Server) che sono protetti dal sistema.

Documentation: https://fatturazioneelettronica.aruba.it/apidoc/docs.html#_signin

CURL Command

curl -X POST  https://demoauth.fatturazioneelettronica.aruba.it/auth/signin \
-H 'Content-Type: application/x-www-form-urlencoded;charset=UTF-8' \
-d 'grant_type=password' \
-d 'username=Utente' \
-d 'password=Password'

Tcl Example


load ./chilkat.dll

set rest [new_CkRest]

#  URL: https://demoauth.fatturazioneelettronica.aruba.it/auth/signin
set bTls 1
set port 443
set bAutoReconnect 1
set success [CkRest_Connect $rest "demoauth.fatturazioneelettronica.aruba.it" $port $bTls $bAutoReconnect]
if {[expr $success != 1]} then {
    puts "ConnectFailReason: [CkRest_get_ConnectFailReason $rest]"
    puts [CkRest_lastErrorText $rest]
    delete_CkRest $rest
    exit
}

CkRest_AddQueryParam $rest "grant_type" "password"
CkRest_AddQueryParam $rest "username" "Utente"
CkRest_AddQueryParam $rest "password" "Password"

set strResponseBody [CkRest_fullRequestFormUrlEncoded $rest "POST" "/auth/signin"]
if {[expr [CkRest_get_LastMethodSuccess $rest] != 1]} then {
    puts [CkRest_lastErrorText $rest]
    delete_CkRest $rest
    exit
}

set respStatusCode [CkRest_get_ResponseStatusCode $rest]
if {[expr $respStatusCode >= 400]} then {
    puts "Response Status Code = $respStatusCode"
    puts "Response Header:"
    puts [CkRest_responseHeader $rest]
    puts "Response Body:"
    puts "$strResponseBody"
    delete_CkRest $rest
    exit
}

set jsonResponse [new_CkJsonObject]

CkJsonObject_Load $jsonResponse $strResponseBody

#  See the Online Tool for Generating JSON Parse Code

set access_token [CkJsonObject_stringOf $jsonResponse "access_token"]
set token_type [CkJsonObject_stringOf $jsonResponse "token_type"]
set expires_in [CkJsonObject_IntOf $jsonResponse "expires_in"]
set refresh_token [CkJsonObject_stringOf $jsonResponse "refresh_token"]
set client_id [CkJsonObject_stringOf $jsonResponse "client_id"]
set userName [CkJsonObject_stringOf $jsonResponse "userName"]
set Issued [CkJsonObject_stringOf $jsonResponse "\".issued\""]
set Expires [CkJsonObject_stringOf $jsonResponse "\".expires\""]

delete_CkRest $rest
delete_CkJsonObject $jsonResponse

Sample JSON Response Body

{
  "access_token": "571a08cd6275e81e",
  "token_type": "bearer",
  "expires_in": 1800,
  "refresh_token": "262ac1f88ad1e9e5",
  "client_id": "123456",
  "userName": "Utente",
  ".issued": "Mon, 21 Jan 2019 16:36:17 GMT",
  ".expires": "Mon, 21 Jan 2019 17:06:17 GMT"
}