@inrupt/solid-client-authn-node
    Preparing search index...

    Class Session

    A Session object represents a user's session on an application. The session holds state, as it stores information enabling access to private resources after login for instance.

    Implements

    • IHasSessionEventListener
    Index

    Constructors

    • Session object constructor. Typically called as follows:

      const session = new Session(
      {
      clientAuthentication: getClientAuthenticationWithDependencies({})
      },
      "mySession"
      );

      Parameters

      • sessionOptions: Partial<ISessionOptions> = {}

        The options enabling the correct instantiation of the session. Either both storages or clientAuthentication are required. For more information, see ISessionOptions.

      • sessionId: undefined | string = undefined

        A string uniquely identifying the session.

      Returns Session

    Properties

    events: ISessionEventListener

    Session attribute exposing the EventEmitter interface, to listen on session events such as login, logout, etc.

    1.14.0

    fetch: {
        (input: URL | RequestInfo, init?: RequestInit): Promise<Response>;
        (input: string | URL | Request, init?: RequestInit): Promise<Response>;
    } = ...

    Fetches data using available login information. If the user is not logged in, this will behave as a regular fetch. The signature of this method is identical to the canonical fetch.

    Type Declaration

      • (input: URL | RequestInfo, init?: RequestInit): Promise<Response>
      • Parameters

        • input: URL | RequestInfo
        • Optionalinit: RequestInit

        Returns Promise<Response>

      • (input: string | URL | Request, init?: RequestInit): Promise<Response>
      • Parameters

        • input: string | URL | Request
        • Optionalinit: RequestInit

        Returns Promise<Response>

    The URL from which data should be fetched.

    Optional parameters customizing the request, by specifying an HTTP method, headers, a body, etc. Follows the WHATWG Fetch Standard.

    Information regarding the current session.

    Methods

    • Completes the login process by processing the information provided by the identity provider through redirect.

      Parameters

      • url: string

        The URL of the page handling the redirect, including the query parameters — these contain the information to process the login.

      Returns Promise<undefined | ISessionInfo>

    • Triggers the login process. Note that this method will redirect the user away from your app.

      Parameters

      • Optionaloptions: ILoginInputOptions

        Parameter to customize the login behaviour. In particular, two options are mandatory: options.oidcIssuer, the user's identity provider, and options.redirectUrl, the URL to which the user will be redirected after logging in their identity provider.

      Returns Promise<void>

      This method should redirect the user away from the app: it does not return anything. The login process is completed by handleIncomingRedirect.

    • Logs the user out of the application.

      There are 2 types of logout supported by this library, app logout and idp logout.

      App logout will log the user out within the application by clearing any session data from the browser. It does not log the user out of their Solid identity provider, and should not redirect the user away. App logout can be performed as follows:

      await session.logout({ logoutType: 'app' });
      

      IDP logout will log the user out of their Solid identity provider, and will redirect the user away from the application to do so. In order for users to be redirected back to postLogoutUrl you MUST include the postLogoutUrl value in the post_logout_redirect_uris field in the Client ID Document. IDP logout can be performed as follows:

      await session.logout({
      logoutType: 'idp',
      // An optional URL to redirect to after logout has completed;
      // this MUST match a logout URL listed in the Client ID Document
      // of the application that is logged in.
      // If the application is logged in with a Client ID that is not
      // a URI dereferencing to a Client ID Document then users will
      // not be redirected back to the `postLogoutUrl` after logout.
      postLogoutUrl: 'https://example.com/logout',
      // An optional value to be included in the query parameters
      // when the IDP provider redirects the user to the postLogoutRedirectUrl.
      state: "my-state"
      });

      Parameters

      Returns Promise<void>

    • Creates a session from auth state information (code verifier and state) This is useful for continuing the auth code flow after storing the auth state in an external database in clustered deployments.

      Parameters

      • authorizationRequestState: AuthorizationRequestState

        Object containing codeVerifier and state needed to continue the auth flow

      • sessionId: undefined | string = undefined

        Optional ID for the session, if not provided a random UUID will be generated

      Returns Promise<Session>

      A Session instance with enough context to continue the auth code flow

      2.5.0

      const session = Session.fromAuthorizationRequestState(authorizationRequestState, "my-session-id");

      // Use the restored session
      const info = await session.handleIncomingRedirect(originalUrl);
    • Creates a session from a set of tokens without requiring a full login flow. This is useful for scenarios where you already have tokens from another source and want to create an authenticated session directly.

      Parameters

      • sessionTokenSet: SessionTokenSet

        The token set to use for authentication

      • sessionId: undefined | string = undefined

        Optional ID for the session, if not provided a random UUID will be generated

      Returns Promise<Session>

      A Session instance

      2.4.0

      const session = Session.fromTokens(mySessionTokenSet, "my-session-id");

      // Use the authenticated session
      const response = await session.fetch("https://pod.example.com/private-resource");