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

Unicode C Example

#include <C_CkRestW.h>
#include <C_CkJsonObjectW.h>

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

    rest = CkRestW_Create();

    //  URL: https://demoauth.fatturazioneelettronica.aruba.it/auth/signin
    bTls = TRUE;
    port = 443;
    bAutoReconnect = TRUE;
    success = CkRestW_Connect(rest,L"demoauth.fatturazioneelettronica.aruba.it",port,bTls,bAutoReconnect);
    if (success != TRUE) {
        wprintf(L"ConnectFailReason: %d\n",CkRestW_getConnectFailReason(rest));
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        return;
    }

    CkRestW_AddQueryParam(rest,L"grant_type",L"password");
    CkRestW_AddQueryParam(rest,L"username",L"Utente");
    CkRestW_AddQueryParam(rest,L"password",L"Password");

    strResponseBody = CkRestW_fullRequestFormUrlEncoded(rest,L"POST",L"/auth/signin");
    if (CkRestW_getLastMethodSuccess(rest) != TRUE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        return;
    }

    respStatusCode = CkRestW_getResponseStatusCode(rest);
    if (respStatusCode >= 400) {
        wprintf(L"Response Status Code = %d\n",respStatusCode);
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",CkRestW_responseHeader(rest));
        wprintf(L"Response Body:\n");
        wprintf(L"%s\n",strResponseBody);
        CkRestW_Dispose(rest);
        return;
    }

    jsonResponse = CkJsonObjectW_Create();
    CkJsonObjectW_Load(jsonResponse,strResponseBody);

    //  See the Online Tool for Generating JSON Parse Code

    access_token = CkJsonObjectW_stringOf(jsonResponse,L"access_token");
    token_type = CkJsonObjectW_stringOf(jsonResponse,L"token_type");
    expires_in = CkJsonObjectW_IntOf(jsonResponse,L"expires_in");
    refresh_token = CkJsonObjectW_stringOf(jsonResponse,L"refresh_token");
    client_id = CkJsonObjectW_stringOf(jsonResponse,L"client_id");
    userName = CkJsonObjectW_stringOf(jsonResponse,L"userName");
    Issued = CkJsonObjectW_stringOf(jsonResponse,L"\".issued\"");
    Expires = CkJsonObjectW_stringOf(jsonResponse,L"\".expires\"");


    CkRestW_Dispose(rest);
    CkJsonObjectW_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"
}