Skip to content
Corex

PreviewAccess

Corex\Config\Operations\PreviewAccess · class · Config layer

The preview link (spec 101, FR-011 to FR-014): one secret address that lets somebody without an account see the real site while it is in Coming soon. Two values, kept apart on purpose. The token is the secret in the link. It is shown to the operator once, when the link is created or regenerated, and is never stored: what is kept is a hash of it keyed with a secret of the site’s, which cannot be turned back into the link and, without the key, cannot even be checked against a guess. The grant is what a browser holds after opening the link: an expiry and a signature over the stored hash and that expiry. It is not the token, so a cookie that leaks gives away one browser’s access and not the link. It is signed over the stored hash, so regenerating, revoking or clearing the link ends every grant at the next request with no list of sessions to walk. And its expiry is inside the signature, so the fourteen days are enforced here rather than left to a cookie lifetime the holder can edit. Preview access grants no capability. It is one fact handed to {@see ComingSoonDecision}, which reads it only while the mode is Coming soon.

__construct(PreviewAccessStore $store, string $key)

Section titled “__construct(PreviewAccessStore $store, string $key)”

When the current link was issued and by whom, or null when there is none.

create(int $userId, DateTimeImmutable $now): ?string

Section titled “create(int $userId, DateTimeImmutable $now): ?string”

Create the link, when there is none. Returns its token — the only time it is available — or null when a link already exists, which is left as it is: replacing one is {@see regenerate()}, and says so in the history.

regenerate(int $userId, DateTimeImmutable $now): ?string

Section titled “regenerate(int $userId, DateTimeImmutable $now): ?string”

Replace the link, ending the old one and every grant made from it. Returns the new token, or null when there was no link to replace.

Remove the link, leaving none. False when there was none to remove.

Remove the link without ceremony: what leaving Coming soon does (FR-012a).

Whether a token is the current link’s.

grant(string $token, DateTimeImmutable $now): ?string

Section titled “grant(string $token, DateTimeImmutable $now): ?string”

The grant for a browser that has just opened the link, or null when the token is not the link’s.

When a grant made now stops being honoured, as a timestamp.

honours(string $grant, DateTimeImmutable $now): bool

Section titled “honours(string $grant, DateTimeImmutable $now): bool”

Whether a grant is one this site made, from the link that exists now, and has not run out.