From 5217416f2d0c002501de69281bf6092f7a726e47 Mon Sep 17 00:00:00 2001 From: nesro Date: Wed, 25 Jun 2025 13:25:53 +0200 Subject: [PATCH] feat: allow to set auth id with api --- library.js | 23 +++++++++++++++++++++++ plugin.json | 1 + 2 files changed, 24 insertions(+) diff --git a/library.js b/library.js index 0161c03..63fc29d 100644 --- a/library.js +++ b/library.js @@ -326,3 +326,26 @@ OAuth.whitelistFields = async (params) => { return params; }; + +// This allows setting up the ids via API +OAuth.updateProfile = async (hookData) => { + const { data } = hookData; + if (data == null) { + return hookData; + } + + const { uid } = data; + if (uid == null) { + return hookData; + } + + const names = await db.getSortedSetMembers('oauth2-multiple:strategies'); + for (const nameId of names.map(name => `${name}Id`)) { + if (typeof data[nameId] === 'number') { + winston.verbose(`[plugins/sso-auth0] uid ${uid} setting up ${nameId}=${data[nameId]}`); + await user.setUserField(uid, nameId, data[nameId]); + await db.setObjectField(`${nameId}:uid`, data[nameId], uid); + } + } + return hookData; +}; \ No newline at end of file diff --git a/plugin.json b/plugin.json index 39b7360..46b84b7 100644 --- a/plugin.json +++ b/plugin.json @@ -10,6 +10,7 @@ { "hook": "filter:admin.header.build", "method": "addAdminNavigation" }, { "hook": "static:user.delete", "method": "deleteUserData" }, { "hook": "filter:user.whitelistFields", "method": "whitelistFields" }, + { "hook": "filter:user.updateProfile", "method": "updateProfile" }, { "hook": "filter:auth.init", "method": "loadStrategies" } ], "modules": {