CI / Docker image (push) Successful in 12s
CI / Server (push) Successful in 25s
CI / CLI (push) Successful in 13s
Development image / Development image (push) Successful in 21s
CI / CLI (windows) (push) Successful in 57s
CI / CLI (linux-arm64, static) (push) Successful in 1m37s
Release / Prepare release (push) Successful in 2s
Release / Server (linux-x64) (push) Successful in 53s
Release / CLI (linux-arm64, static) (push) Successful in 1m32s
Release / Docker image (push) Successful in 2m48s
Release / Server (windows-x64) (push) Successful in 6m20s
Release / CLI (windows-x64) (push) Successful in 6m48s
Release / CLI (linux-x64) (push) Successful in 7m8s
Release / Publish release (push) Successful in 1s
Squash the tree into one commit, drop docs/architecture.html, reset the version line to 0.3.0, consolidate the changelog, enable Renovate automerge for non-major updates and add AGENTS.md.
44 lines
1.6 KiB
JavaScript
44 lines
1.6 KiB
JavaScript
const { Router } = require("../utils/router");
|
|
const oidc = require("../lib/oidc");
|
|
const logger = require("../utils/logger");
|
|
|
|
const app = Router();
|
|
|
|
const pick = body => {
|
|
const values = {};
|
|
for (const key of ["name", "issuer", "clientId", "scope", "usernameClaim"]) {
|
|
if (body[key] !== undefined) values[key] = String(body[key]).trim();
|
|
}
|
|
if (body.clientSecret !== undefined && body.clientSecret !== "") values.clientSecret = String(body.clientSecret);
|
|
for (const key of ["createAccounts", "enabled"]) {
|
|
if (body[key] !== undefined) values[key] = body[key] === true || body[key] === "true";
|
|
}
|
|
return values;
|
|
};
|
|
|
|
app.get("/", async (req, res) => {
|
|
res.json({ providers: await oidc.list(), redirectUri: oidc.redirectUri(req.config) });
|
|
});
|
|
|
|
app.post("/", async (req, res) => {
|
|
const result = await oidc.save(null, pick(req.body || {}));
|
|
if (result.code) return res.status(result.code).json(result);
|
|
logger.info(`${req.session.username} added the login provider "${result.provider.name}"`);
|
|
res.json({ message: `${result.provider.name} added`, provider: result.provider });
|
|
});
|
|
|
|
app.put("/:id", async (req, res) => {
|
|
const result = await oidc.save(Number(req.params.id), pick(req.body || {}));
|
|
if (result.code) return res.status(result.code).json(result);
|
|
res.json({ message: "Saved", provider: result.provider });
|
|
});
|
|
|
|
app.delete("/:id", async (req, res) => {
|
|
const result = await oidc.remove(Number(req.params.id));
|
|
if (result.code) return res.status(result.code).json(result);
|
|
logger.info(`${req.session.username} removed a login provider`);
|
|
res.json(result);
|
|
});
|
|
|
|
module.exports = app;
|