npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@applica-software-guru/iam-client

v1.1.65

Published

Libreria per l'accesso ai servizi REST IAM di Applica.

Downloads

175

Readme

Libreria per l'accesso ai servizi REST IAM di Applica.

| Info | Dettagli | | --------------- | ------------------------------------------------------ | | Ultima versione | 1.1.* | | Autore | Roberto Conte Rosito | | Repository | https://bitbucket.org/applicaguru/iam-client | | Pipeline | https://bitbucket.org/applicaguru/iam-client/pipelines |

Prefazione

La libreria @applica-software-guru/iam-client è un client REST che consente l'integrazione di servizi IAM Applica. La sua implementazione si basa sui principi e le linee guida definite all'interno del progetto React-Admin.

Come si usa

La libreria può essere utilizzata in associazione a react-admin come authProvider (scopo per cui è nata) oppure direttamente come strumento per eseguire il login, aggiornare i token di autenticazione e, in generale, mantenere uno stato di sessione valido per l'utente potendo usufruire di tutti i metodi esposti da un provider IAM Applica.

Per installare la libreria:

npm i @applica-software-guru/iam-client

Puoi utilizzarla all'interno di un progetto react-admin come authProvider seguendo la guida ufficiale.

Configurazione

Puoi configurare e rendere persistente un'istanza di authProvider utilizzando il metodo useAuthProvider:

const apiUrl = 'http://localhost:8080/api';
const authProvider = createAuthProvider({ apiUrl });

Un eventuale (e quasi sicuro) dataProvider che dovrai configurare potrà usufruire di una serie di metodi tecnici, esposti da authProvider, che gli consentiranno di comunicare in sicurezza con i servizi IAM Applica.

const getToken = async () => await authProvider.getToken();
const getHeaders = async () => await authProvider.getHeaders();
const dataProvider = createDataProvider({ apiUrl, getToken, getHeaders });

Applica Auth Provider

Per utilizzare il provider con le firme di applica puoi utilizzare useApplicaAuthProvider al posto di useAuthProvider di react-admin:

const authProvider = useApplicaAuthProvider({ apiUrl });

Login

Per effettuare il login puoi utilizzare il metodo login:

const login = await authProvider.login({
  username: 'admin',
  password: 'admin'
});

Logout

Per effettuare il logout puoi utilizzare il metodo logout:

await authProvider.logout();

Check Auth

Per verificare che il token autorizzativo attuale sia valido e per aggiornarlo se necessario puoi utilizzare il metodo checkAuth:

const checkAuth = await authProvider.checkAuth();

Questo metodo provvederà a rinnovare il token autorizzativo.

Get Permissions

Per ottenere i permessi dell'utente puoi utilizzare il metodo getPermissions:

const getPermissions = await authProvider.getPermissions();

Questo metodo restituisce un array di permessi, ogni permesso è una stringa che segue la formattazione entity:permission, per esempio:

  • users:save
  • users:delete
  • users:new
  • users:edit
  • users:list

Get Roles

Per ottenere i ruoli dell'utente puoi utilizzare il metodo getRoles:

const getRoles = await authProvider.getRoles();

Questo metodo restituisce un array di ruoli, ogni ruolo è una stringa.

Get Identity

Per ottenere l'identità dell'utente puoi utilizzare il metodo getIdentity:

const identity = await authProvider.getIdentity();

Impersonate

Per impersonare un utente puoi utilizzare il metodo impersonate:

const user = await authProvider.impersonate('<id>');
const isImpersonating = await authProvider.isImpersonating();
await authProvider.stopImpersonating();

Storage

Puoi utilizzare uno storage differente dal localStorage presente all'interno del browser (per esempio se devi utilizzare questa libreria all'interno di un applicativo react-admin), per farlo devi passare un'istanza di Storage al metodo useAuthProvider:

import { LocalStorage } from '@applica-software-guru/iam-client';
const storage = new LocalStorage();
const authProvider = useAuthProvider({ apiUrl, storage });

Se utilizzi la libreria sul web puoi utilizzare l'implementazione LocalStorage che non è altro che un wrapper di window.localStorage.

Di seguito un esempio di implementazione di MemoryStorage:

import { StorageInterface } from '@applica-software-guru/iam-client';

/**
 * Implementazione di StorageInterface che utilizza un oggetto in memoria.
 */
class MemoryStorage implements StorageInterface {
  storage: any;

  constructor() {
    this.storage = {};
  }

  getItem(key: string): Promise<string> {
    if (typeof this.storage[key] === 'undefined') {
      return Promise.resolve('');
    }
    return Promise.resolve(this.storage[key]);
  }
  setItem(key: string, value: string): Promise<void> {
    this.storage[key] = value;
    return Promise.resolve();
  }
  removeItem(key: string): Promise<void> {
    delete this.storage[key];
    return Promise.resolve();
  }
}

export default MemoryStorage;