enhance auth status endpoint to return detailed linked services for Discord users
This commit is contained in:
@@ -298,6 +298,48 @@ def revoke(discord_user_id: int, service: str) -> None:
|
||||
logger.info("Revoked auth for user %s on %s", discord_user_id, service)
|
||||
|
||||
|
||||
def get_all_auths(discord_user_id: int) -> list[dict]:
|
||||
"""
|
||||
Return all active auth records for a Discord user.
|
||||
Each record includes service name, external user id, external name,
|
||||
linked_at timestamp, and the raw credentials (e.g. Jellyfin token + URL).
|
||||
|
||||
Used by the /api/v1/auth/status endpoint so other services can discover
|
||||
linked accounts for a given Discord ID.
|
||||
"""
|
||||
_ensure_schema()
|
||||
import json
|
||||
|
||||
with _db_lock:
|
||||
conn = _get_conn()
|
||||
rows = conn.execute(
|
||||
"""SELECT service, external_user_id, external_name, credentials, linked_at
|
||||
FROM user_auth
|
||||
WHERE discord_user_id = ? AND is_active = 1
|
||||
ORDER BY linked_at DESC""",
|
||||
(discord_user_id,),
|
||||
).fetchall()
|
||||
conn.close()
|
||||
|
||||
results: list[dict] = []
|
||||
for row in rows:
|
||||
creds = {}
|
||||
if row["credentials"]:
|
||||
try:
|
||||
creds = json.loads(row["credentials"])
|
||||
except (json.JSONDecodeError, TypeError):
|
||||
creds = {}
|
||||
results.append({
|
||||
"service": row["service"],
|
||||
"external_user_id": row["external_user_id"] or "",
|
||||
"external_name": row["external_name"] or "",
|
||||
"linked_at": row["linked_at"] or "",
|
||||
"credentials": creds,
|
||||
})
|
||||
|
||||
return results
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Dev / testing — reset the entire store
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user