mirror of
https://github.com/navidrome/navidrome.git
synced 2026-11-25 19:39:46 +01:00
API v1 no longer mints short-lived JWT access tokens. Clients send the grant secret from POST /auth/login or /auth/setup as `Authorization: Bearer` on every request. Every request already looked the grant up in the database, so the JWT gave no speed or revocation benefit and only added a refresh loop, which early client authors pushed back on. The grant already is an API key: one per client sign-in, scoped and revocable. Revocation is now immediate on every node; the contract promises "within one minute". Removed: POST /auth/token, the grantAuth scheme, the TokenRequest and AccessToken schemas, the token_expired problem code, the API v1 JWT signer and its signing key, the grant liveness cache, and PropertyRepository.PutIfAbsent. ResolveGrant is now Authenticate. Short-lived tokens return later only as narrow media tokens for ?access_token= on media URLs, together with the media endpoints. Signed-off-by: Deluan <deluan@navidrome.org>
62 lines
1.4 KiB
Go
62 lines
1.4 KiB
Go
package persistence
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
. "github.com/Masterminds/squirrel"
|
|
"github.com/navidrome/navidrome/model"
|
|
"github.com/pocketbase/dbx"
|
|
)
|
|
|
|
type propertyRepository struct {
|
|
sqlRepository
|
|
}
|
|
|
|
func NewPropertyRepository(db dbx.Builder) model.PropertyRepository {
|
|
r := &propertyRepository{}
|
|
r.db = db
|
|
r.tableName = "property"
|
|
return r
|
|
}
|
|
|
|
func (r propertyRepository) Put(ctx context.Context, id string, value string) error {
|
|
update := Update(r.tableName).Set("value", value).Where(Eq{"id": id})
|
|
count, err := r.executeSQL(ctx, update)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if count > 0 {
|
|
return nil
|
|
}
|
|
insert := Insert(r.tableName).Columns("id", "value").Values(id, value)
|
|
_, err = r.executeSQL(ctx, insert)
|
|
return err
|
|
}
|
|
|
|
func (r propertyRepository) Get(ctx context.Context, id string) (string, error) {
|
|
sel := Select("value").From(r.tableName).Where(Eq{"id": id})
|
|
resp := struct {
|
|
Value string
|
|
}{}
|
|
err := r.queryOne(ctx, sel, &resp)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return resp.Value, nil
|
|
}
|
|
|
|
func (r propertyRepository) DefaultGet(ctx context.Context, id string, defaultValue string) (string, error) {
|
|
value, err := r.Get(ctx, id)
|
|
if errors.Is(err, model.ErrNotFound) {
|
|
return defaultValue, nil
|
|
}
|
|
if err != nil {
|
|
return defaultValue, err
|
|
}
|
|
return value, nil
|
|
}
|
|
|
|
func (r propertyRepository) Delete(ctx context.Context, id string) error {
|
|
return r.delete(ctx, Eq{"id": id})
|
|
}
|