Auth: username+password, email+password and API key everywhere; key returns carry username and email

POST /auth/login (form and JSON) now accepts the username in the email field, like HTTP Basic and POST /auth/token always did; the token endpoint no longer lowercases the identifier before the username lookup, fixing mixed-case usernames. The login field is relabelled and type=text so browsers accept a username.

Every JSON return of the personal API key now also returns the account username and email: the profile JSON gains a can_view_api_key-gated email beside api_key (username already rides profile_user), and POST /profile/regenerate-api-key returns {api_key, username, email}. A client holding only its DEVPLACE_API_KEY value can now fetch its full account via GET /profile in one call.

Documented fully: authentication prose page (three credentials, precedence, DEVPLACE_API_KEY, account fetch, separate DevRant/WebSocket auth domains), new auth-token docs_api card, regenerated-key sample, conventions, README, CLAUDE.md, OpenAPI description, corrected profile key hint. Summary in changes.md (left unversioned per request).

Tests: username/mixed-case/uppercase-email login and token cases, API-key account fetch via X-API-KEY and Bearer, owner/admin vs stranger/guest email gating, regenerate shape, browser login by username. Failing-first observed red, green after.
This commit is contained in:
2026-11-11 16:07:43 +01:00
parent 33eb090e27
commit dbdd0d29dd
20 changed files with 357 additions and 45 deletions
+35
View File
@@ -762,4 +762,39 @@ def test_stranger_gets_no_key(app_server, seeded_db):
assert body["api_key"] is None
def test_owner_gets_email_alongside_key(app_server, seeded_db):
session, name = _privacy_member("keye")
body = _profile_json_body(session, name)
assert body["can_view_api_key"] is True
assert body["api_key"]
assert body["email"] == f"{name}@t.dev"
assert body["profile_user"]["username"] == name
def test_admin_gets_email_alongside_member_key(app_server, seeded_db):
_, name = _privacy_member("keym")
body = _profile_json_body(_admin_session(), name)
assert body["can_view_api_key"] is True
assert body["api_key"]
assert body["email"] == f"{name}@t.dev"
def test_stranger_gets_no_email(app_server, seeded_db):
_, name = _privacy_member("keyn")
stranger, _ = _privacy_member("keyw")
body = _profile_json_body(stranger, name)
assert body["can_view_api_key"] is False
assert body["api_key"] is None
assert body["email"] is None
def test_guest_gets_no_email(app_server, seeded_db):
body = requests.get(
f"{BASE_URL}/profile/alice_test",
headers={"Accept": "application/json"},
).json()
assert body["can_view_api_key"] is False
assert body["email"] is None