Aller au contenu
Français

Basic auth

Ce contenu n’est pas encore disponible dans votre langue.

BasicAuth is the Authorization: Basic peer of BearerTokenAuth. Credentials are compared in constant time, and a 401 advertises a real WWW-Authenticate: Basic realm="…" challenge.

import { BasicAuth, BasicAuthOptions, withMiddleware } from 'actor-ts/http';
const auth = BasicAuth(
BasicAuthOptions.create()
.withUsers({ alice: process.env.ALICE_PW! })
.withRealm('admin'),
);
const routes = withMiddleware(auth, adminRoutes);

Provide a users map (username → password) or a custom validate function for checking against a store:

BasicAuth({ validate: (user, pass) => checkAgainstDb(user, pass) });
Builder methodFieldPurpose
withUsers(map)usersusername → password, constant-time compared
withValidate(validate)validatecustom async/sync credential check
withRealm(name)realmadvertised realm (default 'actor-ts')
  • Security — where auth sits in the stack.
  • CSRF — pair with a CSRF guard for browser forms.