UI REST API: accounts, bearer auth, API apps, sessions, OpenAPI docs
- flask-smorest API under /api/v1 with a uniform JSON error shape; spec at /api/openapi.json, Swagger UI at /api/docs, ReDoc at /api/redoc - Register/login/logout/me with hashed, expiring bearer tokens, documented as an OpenAPI bearer security scheme - API application and client-session management endpoints - CORS restricted to the configured UI origin(s) - Flask no longer serves static files: it is API-only - Login and registration metrics Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9af8a4be8b
commit
e026e56ee3
13 files changed
+626
-1
No files matched your search
@@ -0,0 +1,33 @@
|
||||
from flask import g
|
||||
from flask_smorest import Blueprint, abort
|
||||
|
||||
from scrobbler.api.decorators import authenticated
|
||||
from scrobbler.schemas import ErrorSchema, SessionSchema
|
||||
from scrobbler.services import accounts
|
||||
|
||||
blp = Blueprint(
|
||||
"ui_sessions",
|
||||
__name__,
|
||||
description="Last.fm session keys issued to scrobbling clients on your behalf.",
|
||||
)
|
||||
|
||||
|
||||
@blp.route("", methods=["GET"])
|
||||
@authenticated(blp)
|
||||
@blp.response(200, SessionSchema(many=True))
|
||||
def list_sessions():
|
||||
"""List client sessions"""
|
||||
return accounts.list_sessions(g.user)
|
||||
|
||||
|
||||
@blp.route("/<int:session_id>", methods=["DELETE"])
|
||||
@authenticated(blp)
|
||||
@blp.response(204)
|
||||
@blp.alt_response(404, schema=ErrorSchema, description="No such session")
|
||||
def revoke_session(session_id):
|
||||
"""Revoke a client session
|
||||
|
||||
The client's session key stops working immediately (Last.fm error 9).
|
||||
"""
|
||||
if not accounts.revoke_session(g.user, session_id):
|
||||
abort(404, code="not_found", message="No such session")
|
||||
Reference in new issue
Block a user