Authentication

Authentication directly from Browser

To initiate a login process from a browser, the startLogin function checks whether the user is already logged in by examining the session's login status. If not logged in, it uses the login function from @inrupt/solid-client-authn-browser to start the login process, specifying the OpenID Connect issuer, redirect URL, and client name. After the login process, completeLogin is used to handle the incoming redirect and complete the authentication by processing the server's response.

You can use https://login.inrupt.com OIDC provider for this if you do not have your own set up.

import {  login, getDefaultSession } from '@inrupt/solid-client-authn-browser'

// ...

async function startLogin() {
  // Start the Login Process if not already logged in.
  if (!getDefaultSession().info.isLoggedIn) {
    await login({
      oidcIssuer: "https://login.inrupt.com",
      redirectUrl: new URL("/callback", window.location.href).toString(),
      clientName: "My application"
    });
  }
}

Callback Function

After the login process, completeLogin is used in the application code to handle the incoming redirect and complete the authentication by processing the server's response.

Authentication Server Side via OIDC auth-code grant

The server-side code utilizes Express.js to create a new session for each user and manage it using cookies. When a user accesses the /login endpoint, a new session is created, and the user is redirected to the Solid Identity Provider's login page to authenticate. The session data is stored, and after the authentication process is completed, the user is redirected back to /login/callback, where the authentication response is handled to finalize the login process.

Callback Function

The provided code snippet demonstrates how to handle the login callback process after a user logs in via a Solid Identity Provider. It retrieves the session from storage, finalizes the login using session data from the callback URL, and confirms successful authentication by checking the isLoggedIn status. Additionally, it includes routes to perform authenticated fetch operations and handle user logout.

Logout

The code snippet implements a logout route for the application, which retrieves the user's session from storage using the session ID stored in cookies and then logs the user out, sending a simple confirmation message that the user has been logged out.

Authentication for Server Side Single-User Applications

To authenticate a server side single-user application, this code utilizes Inrupt's solid-client-authn-node library. It first requires the developer to register their app with a Solid OIDC identity provider (such as login.inrupt.com) to obtain a clientId and clientSecret. These credentials are then used to initiate a session, allowing the application to make secure, authenticated requests to the user's resources.

Last updated