1.0.0-rc.24 • Published 2 months ago

@janeirodigital/interop-authorization-agent v1.0.0-rc.24

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

Authorization Agent

CI codecov Gitter chat npm version MIT license

Early access

Specifications this library implements are still a work in progress. While we track changes to the public API of this library with semver, the underlying data will be slightly changing for the rest of 2021. We are commited to keep this implementation up to date. If you plan to use your application in production please ask the specification editors on the public chatroom about the stability of the data model.

Service

An open-source implementation of a full service using this library is also available: sai-impl-service (under active development)

Creating Authorization Agent instance

Authorization Agent class provides a static build method to create instances. It expects:

  • webId - WebID of the user which this instance will be an authorization agent of.
  • agentId - Unique IRI denoting this instance. The user will add it to their WebID and it will be used as client_id in Solid-OIDC
  • dependencies
import { randomUUID } from 'crypto';
import { getSessionFromStorage, Session } from '@inrupt/solid-client-authn-node';
import { AuthorizationAgent } from '@janeirodigital/interop-authorization-agent';

import { storage } from './oidc-storage';

const webId = 'https://alice.example/#id';
const agentId = 'https://authz.alice.example/';

// we assume that webId was used as sessionId the when session was created
const session = await getSessionFromStorage(webId, storage);

const agent = AuthorizationAgent.build(webId, clientId, {
  fetch: oidcSession.fetch,
  randomUUID
});

Agent Registry

An instance of Authorization Agent provides a useful method for accessing agent registrations

Application Registrations

applicationRegistrations(): AsyncIterable<CRUDApplicationRegistration is an async iterable over all the application registrations

for await (const registration of agent.applicationRegistrations) {
  // do something with the application registration
}

async findApplicationRegistration(iri: string): Promise<CRUDApplicationRegistration | undefined> finds an application registration based on client_id, if one exists

const clientId = 'https://projectron.example/#app';
const registration = await agent.findApplicationRegistration(clientId);

Social Agent Registrations

socialAgentRegistrations(): AsyncIterable<CRUDSocialAgentRegistration> is an async iterable over all the social agent registrations

for await (const registration of agent.socialAgentRegistrations) {
  // do something with the social agent registration
}

findSocialAgentRegistration(iri: string): Promise<CRUDSocialAgentRegistration | undefined> finds a social registration based on webid, if one exists

const webId = 'https://alice.example/#id';
const registration = await agent.findSocialAgentRegistration(webId);

Access Authorization

Creating Access Authorizations is the primary responsibility of an Authorization Agent.

async recordAccessAuthorization(authorization: AccessAuthorizationStructure): Promise<ReadableAccessAuthorization>

Since access authorization is immutable, it is required to create a new one to replace the old one.

type AccessAuthorizationStructure = {
  grantee: string; // webid or clientid
  hasAccessNeedGroup: string; // iri
  dataAuthorizations: DataAuthorizationData[];
};
type DataAuthorizationData = {
  grantee: string; // webid or clientid
  registeredShapeTree: string;
  scopeOfAuthorization: string;
  accessMode: string[];
  dataOwner?: string; // webid
  hasDataRegistration?: string;
  inheritsFromAuthorization?: string;
  creatorAccessMode?: string[];
  hasDataInstance?: string[];
};

Access Grant

Based on existing Access Authorization an Access Grant can be created

async generateAccessGrant(accessAuthorizationIri: string): Promise<void>

This method updates the appropriate agent registration to reference the newly created access grant.

const authorizationData: AccessAuthorizationStructure = {
  /* all the data */
};
const authorization = await agent.recordAccessAuthorization(authorizationData);
await agent.generateAccessGrant(authorization.iri);

Funding

This project is funded through the NGI Zero Entrust Fund, a fund established by NLnet with financial support from the European Commission's Next Generation Internet program. Learn more at the NLnet project page.

1.0.0-rc.24

2 months ago

1.0.0-rc.23

5 months ago

1.0.0-rc.22

6 months ago

1.0.0-rc.21

11 months ago

1.0.0-rc.20

11 months ago

1.0.0-rc.19

11 months ago

1.0.0-rc.18

1 year ago

1.0.0-rc.16

1 year ago

1.0.0-rc.15

1 year ago

1.0.0-rc.9

2 years ago

1.0.0-rc.13

2 years ago

1.0.0-rc.12

2 years ago

1.0.0-rc.11

2 years ago

1.0.0-rc.10

2 years ago

1.0.0-rc.14

2 years ago

1.0.0-rc.8

2 years ago

1.0.0-rc.7

2 years ago

1.0.0-rc.5

2 years ago

1.0.0-rc.6

2 years ago

1.0.0-rc.4

2 years ago

1.0.0-rc.3

2 years ago