credentialsOffunctionfunction credentialsOf(header: string | null): Credentials | undefinedThe credentials of a request, or nothing where it sent none or sent a form that is not read.
Who may ask. The credentials of a request are read from Authorization (a bearer token, or HTTP Basic whose password is the token, which is what a desktop sends), and a token is compared in constant time over the digests of both, so that the time of an answer says nothing of how much of a guess was right. A token is made from 32 random bytes.
import { tokenAuthenticator, newToken } from "./auth.ts";
const token = newToken();
const may = tokenAuthenticator(token);
await may({ scheme: "bearer", secret: token }); // true
await may(undefined); // falsecredentialsOffunctionfunction credentialsOf(header: string | null): Credentials | undefinedThe credentials of a request, or nothing where it sent none or sent a form that is not read.
newTokenfunctionfunction newToken(): stringA random token: 32 bytes as 64 hex digits.
sameSecretfunctionfunction sameSecret(a: string, b: string): Promise<boolean>Whether two texts are equal, in a time that does not depend on where they differ: it compares the digests.
tokenAuthenticatorfunctionfunction tokenAuthenticator(token: string): AuthenticatorWho may ask where the token is a given text: whoever sends it, as a bearer token or as the password of Basic, with any user name.
noAuthenticationconstconst noAuthentication: AuthenticatorNobody is asked: for a server that only the loopback reaches and that the program starts on purpose.