IF Commons GitHub

logical/auth

Written to: 1 requirement: 1 proved, 0 partly, 0 failing, 0 with no test recorded. 0003-anyfs-serve-logical FR-009

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); // false

Source: commons/anyfs-serve/src/logical/auth.ts

5 of 5 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

credentialsOffunction
function credentialsOf(header: string | null): Credentials | undefined

The credentials of a request, or nothing where it sent none or sent a form that is not read.

Imported by 14 tests of the run (14 passed, 0 failed): the library's results

newTokenfunction
function newToken(): string

A random token: 32 bytes as 64 hex digits.

Imported by 14 tests of the run (14 passed, 0 failed): the library's results

sameSecretfunction
function 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.

Imported by 14 tests of the run (14 passed, 0 failed): the library's results

tokenAuthenticatorfunction
function tokenAuthenticator(token: string): Authenticator

Who 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.

Imported by 23 tests of the run (23 passed, 0 failed): the library's results

noAuthenticationconst
const noAuthentication: Authenticator

Nobody is asked: for a server that only the loopback reaches and that the program starts on purpose.

Imported by 23 tests of the run (23 passed, 0 failed): the library's results

Titles, headings, exports, tables, columns and requirements. Esc closes.