API / Minn\Auth / Authenticator

Authenticator final readonly class

Minn\Auth\Authenticator · public/minn/src/Minn/Auth/Authenticator.php · 149 lines

Resolves the current user two ways. A page load carries the cookie alone; a REST call must also carry a nonce bound to the same session.

Constants and properties

privateNOBODY = '$wp$2y$10$q/tQZiHVAKXuCoJIeZTH0.rb6Otms4vDKv0NrPeGKdvracPiLPy4W'

A real hash of a password nobody knows, checked against when the user does not exist so the answer takes as long either way.

privatereadonly Minn\Auth\Cookie $cookie

Promoted from the constructor.

privatereadonly Minn\Content\Users $users

Promoted from the constructor.

Public

new__construct(Minn\Auth\Cookie $cookie, Minn\Content\Users $users)#
staticfromDb(Minn\Db $db): self#

An authenticator over the shared database door.

methodsession(array $cookies): Minn\Auth\Authenticated|Minn\Auth\AuthFailure#

The session the cookie jar carries, or why there is none.

$cookiesarray<string, string>
methodrest(array $cookies, ?string $nonce): Minn\Auth\Authenticated|Minn\Auth\AuthFailure#

The session for a REST call: the cookie, then the nonce. A cookie sent without a nonce is no sign-in at all (the request goes on signed out, as the reference's cookie check makes it); one with a nonce that does not verify is refused (suite auth, checked against the reference).

$cookiesarray<string, string>
methodrestFromRequest(Minn\Http\Request $request): Minn\Auth\Authenticated|Minn\Auth\AuthFailure#

A REST caller: the cookie session with its nonce first; failing that, HTTP Basic credentials carrying an application password, which need no nonce. A wrong Basic pair is reported as not logged in.

methodapplicationPassword(Minn\Http\Request $request): ?Minn\Auth\Authenticated#

The user an Authorization: Basic header's application password unlocks, with the use recorded.

staticbasicCredentials(Minn\Http\Request $request): ?array#

The login and password an Authorization: Basic header carries, or null.

@return array{0: string, 1: string}|null
staticapplicationPasswordsAvailable(Minn\Http\Request $request): bool#

Application passwords need HTTPS, unless plugin code says otherwise through the reference's filter.

staticapplicationPasswordsAvailableFor(Minn\Content\UserRecord $user): bool#

Whether Basic auth may sign this user in; the runtime's filter has the last word.

$userarray<string, mixed>
methodlogin(string $username, string $password): ?Minn\Content\UserRecord#

Username and password to a user row, an outdated hash replaced as the sign-in succeeds; no session is created here.