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

@ -2,15 +2,17 @@ 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) => { export default Stacker(GetClientApiAuthMiddleware(), async (req: Request, res) => {
const mode = req.query.mode;
let mails = await Promise.all( let mails = await Promise.all(
req.user.mails.map((id) => Mail.findById(id)) req.user.mails.map((id) => Mail.findById(id))
); );
let mail = mails.find((e) => e.primary) || mails[0]; let mail = mails.find((e) => e.primary) || mails[0];
res.json({ let base_response = {
user_id: req.user.uid, user_id: req.user.uid,
id: req.user.uid, id: req.user.uid,
ID: req.user.uid, ID: req.user.uid,
@ -19,5 +21,18 @@ export default Stacker(GetClientApiAuthMiddleware(), async (req: Request, res) =
username: req.user.username, username: req.user.username,
displayName: req.user.name, displayName: req.user.name,
displayNameClaim: 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": {