Use Access Grants to Access Resources#


The inrupt-client-accessgrant module includes AccessGrantSession that builds an authenticated Session object using both Access Grants and an OpenID-based session. (For more information on OpenID-based sessions, see Session Management.)

For example, once ExamplePrinter app receives an access grant, it can use the grant to access the resource(s) for printing; namely:

  1. Fetch the access grant:

    Session myOpenIDSession = OpenIdSession.ofIdToken(idToken);    // idToken of ExamplePrinter
    URI MY_ESS_ACCESS_GRANT_SERVICE = URI.create("https://vc.{MY_ESS_DOMAIN}.com");
    AccessGrantClient accessgrantclient = new AccessGrantClient(MY_ESS_ACCESS_GRANT_SERVICE)
        .session(myOpenIDSession);     // the authenticated session of ExamplePrinter
    AccessGrant grant = accessgrantclient.fetch(URI.create("https://vc.{ESS DOMAIN}/vc/xxxxxx..."));
  2. Create a AccessGrantSession using both the ExamplePrinter’s OpenID Session and the access grant:

    Session agSession = AccessGrantSession.ofAccessGrant(myOpenIDSession, grant);
  3. Create a SolidClient (or SolidSyncClient) using this AccessGrantSession:

    SolidClient client = SolidClient.getClient().session(agSession);

    Use the .send() method to access the non-RDF resources and .read() method to read RDF resources.