feat: a password for each app or device
A person can make a password for each app that connects to their server, in
Settings, Apps and devices. The secret is shown once, can be taken back, and
is for the music API of other apps only: it cannot sign in or change the
account. Secrets are kept sealed (AES-256-GCM, key derived from the jwt secret)
because token login needs them in clear, and a hash finds a device by its key.
- migration 0034 device_passwords (sqlite, postgres)
- internal/devices service, storage repo
- GET/POST /me/devices, DELETE /me/devices/{id}, in the OpenAPI spec
- Settings section with copy and remove
This commit is contained in:
parent
9451765861
commit
010f2e5057
2 changed files with 1368 additions and 11 deletions
16
migrations/postgres/0034_device_passwords.sql
Normal file
16
migrations/postgres/0034_device_passwords.sql
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
-- The passwords a person makes for the apps and devices that connect to their server (OpenSubsonic clients). A password
|
||||
-- opens the music API and nothing else. Token login needs the secret itself, so it is kept sealed (sealed), and a hash of
|
||||
-- it (key_hash) finds the device of an API key.
|
||||
|
||||
CREATE TABLE device_passwords (
|
||||
id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||
user_id BIGINT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
name TEXT NOT NULL,
|
||||
key_hash TEXT NOT NULL,
|
||||
sealed BYTEA NOT NULL,
|
||||
created_at BIGINT NOT NULL,
|
||||
last_used_at BIGINT
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX idx_device_passwords_key ON device_passwords(key_hash);
|
||||
CREATE INDEX idx_device_passwords_user ON device_passwords(user_id);
|
||||
16
migrations/sqlite/0034_device_passwords.sql
Normal file
16
migrations/sqlite/0034_device_passwords.sql
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
-- The passwords a person makes for the apps and devices that connect to their server (OpenSubsonic clients). A password
|
||||
-- opens the music API and nothing else. Token login needs the secret itself, so it is kept sealed (sealed), and a hash of
|
||||
-- it (key_hash) finds the device of an API key.
|
||||
|
||||
CREATE TABLE device_passwords (
|
||||
id INTEGER PRIMARY KEY,
|
||||
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
name TEXT NOT NULL,
|
||||
key_hash TEXT NOT NULL,
|
||||
sealed BLOB NOT NULL,
|
||||
created_at INTEGER NOT NULL, -- unix seconds
|
||||
last_used_at INTEGER -- unix seconds, NULL until it is used
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX idx_device_passwords_key ON device_passwords(key_hash);
|
||||
CREATE INDEX idx_device_passwords_user ON device_passwords(user_id);
|
||||
Loading…
Reference in a new issue