Explanation

The following provides a brief explanation of the Inrupt’s JavaScript client libraries usage in the Tutorial application code.

Login Code

The example uses Inrupt’s @inrupt/solid-client-authn-browser library to log in. @inrupt/solid-client-authn-browser is for client-side code only .

For applications implementing Authorization Code Flowarrow-up-right :

  1. The application starts the login process by sending the user to the user’s Solid Identity Provider.

  2. The user logs in to the Solid Identity Provider.

  3. The Solid Identity Provider sends the user back to your application, where the application handles the returned authentication information to complete the login process.

Import

The application uses various objects from @inrupt/solid-client-authn-browser to log in.

Start Login

The application starts the login process by calling login()arrow-up-right with the following options:

oidcIssuer

The URL of the user’s Solid Identity Provider. The function sends the user to this URL to log in. In this example, it is set to the value selected by the user.

circle-info

If you are not using PodSpaces, modify the select-idp options in the example’s index.html .

redirectUrl

The URL where the user, after logging in, will be redirected in order to finish the login process.

circle-info

The redirectUrl value should not change with application routes or hash or query parameters.

In this example, it is set to new URL("/", window.location.href).toString() (i.e., the root URL of this application https://localhost:8080/).

Alternatively, the example could have explicitly specified the index.html as the redirectURL; i.e., new URL("/index.html", window.location.href).toString().

clientName

A user-friendly application name to be passed to the Solid Identity Provider. The value is displayed in the Identity Provider’s Access Request approval window.

The login()arrow-up-right function sends the user to the Solid Identity Provider specified in oidcIssuer . Once the user logs in with the Identity Provider, the user is redirected back to the specified redirectUrl to finish the login process .

Finish Login

Once logged in at the Solid Identity Provider, the user is redirected back to the redirectUrl specified at the start of the login process (i.e., in the login() function call). The page at this redirectUrl calls handleIncomingRedirect()arrow-up-right to complete the login process.

In the example, the page calls handleRedirectAfterLogin() method, which, in turn, calls the handleIncomingRedirect()arrow-up-right :

The handleIncomingRedirect()arrow-up-right function collects the information provided by the Identity Provider. handleIncomingRedirect()arrow-up-right is a no-op if called outside the login processs.

For more information on using the library to authenticate, see Authentication.

Get Pods Code

The example uses Inrupt’s solid-client library to return the Pods associated with a WebID.

Import

The application uses various objects from @inrupt/solid-client . Additional import objects are displayed for the other read and write operations used in the application.

Get Pods

The application uses getPodUrlAllarrow-up-right to retrieve the Pod URLs (i.e., the value stored under http://www.w3.org/ns/pim/space#storage ) in the user’s profile.

Write Reading List

Import

The application uses various objects from solid-client and vocab-common-rdf libraries to write data to your Pod. Additional import objects are shown for read profile operations.

Create Reading List SolidDataset

The application uses getSolidDatasetarrow-up-right to retrieve an existing reading list from the URL.

circle-info

As an alternative to fetching an existing reading list and removing all titles from the list, you can instead attempt to deleteSolidDatasetarrow-up-right first, and then use createSolidDatasetarrow-up-right .

Add Items (Things) to Reading List

For each title entered by the user:

  • The application uses createThingarrow-up-right to create a new reading item Thing.

    • The application specifies the Thing’s name (optional) during its instantiation. Typically, a Thing’s URL is its SolidDataset URL (which ends with a /) appended with # and the Thing’s name; in this case:

      • ${podURL}getting-started/readingList/myList#title1,

      • ${podURL}getting-started/readingList/myList#title2, etc.

  • To the item, the application uses the following functions to add specific data:

    • addUrlarrow-up-right to add the http://www.w3.org/1999/02/22-rdf-syntax-ns#type property with the URL value https://www.w3.org/ns/activitystreams#Article The example uses the RDF.type and AS.Article convenience objects to specify the aforementioned property and value.

    • addStringNoLocalearrow-up-right to add the https://schema.org/name property with the string value set to one of the entered titles. The example uses the SCHEMA_INRUPT.name convenience object for the aforementioned property.

  • Then, the application uses setThingarrow-up-right to add the item to the SolidDataset (i.e., the reading list).

The solid-client library’s functions (such as the various add/set functions) do not modify the objects that are passed in as arguments. Instead, the library’s functions return a new object with the requested changes.

Save Reading List (SolidDataset)

circle-info

For the sake of simplicity and brevity, this getting started guide hardcodes the SolidDataset URL. In practice, you should add a link to this resource in your profile that applications can follow.

Use saveSolidDatasetAtarrow-up-right to save the reading list to <PodURL>getting-started/readingList/myList . saveSolidDatasetAtarrow-up-right creates any intermediate folders/containers as needed.

circle-info

The solid-client library also provides the saveSolidDatasetInContainerarrow-up-right . However, unlike saveSolidDatasetAtarrow-up-right which creates any intermediate folders/containers as needed, saveSolidDatasetInContainerarrow-up-right requires that the specified destination container already exists.

Upon successful save, saveSolidDatasetAtarrow-up-right returns a SolidDataset whose state reflects the data that was sent to be saved.

See also Create vs. Update Operations.

Verify the Save Operation

The save operation returns the SolidDataset (the reading list) whose state reflect the data that was sent to be saved. The savedReadingList may not accurately reflect the saved state of the data if concurrent operations have modified additional fields.

To ensure you have the latest data, the tutorial uses getSolidDatasetarrow-up-right again after saving the data.

The application uses SCHEMA_INRUPT.name convenience object from the vocab-common-rdf library to specify the property to retrieve.

Last updated