Expand description
Authentication primitives: password hashing, random tokens, cookies and the request extractors that resolve the current user.
- Browser users authenticate with a session cookie (
tc_session). - API clients authenticate with a personal access token sent as
Authorization: Bearer tc_pat_…. The API never accepts cookies, which keeps it immune to CSRF.
Re-exports§
pub use services::membership_conditions::Origin;
Structs§
- Actor
- The authenticated user on whose behalf a request is executed.
- ApiCaller
- The user of an API request and the scope of its token. Refuses (403) a
request outside the scope: a
read_onlytoken may only sendGET/HEADrequests and post to the MCP endpoint (whose dispatcher allows it the read-only tools only), anmcp_onlytoken may only post to the MCP endpoint (domain::TokenScope::allows_request). - ApiUser
- Extracts the user of an API request from a bearer token.
- Sign
InThrottle - Failed password sign-ins per username and per client address
(
TEAMCRAFT_SIGNIN_MAX_FAILURESwithinSIGN_IN_WINDOW); once a counter is full, sign-in for that name or address is refused with 429 until the window has passed – without checking the password. Counted in memory per server process; a successful sign-in clears the username’s counter, not the address’s (else an attacker with an account of their own could reset it between guesses). - WebUser
- Extracts the user of a browser session. Rejects with
401, which the web UI turns into a redirect to the login page.
Constants§
- API_
TOKEN_ PREFIX - FLASH_
COOKIE - SESSION_
COOKIE - SESSION_
TOKEN_ PREFIX - SIGN_
IN_ ADDRESS_ FACTOR - A client address may fail this many times the per-username limit: an office behind one NAT address shares it.
- SIGN_
IN_ WINDOW - How long failed sign-ins are counted (from the first failure).
Functions§
- clear_
flash_ cookie - clear_
session_ cookie - client_
address - The client address of a request: the peer, or – when the peer is a
reverse proxy on an internal address – the last
X-Forwarded-Forentry, the one that proxy added (a client can only prepend to the header). In tests without a peer address, the header alone. - cookie_
value - Returns the value of the cookie
namefrom the request headers. - flash_
cookie - generate_
token - Generates a random token with 256 bits of entropy, e.g.
tc_pat_3f9a…. - hash_
password - Hashes a password with Argon2id (OWASP recommended default parameters).
- hash_
password_ async - Runs Argon2 on the blocking thread pool (it is deliberately CPU heavy).
- hash_
token - Tokens are high-entropy, so a fast hash is sufficient for storage.
- session_
cookie - verify_
password - Verifies a password against a stored PHC hash string.
- verify_
password_ async - Verifies on the blocking pool.
hash = Noneperforms a dummy verification.