Require logging in to the web UI and API
The first visit to the UI creates the account from a username and password; after that every API route needs a session cookie from logging in. Accounts are stored in app_user (Argon2id password hashes) and sessions in user_session (SHA-256 token hashes, 30 days). The account page lets the user save a Listenbrainz token, checked with Listenbrainz first. It takes priority over listenbrainz.token from the config for LB Radio suggestions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0767c21a6f
commit
53c1bffa6d
33 files changed
+1249
-39
No files matched your search
@@ -32,8 +32,10 @@ cp .env.example .env # then fill in your Subsonic server and a database passw
|
||||
docker compose up -d --build
|
||||
```
|
||||
|
||||
The web UI is then at http://localhost:8000. playlistd has no login, so it only listens on the
|
||||
Docker host by default; set `PLAYLISTD_BIND=0.0.0.0` in `.env` to open it to your network. If your
|
||||
The web UI is then at http://localhost:8000. The first visit asks you to create an account (see
|
||||
[Logging in](#logging-in)), and anyone who reaches it first can, so it only listens on the Docker
|
||||
host by default: create your account, then set `PLAYLISTD_BIND=0.0.0.0` in `.env` to open it to
|
||||
your network. If your
|
||||
Subsonic server runs on the Docker host, use `http://host.docker.internal:4533/rest` as
|
||||
`SUBSONIC_BASE`.
|
||||
|
||||
@@ -136,10 +138,10 @@ Mixes are rebuilt every `refresh_hours`. On a rebuild, existing mix playlists ar
|
||||
new cluster with the most similar genres (and renamed), new playlists are created for new
|
||||
clusters, and playlists for clusters that no longer appear are deleted.
|
||||
|
||||
Create a rule through the API:
|
||||
Create a rule through the API (after logging in, see [Logging in](#logging-in)):
|
||||
|
||||
```sh
|
||||
curl -X POST localhost:8000/api/playlist/mix -H 'Content-Type: application/json' \
|
||||
curl -b cookies -X POST localhost:8000/api/playlist/mix -H 'Content-Type: application/json' \
|
||||
-d '{"tracking_user": "jellywx", "months": 3, "playlist_size": 50}'
|
||||
```
|
||||
|
||||
@@ -170,7 +172,8 @@ your library yet.
|
||||
Each time the mixes are rebuilt, playlistd also looks for new songs for each mix:
|
||||
|
||||
* your Listenbrainz recommendations, keeping only recordings you've never listened to, and
|
||||
* if `listenbrainz.token` is set, an LB Radio playlist for each mix's top genres.
|
||||
* if a Listenbrainz token is saved to your account (or `listenbrainz.token` is set), an LB Radio
|
||||
playlist for each mix's top genres.
|
||||
|
||||
Every candidate's MusicBrainz genres are compared with each mix's, and it's suggested in the mix
|
||||
it fits best (if it fits well enough), skipping songs already in your library.
|
||||
@@ -197,6 +200,46 @@ and set `discover.ui` (or `DISCOVER_UI`) to the `discover/dist` directory to ser
|
||||
playlistd at `/`. For development, `npm run dev` serves the UI with hot reload and forwards API
|
||||
requests to playlistd on `localhost:8000` (or `PLAYLISTD_URL`).
|
||||
|
||||
### Logging in
|
||||
|
||||
The web UI and every API endpoint need you to log in. There's no default account: the first time
|
||||
anyone opens the UI, it asks for a username and password, and creates the account with them. After
|
||||
that, the UI shows a login page instead, and new accounts can't be created. Passwords are stored as
|
||||
Argon2id hashes in the `app_user` table, and logging in sets a session cookie that lasts 30 days.
|
||||
|
||||
To start over (e.g. if you forget your password), delete the account, and the next visit to the UI
|
||||
will set it up again:
|
||||
|
||||
```sql
|
||||
DELETE FROM app_user;
|
||||
```
|
||||
|
||||
Under the account page in the UI (your username, in the sidebar), you can save your Listenbrainz
|
||||
user token to your account. It's checked with Listenbrainz first, and is then used instead of
|
||||
`listenbrainz.token` from the config.
|
||||
|
||||
To use the API from a script, log in with a cookie jar and pass it with each request:
|
||||
|
||||
```sh
|
||||
curl -c cookies -X POST localhost:8000/api/auth/login -H 'Content-Type: application/json' \
|
||||
-d '{"username": "you", "password": "your password"}'
|
||||
curl -b cookies localhost:8000/api/tracked/playlists
|
||||
```
|
||||
|
||||
Requests without a valid session get `401 {"error": "Log in to continue"}`. These endpoints are
|
||||
under `/api/auth`:
|
||||
|
||||
| Endpoint | Purpose |
|
||||
|------------------------------|---------------------------------------------------------------|
|
||||
| `GET /status` | Whether the account still has to be set up, and who's logged in |
|
||||
| `POST /setup` | Create the account (`username`, `password`), only if there isn't one |
|
||||
| `POST /login` | Log in (`username`, `password`) |
|
||||
| `POST /logout` | Log out |
|
||||
| `GET /account` | The logged in account |
|
||||
| `PUT /account/listenbrainz` | Save a Listenbrainz `token` to the account (empty removes it) |
|
||||
|
||||
### Endpoints
|
||||
|
||||
The UI uses these endpoints under `/api/discover`:
|
||||
|
||||
| Endpoint | Purpose |
|
||||
|
||||
Reference in new issue
Block a user