Frauthy
SDK ReferencePrivate beta

SDK Reference

Application SDK

Private beta  ·  TypeScript

The stable app-layer contract. One call chain:createFrauthy(config) →session(req) →can(action, resource) →boolean.

  1. 01Priority 1

    TypeScript

    Published and supported as the primary SDK.

    Published
  2. 02Priority 2

    Rust

    An implementation exists alongside the TypeScript contract.

    Exists
  3. 03Priority 3

    Go

    A native Go implementation is planned.

    Planned
  4. 04Priority 4

    Python

    A native Python implementation is planned.

    Planned
00

Reference status

Truthful availability

This page is the canonical TypeScript reference for the private-beta application SDK.

Approved participants receive package coordinates, compatibility details, and access instructions through the private-beta channel. Public examples retain the API contract without exposing executable setup.

SDK language references

  • TypeScript

    Canonical private-beta reference on this page.

    availablePrivate betaOpen reference
  • Rust

    An implementation exists, but a detailed public reference is not published. No dead route is exposed.

    unavailable
  • Go

    An implementation exists, but a detailed public reference is not published. No dead route is exposed.

    unavailable
  • Python

    An implementation exists, but a detailed public reference is not published. No dead route is exposed.

    unavailable
01

Installation

Setup

Package coordinates and setup instructions are provided only to approved private-beta participants.

Approved access

# Approved private-beta participants
[PRIVATE_BETA_INSTALL_INSTRUCTIONS_REDACTED]
Private-beta access. Approved participants receive compatibility and package-client guidance with their invitation.
02

Quick start

Usage

Two steps: configure a Frauthy instance, then guard routes with session and can.

frauthy.ts — Configuration

import { createFrauthy, resource } from "[PRIVATE_BETA_PACKAGE_COORDINATE_REDACTED]";

const portal = resource("portal", "gpfamily");

const frauthy = createFrauthy({
  provider: { issuer: "https://login.mypeople.com", audience: "gpfamily-portal" },
  store: {
    kind: "spicedb",
    endpoint: "https://spicedb.prod.example.com:8443",
    token: process.env.SPICEDB_TOKEN!,
  },
  mapping: [{
    claimField: "email_domain",
    match: { kind: "domain_equals", value: "mypeople.com" },
    emit: { object: "domain:{domain}", relation: "member", subject: "user:{sub}" },
  }],
  telemetry: {
    enabled: true,
    endpoint: "https://ingest.frauthy.cloud",
    apiKey: process.env.FRAUTHY_CLOUD_API_KEY,
    serviceName: "gpfamily-portal",
  },
});

server.ts — Request handler

app.get("/portal", async (req) => {
  const session = await frauthy.session(req);
  if (await session.can("access", portal)) {
    return render("portal");
  }
  return new Response(null, { status: 403 });
});
03

createFrauthy(config)

Factory

The main factory function. Accepts a FrauthyConfig object and returns a configured Frauthy instance.

  1. 01

    provider

    Authentication. OIDC token verification supports issuer plus audience, or an explicit audience-validation opt-out.

  2. 02

    store

    Authorization. Configure the relationship store with kind, endpoint, optional token, and local-development TLS override.

  3. 03

    mapping

    MappingRule[] turns verified claims into relationship writes. Each rule defines claimField, match, and emit.

  4. 04

    cookieName

    The token-extraction cookie name. Defaults to frauthy_session.

  5. 05

    telemetry

    TelemetryConfig controls OTLP trace emission; see Section 05.

Return value

Returns a Frauthy instance with two methods:

Method

session(req: Request)

Extract bearer/cookie token, verify via provider, run mapping rules, return a Session. Throws UnauthenticatedError on invalid or missing tokens.

Method

sessionFromClaims(claims)

Skip token extraction and build a session from pre-verified claims. Useful for S2S calls, tests, and local development.

// Return type
interface Frauthy {
  session(req: Request): Promise<Session>;
  sessionFromClaims(claims: CanonicalClaims): Promise<Session>;
}
04

Session

Runtime

The session object returned by frauthy.session(). Carries the verified identity and exposes permission checks against the relationship store.

Permission methods

Check

can(action, resource)

Single permission check. Returns Promise<boolean>.

Check

cannot(action, resource)

Negated check. Returns Promise<boolean>.

Batch

canAll(checks)

True only if all { action, resource } checks pass. Returns Promise<boolean>.

Lookup

lookupResources(action, type)

Which resources this subject can reach. Returns Promise<string[]>.

Identity properties

  1. 01

    claims

    CanonicalClaims — the complete verified identity claim set from the token.

  2. 02

    sub

    string — shorthand for claims.sub.

  3. 03

    email

    string | undefined — shorthand for claims.email.

  4. 04

    emailVerified

    boolean — shorthand for claims.emailVerified.

// Full Session interface
interface Session {
  can(action: string, resource: Resource): Promise<boolean>;
  cannot(action: string, resource: Resource): Promise<boolean>;
  canAll(checks: PermissionCheck[]): Promise<boolean>;
  lookupResources(action: string, resourceType: string): Promise<string[]>;
  readonly claims: CanonicalClaims;
  readonly sub: string;
  readonly email: string | undefined;
  readonly emailVerified: boolean;
}
05

TelemetryConfig

Observability

OTLP-based trace emission. Zero overhead when disabled — no spans are created, no exporter is loaded.

  1. 01

    enabled

    boolean — defaults to false. This master switch keeps telemetry zero-overhead when disabled.

  2. 02

    endpoint

    string — defaults to http://localhost:4318, the OTLP/HTTP collector URL.

  3. 03

    serviceName

    string — defaults to frauthy-app and is reported in resource attributes.

  4. 04

    apiKey

    string — bearer token for OTLP export, required for Frauthy Cloud ingest.

  5. 05

    headers

    Record<string, string> — additional headers attached to OTLP export requests.

  6. 06

    exporter

    (payload) => void — custom export function replacing the built-in OTLP HTTP exporter.

// Full TelemetryConfig interface
interface TelemetryConfig {
  enabled?: boolean;           // default: false
  endpoint?: string;          // default: "http://localhost:4318"
  serviceName?: string;       // default: "frauthy-app"
  apiKey?: string;
  headers?: Record<string, string>;
  exporter?: (payload: unknown) => void;
}
06

Security behaviors

Guardrails

Three built-in guardrails that enforce safe defaults. These are not configurable — they are always active.

email_verified enforcement

Mapping rules with email_domain or email as the claimField are silently skipped when emailVerified is false. Unverified email addresses never produce relationship writes.

Store TLS guard

SpiceDbStore rejects non-HTTPS endpoints unless the host is localhost. Pass allowInsecure: true in the store config for Docker-based local development.

StubProvider production guard

StubProvider throws when NODE_ENV=production. Override with FRAUTHY_ALLOW_STUB=1 if you need stubs in a production-like environment.

Design principle. These guards prevent classes of misconfiguration that lead to security incidents. They are enforced at the SDK level, not the application level, so they cannot be accidentally bypassed.
07

Framework adapters

Integration

Express, Hono, Next.js, and Astro adapters ship with the SDK. Each adapter wraps createFrauthy into the framework's native middleware or handler pattern.

Express

expressFrauthyMiddleware

Classic Express middleware. Attaches req.session on authenticated requests.

Hono

honoFrauthyMiddleware

Hono middleware. Sets c.var.session in the context.

Next.js

withFrauthy · checkPermission

HOC and route-level guard for App Router server components and API routes.

Astro

astroFrauthyMiddleware

Astro middleware. Injects session into Astro.locals.

Imports

// Express
import { expressFrauthyMiddleware } from "[PRIVATE_BETA_PACKAGE_COORDINATE_REDACTED]";

// Hono
import { honoFrauthyMiddleware } from "[PRIVATE_BETA_PACKAGE_COORDINATE_REDACTED]";

// Next.js
import { withFrauthy, checkPermission } from "[PRIVATE_BETA_PACKAGE_COORDINATE_REDACTED]";

// Astro
import { astroFrauthyMiddleware } from "[PRIVATE_BETA_PACKAGE_COORDINATE_REDACTED]";

Frauthy

SDK reference for the stable app-layer contract — authentication and fine-grained authorization in one call chain.

Package [PRIVATE_BETA_PACKAGE_COORDINATE_REDACTED]
Version Private beta · TypeScript
Access Approved participants
License Proprietary
violet = authentication / identity  ·  coral = authorization / permission  ·  Fraunces · IBM Plex Sans · IBM Plex Mono