Android™ 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'

Android™ Example

// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;

import android.app.Activity;
import com.chilkatsoft.*;

import android.widget.TextView;
import android.os.Bundle;

public class SimpleActivity extends Activity {

  private static final String TAG = "Chilkat";

  // Called when the activity is first created.
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    CkRest rest = new CkRest();
    boolean success;

    //  URL: https://demoauth.fatturazioneelettronica.aruba.it/auth/signin
    boolean bTls = true;
    int port = 443;
    boolean bAutoReconnect = true;
    success = rest.Connect("demoauth.fatturazioneelettronica.aruba.it",port,bTls,bAutoReconnect);
    if (success != true) {
        Log.i(TAG, "ConnectFailReason: " + String.valueOf(rest.get_ConnectFailReason()));
        Log.i(TAG, rest.lastErrorText());
        return;
        }

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

    String strResponseBody = rest.fullRequestFormUrlEncoded("POST","/auth/signin");
    if (rest.get_LastMethodSuccess() != true) {
        Log.i(TAG, rest.lastErrorText());
        return;
        }

    int respStatusCode = rest.get_ResponseStatusCode();
    if (respStatusCode >= 400) {
        Log.i(TAG, "Response Status Code = " + String.valueOf(respStatusCode));
        Log.i(TAG, "Response Header:");
        Log.i(TAG, rest.responseHeader());
        Log.i(TAG, "Response Body:");
        Log.i(TAG, strResponseBody);
        return;
        }

    CkJsonObject jsonResponse = new CkJsonObject();
    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\"");

  }

  static {
      System.loadLibrary("chilkat");

      // Note: If the incorrect library name is passed to System.loadLibrary,
      // then you will see the following error message at application startup:
      //"The application <your-application-name> has stopped unexpectedly. Please try again."
  }
}

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