Create Access Requests/Grants

AccessGrantClient

The inrupt-client-accessgrant module provides an AccessGrantClientarrow-up-right that interacts with the ESS Access Grant Servicearrow-up-right to create/verify/query/fetch Access Requests and Grants.

To interact with the service, the AccessGrantClientarrow-up-right has the following methods:

Method
Description

Updates the status of the Access Requests/Grantss to revoked.

Queries for Access Requests and Grants.

Creates Access Request denials.

Performs validation checksarrow-up-right on Access Requests/Grantss, such as signature validation, date validation, etc.

To instantiate an AccessGrantClientarrow-up-right, you need to pass in the URI of the ESS Access Grant Service. For example, the Access Grant service for Inrupt’s PodSpaces runs at https://vc.inrupt.com.

Create an Access Request

An application can use AccessGrantClient.requestAccessarrow-up-right to create an Access Request.

For example, a user visits an ExamplePrinter’s website which provides photo printing services. When the ExamplePrinter’s web application asks for the photos to print, the user enters the URLs of the photos that are located in the user’s Pod. To continue, the ExamplePrinter’s backend server uses AccessGrantClient.requestAccessarrow-up-right to create Access Requests to read the photos.

1. Instantiate the Requestor’s AccessGrantClient

To instantiate an AccessGrantClientarrow-up-right, call the constructor with the following parameters:

Parameters
Descriptions

Access Grant Service URI

The root URL of the ESS Access Grant service.

Authenticated Session

The authenticated session of the requestor.

For example, the following instantiates an AccessGrantClientarrow-up-right for ExamplePrinter using the Inrupt PodSpaces Access Grant Service URI and ExamplePrinter’s authenticated session:

circle-info

In these examples, logic to initialize an authenticated session for ExamplePrinter has been omitted for brevity.

2. Create the Access Request

To create an Access Request, call AccessRequest.requestAccess with the request details:

Parameters
Descriptions

Resource Owner

The WebID of the agent who controls access to the requested resource(s).

Requested resource(s)

Resource(s) to which the access is being requested.

Requested access mode(s).

Requested access modes. Available modes are:

  • "Read",

  • "Write", and

  • "Append".

Optional. Purpose(s) for the request.

URI(s) indicating the stated purpose(s) for the request.

Optional (but Recommended) Expiration Date.

Expiration date of the Access Request and subsequent Access Grant, if approved.

ESS Access Grant Service may be configuredarrow-up-right to issue Access Requests and Grants with earlier expiration date.

The AccessRequest.requestAccess accepts:

AccessGrantClient.requestAccess(AccessRequest.RequestParameters)arrow-up-right accepts the Access Request details as AccessRequest.RequestParametersarrow-up-right. To build the AccessRequest.RequestParametersarrow-up-right object, you can use AccessRequest.RequestParameters.Builderarrow-up-right and its methods.

For example, the following code uses:

  • AccessRequest.RequestParameters.Builderarrow-up-right to specify the request details (i.e., the resource owner, the resources, the modes, the purposes, and the expiration); and

  • ExamplePrinter’s instantiated AccessGrantClient to create the request (i.e., the requestor is ExamplePrinter).

Create an Access Grant

Resource owners can use their access management application to view Access Requests made to them and decide whether to grant the requested access or not. If the resource owner decides to grant an Access Request, the access management application can call AccessGrantClient.grantAccessarrow-up-right to create an Access Grant. Optionally, the application can also call AccessGrantClient.verifyarrow-up-right to verify the Access Request before displaying it to the user.

For example, the user (the resource owner) who visited ExamplePrinter’s website to print pictures can login to a trusted access management application. The access management application can display the Access Request made to the user by the ExamplePrinter. If the user decides to grant the requested access, the application can create an Access Grant. The access manage application has a backend server that uses various AccessGrantClientarrow-up-right methods, namely:

1. Instantiate the Grantor’s AccessGrantClient

To instantiate an AccessGrantClientarrow-up-right for the grantor/resource owner, call the constructor with the following parameters:

Parameters
Descriptions

Access Grant Service URL

The root URL of the ESS Access Grant service

Authenticated Session

The authenticated session of the user (the resource owner).

For example, the following instantiates an AccessGrantClientarrow-up-right using Inrupt PodSpaces Access Grant Service URI and the resource owner’s session:

2. Get the Access Requests Made to the User

circle-info

The user can only retrieve Access Requests where the user is either the requestor (creator of the Access Request) or the resource owner (recipient of the Access Request).

If the Access Request’s id is known, the application can directly retrieve the Access Request using AccessGrantClient.fetcharrow-up-right with the Access Request’s id.

The fetch operation can return expired or future Access Requests.

3. Verify the Requested Access

To verify the Access Requestarrow-up-right, use AccessGrantClient.verifyarrow-up-right, passing it the Access Request.

For example, the following example uses AccessGrantClient.verifyarrow-up-right to verify an Access Request, checking for errors and warning.

4. Create the Access Grant

For a valid Access Request, if the resource owner decides to grant the requested access, the application can call AccessGrantClient.grantAccessarrow-up-right, passing in the specific Access Request to grant.

For example:

Last updated