Register an app to start the authentication flow.
Authentication.register("alice.baq.run", {...});
Authentication
register(entity, appContent, options?)
: Promise<object>
Start registration of the app with the user’s server.
entity
Entity
appContent
AppRecordContent
options
object optional
icon
Blob optional : Image to use as app icon.
signal
AbortSignal optional : Abort the registration process.
flowUrl
string
state
AuthenticationState
complete(state, authorizationId)
: AuthenticationState
Update the authentication state with the authorization ID obtained after completion of the authorization flow.
state
AuthenticationState
authorizationId
string
AuthenticationState
Authentication data to persist locally.
Contains the private key used to sign requests.
entityRecord
EntityRecord
appRecord
AppRecord
credentialsRecord
CredentialsRecord
serverPublicKey
string
Base64 encoded server-issued public key.
Used to validate server responses.
authorizationId
string optional
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.