Guides

Authentication

OAuth2 flow management

Authentication

The Aruba API uses OAuth2 with password grant type.

Login

import { ArubaClient } from '@fatturazione-elettronica-aruba/core';

const client = new ArubaClient({ environment: 'demo' });

const result = await client.auth.signin('username', 'password');

console.log('Access Token:', result.access_token);
console.log('Expires in:', result.expires_in, 'seconds'); // 1800s = 30 min

Refresh Token

Refresh token is valid for 60 minutes:

const newToken = await client.auth.refresh(refreshToken);

The SDK automatically refreshes tokens during API calls.

User Info

const userInfo = await client.auth.getUserInfo();

console.log('Username:', userInfo.username);
console.log('VAT:', userInfo.vatCode);
console.log('Space used:', userInfo.usageStatus.usedSpaceKB, 'KB');

Multi-company (Premium)

const multicedenti = await client.auth.getMulticedenti({
  page: 0,
  size: 20,
});

for (const cedente of multicedenti.content) {
  console.log(`${cedente.id}: ${cedente.description}`);
}

Custom Token Storage

const client = new ArubaClient({
  environment: 'production',
  tokenStorage: {
    getToken: async () => {
      const stored = await redis.get('aruba:token');
      return stored ? JSON.parse(stored) : null;
    },
    setToken: async (token) => {
      await redis.set('aruba:token', JSON.stringify(token), 'EX', 3600);
    },
    clearToken: async () => {
      await redis.del('aruba:token');
    },
  },
});