- /2.0/ and /api/auth/ are described from the Last.fm method registry: method enum, per-method parameter tables, auth requirements, notes, request schemas and XML example responses - Readable tags (Auth, Apps, Sessions, Tokens, Stats, Last.fm) - docs/openapi.json is exported with `flask openapi write`; tests fail if it drifts from the code, if any route is undocumented, or if a UI route is missing its bearer-auth security declaration Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
34 lines
973 B
Python
34 lines
973 B
Python
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(
|
|
"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")
|