[data-reveal]{opacity:1!important;transform:none!important}
AntelopeJS DMS
DocumentationIntroduction

Introduction

The auth domain answers who is calling: authentication decorators, tokens and sessions, users and external identities.

Overview

The auth domain of @antelopejs/interface-dms answers one question for the DMS: who is calling. It resolves the bearer token of an HTTP request into a User row. It issues and validates the tokens that make such a request possible, records logins as sessions, and binds the accounts a user owns on external login providers. It also owns the users, sessions and user_external_identities tables and their models.

The domain stops at identity. The Core domain decides what an authenticated caller may do, through permissions, roles and tenant membership. Its tenant guards build on the authenticateRequestUser function this domain exports.

The domain is published under three subpaths:

SubpathContents
@antelopejs/interface-dms/authThe authentication decorators, authenticateRequestUser, the token generators and validators, createSession, sanitizeUser, the external-identity functions, announceRegistration, the account mail functions, bindVerifiedRequestIdentity, and the RequestPrincipal, RequestAuthenticator and VerifiedRequestIdentity types.
@antelopejs/interface-dms/auth/dbThe User, Session and UserExternalIdentity tables, their models, the table-name constants, normalizeEmail, isCurrentRefreshToken and buildExternalIdentityId.
@antelopejs/interface-dms/auth/passwordThe password policy: PASSWORD_MIN_LENGTH, PASSWORD_PATTERN and isPasswordCompliant. These are plain values and a pure function, usable without the DMS loaded.

What the domain provides

  • Request authentication decorators. AuthUser and AuthRawUser gate a route, a controller property, or a whole controller class on a valid bearer token, and inject the resolved User.
  • Optional authentication. IfAuthUser serves the same route to signed-in and anonymous callers. It injects User | undefined instead of rejecting the request.
  • An owner-only gate. AuthOwnerOnly restricts administration routes to platform owners. It answers 403 to an authenticated caller who is not an owner.
  • Composable authentication. authenticateRequestUser runs the same checks outside a decorator. The DMS tenant guards start from it, and your own parameter providers can too.
  • Token lifecycle. The domain issues and validates access and refresh tokens scoped to a tenant. It also issues the short-lived two-factor and tenant-assignment tokens that sit between a password check and a real session.
  • Revocable sessions. Each login is a Session row with its device, IP, and the hash of its current refresh token. You can revoke one session, or every session of a user.
  • The user table and model. The User table hashes passwords through HashModifier. UserModel looks users up by email and by owner flag.
  • External login providers. linkExternalIdentity binds the accounts a user owns on GitHub, Google, or any configured provider. On the next login, the DMS resolves the provider profile back to the user.
  • Safe responses. sanitizeUser strips authentication secrets from a user before you return it over HTTP.
  • One password policy. isPasswordCompliant checks a password against the policy the DMS enforces, so the signup of a module accepts exactly what the DMS accepts.
  • Account emails. The domain sends the second-factor, email-validation, password-reset and invite messages that the authentication flows depend on.
  • One registration path. announceRegistration runs the notifications and the USER_REGISTERED hook, whichever flow created the account.

Dependencies

This domain relies on the following AntelopeJS packages:

Quick start

The following controller gates a route on an authenticated user and returns the account with its secrets stripped.

typescript
import { Controller, Get } from "@antelopejs/interface-api";
import {
  AuthUser,
  sanitizeUser,
} from "@antelopejs/interface-dms/auth";
import type { User } from "@antelopejs/interface-dms/auth/db";

export class ProfileController extends Controller("/api/profile") {
  @Get("")
  profile(@AuthUser() user: User): Promise<Partial<User>> {
    // 401 before this line runs when the token is missing or invalid
    return sanitizeUser(user);
  }
}

A client calls it with the access token issued at login, in the Authorization header, as Bearer <access token>.

Pages in this section

  • Authentication: Resolve a request to a user with the authentication decorators and authenticateRequestUser.
  • Tokens and sessions: Issue and validate access, refresh, two-factor and tenant-assignment tokens, and record login sessions.
  • Users: The user table and model, password hashing, the password policy, sanitization, the account mail functions, and announcing a registration.
  • External identities: Bind and read the accounts a user owns on external login providers.