Basic auth
このコンテンツはまだ日本語訳がありません。
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) });Configuration
Section titled “Configuration”| Builder method | Field | Purpose |
|---|---|---|
withUsers(map) | users | username → password, constant-time compared |
withValidate(validate) | validate | custom async/sync credential check |
withRealm(name) | realm | advertised realm (default 'actor-ts') |
