Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@entur-partner/permission-client-node

Package Overview
Dependencies
Maintainers
7
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@entur-partner/permission-client-node

Node client library for Permission Store

  • 2.3.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
7
Created
Source

Permission Client for Node

Javascript modul som tilbyr en cache av bruker rettigheter fra Permission Store.

Oppsett for bruk

Basis

npm install @entur-partner/permission-client-node

# alternativt yarn add auth0 @entur-partner/permission-client-node

WebSocket

Planlegger en å motta WebSocket push meldinger trengs følgende pakkener:

yarn add @stomp/stompjs websocket

I tillegg trengs det å kjøre følgende ved oppstart av tjenesten:

Object.assign(global, { WebSocket: require('websocket').w3cwebsocket });

Eksempel på bruk

TokenFactory

Benyttes for å hente ut access tokens from Auth0 ved bruk av klient id og klient hemmelighet (Auth0 Clients)

import {TokenOptions, TokenFactory} from '@entur-private/permission-client-node'
const clientTokenOptions : TokenOptions = {
    domain: 'internal.dev.entur.org',
    clientId: '<clientId>',
    clientSecret: '<secret>',
    audience: 'https://api.dev.entur.io',
    refreshBeforeMinValidSeconds: 600  // getAccessToken() vil fornye token den retuner, når acess token er gyldig i mindre enn 10 minutter.
}
const accessTokenFactory = new TokenFactory(clientTokenOptions);

// Eksempel bruk av TokenFactory
const accessToken = await accessTokenFactory.getAccessToken();

AuthorizeCache

Ønsker en å sjekke hvilke rettigheter en bruker har i Permission Store benyttes PermissionClient.

import {AuthorizeCacheType, Application, ApplicationPermission, PermissionDeliverRepository} from '@entur-private/permission-client-node'
import PermissionClient from '@entur-private/permission-client-node'
const application : Application = {
    name : 'TestApplication',
    refreshRate : 300  // Hver 5 minutt sjekkes Permission Store for endringer
}
const permissionStoreUrl = new URL('https://api.dev.entur.io/permission-store/v1');
const repository = new PermissionDeliverRepository(application, accessTokenFactory, permissionStoreUrl);

// Definerer rettigheter som benyttes av tjenesten
const applicationpermissions : ApplicationPermission[] = [];
applicationpermissions.push({operation: 'produkt', access: 'les', responsibilityType: null});
applicationpermissions.push({operation: 'produkt', access: 'les', responsibilityType: 'produkt.organisation'});
applicationpermissions.push({operation: 'produkt', access: 'les', responsibilityType: 'produkt.id'});

// Ved bruk at poll skriv følgende:
const autorizeCache = await PermissionClient(AuthorizeCacheType.IN_MEMORY, applicationpermissions, repository);

// Optional for å benytte WebSocket. NB! Pass på at angitt permissionStoreUrl støtter WebSocket og ikke går via APIGEE      
// const autorizeCache = await PermissionClient(AuthorizeCacheType.IN_MEMORY, applicationpermissions, repository, { communicationType: CommunicationType.SocketJS });

// autorizeCache are ready to be used like:
const hasBCAccess = autorizeCache.checkBusinessCapabilityPermission(authoritySubject, businessCapability);
const hasRSAccess = autorizeCache.checkResponsibilitySetPermission(authoritySubject, responsibilitySet);
const userPermissions = getPermissions(authoritySubject);

Bidrag til vidreutvikling

Clone modulen fra Bitbucket med:

git clone https://<username>@bitbucket.org/enturas/permission-client-node.git

Innstaller avhengigeter fra konsoll på roten av prosjektet:

npm install

Enhetstester utviklet i Jest kjøres ned:

npm test

Publisering

Oppgrader versjon

npm version <major | minor | patch> 

Opprett en NPM user account på https://www.npmjs.com/signup. Send brukeren din til tech-lead i Entur Partner og be om å bli lagt til i Entur Partner organisation.

Publisering utføres ved å skrive:

npm publish

FAQs

Package last updated on 25 Aug 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc