Add a nextcloud compatible response for profile.

This commit is contained in:
Fabian Stamm 2023-04-10 00:54:21 +02:00
parent 1e2bb83447
commit 80aace7b72
2 changed files with 39 additions and 24 deletions

View File

@ -1,23 +1,38 @@
import Mail from "../../models/mail"; import Mail from "../../models/mail";
import { GetClientApiAuthMiddleware } from "../middlewares/client"; import { GetClientApiAuthMiddleware } from "../middlewares/client";
import Stacker from "../middlewares/stacker"; import Stacker from "../middlewares/stacker";
import { Request, Response } from "express"; import { Request, Response } from "express";
import Logging from "@hibas123/nodelogging";
export default Stacker(GetClientApiAuthMiddleware(), async (req: Request, res) => {
let mails = await Promise.all( export default Stacker(GetClientApiAuthMiddleware(), async (req: Request, res) => {
req.user.mails.map((id) => Mail.findById(id)) const mode = req.query.mode;
); let mails = await Promise.all(
req.user.mails.map((id) => Mail.findById(id))
let mail = mails.find((e) => e.primary) || mails[0]; );
res.json({ let mail = mails.find((e) => e.primary) || mails[0];
user_id: req.user.uid,
id: req.user.uid, let base_response = {
ID: req.user.uid, user_id: req.user.uid,
sub: req.user.uid, id: req.user.uid,
email: mail.mail, ID: req.user.uid,
username: req.user.username, sub: req.user.uid,
displayName: req.user.name, email: mail.mail,
displayNameClaim: req.user.name, username: req.user.username,
}); displayName: req.user.name,
}) displayNameClaim: req.user.name,
}
if (mode == "nextcloud") {
Logging.debug("Profile in Nextcloud mode");
base_response["ocs"] = {
data: {
id: base_response.user_id,
email: base_response.email,
"display-name": base_response.displayName,
}
}
}
res.json(base_response);
})

View File

@ -1,6 +1,6 @@
{ {
"name": "@hibas123/openauth", "name": "@hibas123/openauth",
"version": "1.2.0", "version": "1.2.1",
"author": "Fabian Stamm <dev@fabianstamm.de>", "author": "Fabian Stamm <dev@fabianstamm.de>",
"private": true, "private": true,
"scripts": { "scripts": {