Let guild members log in to the jukebox with Discord

- Optional Discord OAuth2 login (identify scope), enabled by
  DISCORD_CLIENT_SECRET, WEB_PUBLIC_URL and SESSION_SECRET; restricted to
  members of the configured guild, checked at login.
- Stateless 30-day session in a signed HttpOnly SameSite=Lax cookie; the
  OAuth state is checked against its own short-lived cookie.
- The jukebox API accepts the key or the session; with the session,
  changes must come from the site's own origin. The member's server name
  becomes the uploader name.
- GET /auth/me tells the page whether the login is enabled and who is
  logged in.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Shinuwa 2026-11-29 12:17:48 +01:00
parent 9fb54798dd
commit 399e851178
11 changed files with 489 additions and 13 deletions

View file

@ -29,10 +29,11 @@ const upload = multer({
function uploadsRouter({ queue }) {
const router = Router();
const options = (body) => ({
// Connecté avec Discord, le nom vient de la session et non du formulaire.
const options = ({ body, user }) => ({
permanent: body?.permanent === "true" || body?.permanent === true,
enqueue: body?.enqueue !== "false" && body?.enqueue !== false,
uploader: body?.uploader || "web-ui",
uploader: user?.name || body?.uploader || "web-ui",
title: body?.notes,
});
@ -42,10 +43,10 @@ function uploadsRouter({ queue }) {
}
try {
const track = await ingestAudioFile(req.file, options(req.body), { queue });
const track = await ingestAudioFile(req.file, options(req), { queue });
return res.status(201).json({
track: serializeTrack(track),
enqueued: options(req.body).enqueue,
enqueued: options(req).enqueue,
});
} catch (error) {
return next(error);
@ -61,10 +62,10 @@ function uploadsRouter({ queue }) {
try {
const file = await downloadAudio(url, { destinationDir: TEMP_DIR });
const track = await ingestAudioFile(file, options(req.body), { queue });
const track = await ingestAudioFile(file, options(req), { queue });
return res.status(201).json({
track: serializeTrack(track),
enqueued: options(req.body).enqueue,
enqueued: options(req).enqueue,
});
} catch (error) {
return next(error);