Skip to content

Commit

Permalink
Adjustments for NodeBB 3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Brutus5000 committed Nov 6, 2024
1 parent 1803b40 commit 11b7888
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 additions & 7 deletions library.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const Groups = require.main.require('./src/groups');
const db = require.main.require('./src/database');
const authenticationController = require.main.require('./src/controllers/authentication');
const userController = require.main.require('./src/controllers/user');
const routeHelpers = require.main.require('./src/routes/helpers');

const async = require('async');

Expand Down Expand Up @@ -82,13 +83,15 @@ if (!constants.name) {
}

// This adds a route to query forum users by their FAF id
OAuth.load = function (params, callback) {
const router = params.router;
const middleware = params.middleware;
OAuth.addRoutes = async ({ router, middleware }) => {
const middlewares = [
middleware.ensureLoggedIn,
middleware.admin.checkPrivileges,
];

// This actually creates the routes, you need two routes for every page.
// The first parameter is the actual path to your page.
router.get('/api/user/oauth/:externalUserId', middleware.authenticateRequest, async (req, res, next) => {
routeHelpers.setupApiRoute(router, 'get', '/sso/user/:externalUserId', middlewares, async (req, res, next) => {
const userId = await db.getObjectField(`${constants.name}Id:uid`, req.params.externalUserId);
if (!userId) {
return next();
Expand All @@ -97,8 +100,6 @@ OAuth.load = function (params, callback) {

res.json(userData);
});

callback();
};

OAuth.getStrategy = function (strategies, callback) {
Expand Down Expand Up @@ -245,7 +246,7 @@ OAuth.login = async (payload) => {

// Automatically confirm user email
await User.setUserField(uid, 'email', email);
await UserEmail.confirmByUid(uid);
await User.email.confirmByUid(uid);
}

// Save provider-specific information to the user
Expand Down
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"url": "https://github.com/FAForever/nodebb-plugin-sso-oauth-faforever",
"library": "./library.js",
"hooks": [
{ "hook": "static:app.load", "method": "load" },
{ "hook": "static:api.routes", "method": "addRoutes" },
{ "hook": "static:user.delete", "method": "deleteUserData" },
{ "hook": "filter:user.whitelistFields", "method": "whitelistFields" },
{ "hook": "filter:auth.init", "method": "getStrategy" }
Expand Down

0 comments on commit 11b7888

Please sign in to comment.