Javascript SDK

Authentication

Register an app to start the authentication flow.

Authentication.register("alice.baq.run", {...});

Static methods

  • register(entity, appContent, options?): Promise<object>

    • Start registration of the app with the user’s server.

    • Parameters
      • entity Entity

        • Entity of the user to register with.
      • appContent AppRecordContent

      • options object optional

        • icon Blob optional : Image to use as app icon.

        • signal AbortSignal optional : Abort the registration process.

    • Return value properties
  • complete(state, authorizationId): AuthenticationState

    • Update the authentication state with the authorization ID obtained after completion of the authorization flow.

    • Parameters
      • state AuthenticationState

        • Partial authentication state to update.
      • authorizationId string

        • Result of the authorization flow.
    • Return value

Authentication data to persist locally.
Contains the private key used to sign requests.

Properties

  • entityRecord EntityRecord

    • Entity record of the authenticated user.
  • appRecord AppRecord

    • App record for the current app.
  • credentialsRecord CredentialsRecord

    • Public/private key pair used to sign requests.
  • serverPublicKey string

    • Base64 encoded server-issued public key.

    • Used to validate server responses.

  • authorizationId string optional

    • ID of the authorization record resulting from a successful flow.

The first step to getting an app authenticated with a user’s server is to register the app. This creates a new App record­ that describes the app and the permissions it wishes to be granted. In this example, we want to register a task management application that needs read and write access to task records.

import {Authentication} from "@baqhub/sdk";
import {TaskRecord} from "./baq/taskRecord.js";

const {flowUrl, state} = await Authentication.register(
  "alice.baq.run",
  {
    name: "BAQ Todo",
    description: "Manage your daily tasks with ease.",
    uris: {
      website: "https://baqtodo.app",
      redirect: "https://baqtodo.app/auth{/authorization_id}",
    },
    scopeRequest: {
      read: [TaskRecord.link],
      write: [TaskRecord.link],
    },
  }
);

// Next steps:
// 1. Persist local state.
// 2. Navigate user to "flowUrl" for the authorization flow.
© 2024 Quentez