Take auth/ whole from boilerplate 09e144d: the lockout claimed before the scrypt, APP_PASSWORD recovery closing every session, Starlette's cookie parser, the rightmost forwarded hop in the log, revoke_all on a password change, a 421 for a non-loopback Host on an open app, API tokens in auth_tokens behind Authorization: Bearer, and sockets closed with their credential
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
83e965dfeb
commit
244e57ac29
19 files changed
+2288
-214
No files matched your search
+84
-2
@@ -1,10 +1,15 @@
|
||||
"""The five bodies this package accepts. Small on purpose.
|
||||
"""The seven bodies this package accepts, and the five small answers it gives.
|
||||
Small on purpose.
|
||||
|
||||
A ceremony's `credential` is passed through as an opaque dict — it is the
|
||||
browser's `PublicKeyCredential` serialised by `toJSON()`, and its shape is the
|
||||
WebAuthn spec's business rather than ours. Restating it as a model here would
|
||||
be a second, staler copy of a structure the library already parses and
|
||||
validates properly.
|
||||
|
||||
The answers are models rather than dicts so that the app's OpenAPI document,
|
||||
which a client generates its types from, names every one of them. The JSON is
|
||||
what the dicts were.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -34,6 +39,22 @@ class PasswordBody(BaseModel):
|
||||
|
||||
current: str = Field(max_length=1000)
|
||||
new: str = Field(max_length=1000)
|
||||
#: Also delete every API token and passkey. Off by default, because a
|
||||
#: token's cron job is not what a routine change is against; on when the
|
||||
#: password may have been someone else's, since what they minted with it
|
||||
#: outlives the change. None is off, and is the default rather than False
|
||||
#: so the generated client type leaves the field optional, as it does
|
||||
#: `TokenBody.days`: openapi-typescript makes a field with a non-null
|
||||
#: default required, and a client that never asks should not have to say so.
|
||||
revoke_all: bool | None = None
|
||||
|
||||
|
||||
class PasskeyOptionsBody(BaseModel):
|
||||
"""Starting to register a passkey. `current` is the password, required for
|
||||
the same reason as in `PasswordBody`: a passkey is a permanent way in, and
|
||||
a borrowed session must not be able to mint one."""
|
||||
|
||||
current: str = Field(max_length=1000)
|
||||
|
||||
|
||||
class PasskeyBody(BaseModel):
|
||||
@@ -51,6 +72,67 @@ class PasskeyLoginBody(BaseModel):
|
||||
|
||||
|
||||
class LabelBody(BaseModel):
|
||||
"""Renaming a passkey."""
|
||||
"""Renaming a passkey or a token."""
|
||||
|
||||
label: str = Field(max_length=100)
|
||||
|
||||
|
||||
class TokenBody(BaseModel):
|
||||
"""Minting an API token. `current` is the password, required for the same
|
||||
reason as in `PasskeyOptionsBody`: a token is a standing way in, and a
|
||||
borrowed session must not be able to mint one."""
|
||||
|
||||
current: str = Field(max_length=1000)
|
||||
#: What to call it: the machine or the job that will hold it.
|
||||
label: str = Field("", max_length=100)
|
||||
#: How long it lives, in days. None is a token that does not expire, which
|
||||
#: is what a cron job wants; bounded above so a typo cannot ask for a
|
||||
#: thousand years and still be called dated.
|
||||
days: int | None = Field(None, ge=1, le=3650)
|
||||
|
||||
|
||||
class Ok(BaseModel):
|
||||
"""A change that has nothing to report beyond having happened."""
|
||||
|
||||
ok: bool = True
|
||||
|
||||
|
||||
class SignedOut(BaseModel):
|
||||
"""How many other sessions "sign out everywhere else" closed."""
|
||||
|
||||
signed_out: int
|
||||
|
||||
|
||||
class PasswordChanged(BaseModel):
|
||||
"""What a password change closed and what it left, for the screen to say.
|
||||
|
||||
`signed_out` is the other sessions, always closed. The tokens and
|
||||
passkeys are deleted only when `revoke_all` was asked for, and the
|
||||
`_left` counts are what is still registered afterwards, expired tokens
|
||||
included, so an owner who did not ask knows what to review."""
|
||||
|
||||
signed_out: int
|
||||
tokens_revoked: int
|
||||
passkeys_revoked: int
|
||||
tokens_left: int
|
||||
passkeys_left: int
|
||||
|
||||
|
||||
class PasskeyAdded(BaseModel):
|
||||
"""The row a registered passkey was given, which rename and revoke take."""
|
||||
|
||||
id: int
|
||||
|
||||
|
||||
class TokenCreated(BaseModel):
|
||||
"""A minted token: the one answer in this package that carries a credential.
|
||||
|
||||
`token` is shown once and stored nowhere but as a hash, so a caller that
|
||||
loses it mints another. The rest is the row as `ApiToken` lists it.
|
||||
"""
|
||||
|
||||
id: int
|
||||
token: str
|
||||
hint: str
|
||||
label: str
|
||||
expires_at: str
|
||||
Reference in new issue
Block a user