C 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'

C Example

#include <C_CkRest.h>
#include <C_CkJsonObject.h>

void ChilkatSample(void)
    {
    HCkRest rest;
    BOOL success;
    BOOL bTls;
    int port;
    BOOL bAutoReconnect;
    const char *strResponseBody;
    int respStatusCode;
    HCkJsonObject jsonResponse;
    const char *access_token;
    const char *token_type;
    int expires_in;
    const char *refresh_token;
    const char *client_id;
    const char *userName;
    const char *Issued;
    const char *Expires;

    rest = CkRest_Create();

    //  URL: https://demoauth.fatturazioneelettronica.aruba.it/auth/signin
    bTls = TRUE;
    port = 443;
    bAutoReconnect = TRUE;
    success = CkRest_Connect(rest,"demoauth.fatturazioneelettronica.aruba.it",port,bTls,bAutoReconnect);
    if (success != TRUE) {
        printf("ConnectFailReason: %d\n",CkRest_getConnectFailReason(rest));
        printf("%s\n",CkRest_lastErrorText(rest));
        CkRest_Dispose(rest);
        return;
    }

    CkRest_AddQueryParam(rest,"grant_type","password");
    CkRest_AddQueryParam(rest,"username","Utente");
    CkRest_AddQueryParam(rest,"password","Password");

    strResponseBody = CkRest_fullRequestFormUrlEncoded(rest,"POST","/auth/signin");
    if (CkRest_getLastMethodSuccess(rest) != TRUE) {
        printf("%s\n",CkRest_lastErrorText(rest));
        CkRest_Dispose(rest);
        return;
    }

    respStatusCode = CkRest_getResponseStatusCode(rest);
    if (respStatusCode >= 400) {
        printf("Response Status Code = %d\n",respStatusCode);
        printf("Response Header:\n");
        printf("%s\n",CkRest_responseHeader(rest));
        printf("Response Body:\n");
        printf("%s\n",strResponseBody);
        CkRest_Dispose(rest);
        return;
    }

    jsonResponse = CkJsonObject_Create();
    CkJsonObject_Load(jsonResponse,strResponseBody);

    //  See the Online Tool for Generating JSON Parse Code

    access_token = CkJsonObject_stringOf(jsonResponse,"access_token");
    token_type = CkJsonObject_stringOf(jsonResponse,"token_type");
    expires_in = CkJsonObject_IntOf(jsonResponse,"expires_in");
    refresh_token = CkJsonObject_stringOf(jsonResponse,"refresh_token");
    client_id = CkJsonObject_stringOf(jsonResponse,"client_id");
    userName = CkJsonObject_stringOf(jsonResponse,"userName");
    Issued = CkJsonObject_stringOf(jsonResponse,"\".issued\"");
    Expires = CkJsonObject_stringOf(jsonResponse,"\".expires\"");


    CkRest_Dispose(rest);
    CkJsonObject_Dispose(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"
}