Back to the room

Pass 3 of 3 · Deep dive of PHAROSPass 1 · OverviewPass 2 · How it works

Code Observatory / Source

Constant-time token check

Two static bearer tokens, compared with hmac.compare_digest. Unset tokens fail closed.

PINNED SOURCE Copied from the repository at this commit. Source, not an execution.

PHAROS at 975a38dMIT license

principal_for_tokenbackend/app/shared/auth.py, lines 102–110Open source
def principal_for_token(token: str) -> Principal | None:    admin = _configured("PHAROS_ADMIN_TOKEN")    reader = _configured("PHAROS_READ_TOKEN")    encoded = token.encode()    if admin and hmac.compare_digest(encoded, admin.encode()):        return ADMIN    if reader and hmac.compare_digest(encoded, reader.encode()):        return READER    return None

Where this comes from

Commit
975a38d5d17839c26ee219295a5be6ac66b6d910
File
backend/app/shared/auth.py
Lines
102–110
Git blob
c77f24b3d7406a6b302764a8fc5e475c40480e60
License
MIT, © 2024–2026 Pharos Contributors. Notice

Read it on GitHub at this commit

Check it yourself

From a clone of the repository, the first command prints the blob above and the second prints these lines.

git rev-parse 975a38d:backend/app/shared/auth.py
git show 975a38d:backend/app/shared/auth.py | sed -n '102,110p'