Skip to Content
Authentication & SecurityConnect an Auth Provider

Authenticate a KalamDB Application

Sign in with a local account or your identity provider, then pass that identity to SQL and live subscriptions. Keep administrative credentials out of browser and mobile bundles.

Try KalamDB local authentication

After first-time server setup, create a normal application user as an administrator. This password is a local example; choose your own for a real account:

SQL
CREATE USER 'alice' WITH PASSWORD 'LocalExample123!' ROLE user;

In a Node.js development script, supply that user’s password through the environment:

TS
import { Auth, createClient } from '@kalamdb/client'; const client = createClient({  url: 'http://127.0.0.1:2900',  authProvider: async () => Auth.basic('alice', process.env.KALAM_PASSWORD!),}); console.log(await client.query('SELECT CURRENT_USER;'));await client.disconnect();

Expect the effective user identity in the query result. For a browser, use a sign-in flow and a token provider instead of embedding this password in source code. See the TypeScript authentication guide, Rust authentication, or Dart authentication for refresh and lifecycle handling.

Connect an external provider: Dex example

KalamDB uses one configured external OpenID Connect issuer. Dex is a reproducible local example; Keycloak and other compatible OIDC providers use the same issuer/client configuration model.

The KalamDB repository contains a local Dex setup:

BASH
cd KalamDB/docker/utilsdocker compose up -d dex

Merge these settings into the server’s server.toml, preserving its other configuration:

TOML
[auth]jwt_trusted_issuers = "kalamdb,http://127.0.0.1:5556" [auth.local]enabled = true [auth.oidc]enabled = truedisplay_name = "Dex"issuer = "http://127.0.0.1:5556"client_id = "client"scopes = ["openid", "email", "profile"]auto_provision = truedefault_role = "user"

Restart the server. The repository’s Dex client permits the Admin UI callback http://127.0.0.1:2900/ui/oauth/callback and CLI browser callback http://127.0.0.1:8787/callback. Open the Admin UI and select Dex, or run:

BASH
kalam login --instance local --url http://127.0.0.1:2900 --oidckalam --instance local -c 'SELECT CURRENT_USER;'

The bundled local Dex test account is alice@example.org with password kalamdb123. These are development fixtures, not deployment credentials. See Dex setup for the full configuration and device-login options.

Pass the provider identity to your SDK

After your application’s OIDC login flow returns the trusted ID token:

TS
import { Auth, createClient } from '@kalamdb/client'; const client = createClient({  url: 'https://database.example.com',  authProvider: async () => Auth.jwt(await getFreshIdToken()),});

getFreshIdToken() belongs to your identity-provider integration; it must return a valid, refreshed token rather than a hardcoded token. The issuer must match the server configuration and the audience must match its client/audience settings. Use HTTPS for deployed issuers, callbacks, and API endpoints.

KalamDB validates the token and maps the OIDC subject to the effective user. That identity determines USER-table isolation and CURRENT_USER in RLS policies. Do not grant every provisioned account an administrative role to work around an authorization error.

Check the complete flow

  1. Sign in as a normal user and query CURRENT_USER.
  2. Write and read that user’s data.
  3. Sign in as a second user and verify isolation.
  4. Open a live subscription with the same identity.
  5. Test token refresh and sign-out; stop old subscriptions when accounts change.

For another provider, replace the issuer, client ID, allowed callbacks, and audience with that provider’s values. KalamDB supports one external issuer per process; multiple tenants/providers require an intentional identity-broker design.

Next step

Protect shared data with row-level security →

Reference: OIDC configuration and issuer trust.