Access Prompt and Use of Access Grant
This method allows users to share data with third parties directly. Users start the process, prompting the Wallet to generate an Access Request. It involves sending the application clientID and data type, activating the Wallet to send an Access Request.
Here's the flow:
A user interacts with services without prior knowledge; the service needs enough user information for an Access Request. The Access Prompt endpoint enables the user's wallet to provide user details to the service. The encoded resource type and service clientID help determine the necessary resource.
async function sendAccessPrompt(clientId, webId, resourceUri) {
const response = await fetch('https://businessapp.com/accessprompt', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
clientId: clientId,
webId: webId,
resourceUri: resourceUri
})
});
if (response.ok) {
const data = await response.json();
return data;
}
throw new Error(`Failed to send Access Prompt: ${response.status}`);
}
Once the Access Prompt is successfully called using the sendAccessPrompt
function, the business application should generate an Access Request tailored to the user's information. This request will then be sent to the user's inbox, allowing them to review and approve the data sharing with the third-party service. These functions can be found in Make Your First Business Application.
Receiving and Granting Access Request
After the Access Request is sent to the user's inbox, the user can review the details of the data being shared with the third-party service and approve the request if they agree to the terms.
Overview of Deliver Access Grant Integration
The queryAccessGrant
function is designed to initialize the business app session and send a GET
request to the Access Grant endpoint to query active Access Grants for a specific resource. Upon a successful response, it retrieves all Access Grants in JSON format to be used to fetch the resource.
async function queryAccessGrant() {
const session = await initializeAndLoginSession();
const vcEndpoint = `https://vc.inrupt.com/`;
const resource = userWalletStorage + '/wallet/text.txt';
const query = vcEndpoint + "query?type=SolidAccessGrant&status=Active&resource=resource";
if (!session) {
throw new Error("Session is undefined");
}
const response = await session.fetch(query, {
method: "GET",
});
if (response.status === 200) {
const fecthAccessGrant = await response.json();
return fetchAccessGrant;
}
}
The readFileWithAccessGrant
function utilizes an Access Grant to fetch a resource from the user's Pod. It retrieves the Access Grant by calling the previous function queryAccessGrant
, then uses this grant and the business app session to access and read the specified resource using the getFile
function from the Client library.
import {getFile} from "@inrupt/solid-client-access-grants";
async function readFileWithAccessGrant(resource) {
// Get the access grant
const myAccessGrantVC = await queryAccessGrant();
const session = await initializeAndLoginSession();
// Use the access grant to read the file
const file = await getFile(
resource,
myAccessGrantVC,
{ fetch: session.fetch }
);
return file;
}
Last updated