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
+10
View File
@@ -51,3 +51,13 @@ def test_regenerate_invalidates_old_key(app_server):
allow_redirects=False,
)
assert new.status_code in (302, 200)
def test_regenerate_returns_username_and_email(app_server):
session, name, email, _ = _signup_api_auth()
resp = session.post(f"{BASE_URL}/profile/regenerate-api-key")
assert resp.status_code == 200, resp.text[:300]
body = resp.json()
assert body["api_key"]
assert body["username"] == name
assert body["email"] == email