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:
@@ -351,13 +351,20 @@ accepts three header-based methods, resolved centrally in `get_current_user`
|
||||
Every user has an `api_key` (a uuid7), set at signup and backfilled for existing
|
||||
users on startup (and via `devplace apikey backfill`). The key is shown on the
|
||||
profile page to its owner (and to admins for any user) with a live **Regenerate**
|
||||
button; regenerating invalidates the old key immediately. A successful JSON
|
||||
`POST /auth/login` or `POST /auth/signup` also returns the account's `email`,
|
||||
`api_key`, and `is_admin` flag, and `GET /profile/{username}` as JSON reports
|
||||
`profile_is_admin` plus the key (null unless the viewer owns the profile or is
|
||||
an admin). Invalid credentials return `401`; requests with no credentials behave
|
||||
as anonymous (browser redirect to login). Full details and copy-paste `curl`
|
||||
examples live at `/docs/authentication.html`.
|
||||
button; regenerating invalidates the old key immediately. The three account
|
||||
credentials are username+password, email+password, and the personal API key: the
|
||||
login form, JSON `POST /auth/login`, `POST /auth/token`, and HTTP Basic all accept
|
||||
the username or the email address as the password identifier (usernames are
|
||||
case-sensitive, email addresses are not), and clients conventionally carry the API
|
||||
key in the `DEVPLACE_API_KEY` environment variable. Every JSON response that returns
|
||||
the personal API key returns the account's `username` and `email` alongside it:
|
||||
login/signup (`data`), `POST /profile/regenerate-api-key`, and the profile JSON
|
||||
(`profile_user.username`, `email`, `api_key`; key and email null unless the viewer
|
||||
owns the profile or is an admin). So a client holding only an API key fetches its
|
||||
account in one call: `GET /profile` with `X-API-KEY` and `Accept: application/json`.
|
||||
Invalid credentials return `401`; requests with no credentials behave as anonymous
|
||||
(browser redirect to login). Full details and copy-paste `curl` examples live at
|
||||
`/docs/authentication.html`.
|
||||
|
||||
```bash
|
||||
curl -H "X-API-KEY: <your-key>" https://your-host/notifications
|
||||
|
||||
Reference in New Issue
Block a user