C# UWP/WinRT 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# UWP/WinRT Example

Chilkat.Rest rest = new Chilkat.Rest();
bool success;

//  URL: https://demoauth.fatturazioneelettronica.aruba.it/auth/signin
bool bTls = true;
int port = 443;
bool bAutoReconnect = true;
success = await rest.ConnectAsync("demoauth.fatturazioneelettronica.aruba.it",port,bTls,bAutoReconnect);
if (success != true) {
    Debug.WriteLine("ConnectFailReason: " + Convert.ToString(rest.ConnectFailReason));
    Debug.WriteLine(rest.LastErrorText);
    return;
}

rest.AddQueryParam("grant_type","password");
rest.AddQueryParam("username","Utente");
rest.AddQueryParam("password","Password");

string strResponseBody = await rest.FullRequestFormUrlEncodedAsync("POST","/auth/signin");
if (rest.LastMethodSuccess != true) {
    Debug.WriteLine(rest.LastErrorText);
    return;
}

int respStatusCode = rest.ResponseStatusCode;
if (respStatusCode >= 400) {
    Debug.WriteLine("Response Status Code = " + Convert.ToString(respStatusCode));
    Debug.WriteLine("Response Header:");
    Debug.WriteLine(rest.ResponseHeader);
    Debug.WriteLine("Response Body:");
    Debug.WriteLine(strResponseBody);
    return;
}

Chilkat.JsonObject jsonResponse = new Chilkat.JsonObject();
jsonResponse.Load(strResponseBody);

//  See the Online Tool for Generating JSON Parse Code
string access_token;
string token_type;
int expires_in;
string refresh_token;
string client_id;
string userName;
string Issued;
string Expires;

access_token = jsonResponse.StringOf("access_token");
token_type = jsonResponse.StringOf("token_type");
expires_in = jsonResponse.IntOf("expires_in");
refresh_token = jsonResponse.StringOf("refresh_token");
client_id = jsonResponse.StringOf("client_id");
userName = jsonResponse.StringOf("userName");
Issued = jsonResponse.StringOf("\".issued\"");
Expires = jsonResponse.StringOf("\".expires\"");

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"
}