diff --git a/server/modules/authentication/discord/authentication.js b/server/modules/authentication/discord/authentication.js index ec0b56f6..67c079ca 100644 --- a/server/modules/authentication/discord/authentication.js +++ b/server/modules/authentication/discord/authentication.js @@ -6,12 +6,12 @@ const DiscordStrategy = require('passport-discord').Strategy const _ = require('lodash') -const DiscordOauth2 = require('discord-oauth2') +const DiscordOauth2 = require('./node_modules/discord-oauth2/index.js') //I don't remember why I -// Checks for the existence of all of the configured role IDs in the member's guild IDs. +// Checks for the existence of all of the required role IDs in the member's guild role IDs. function hasRoles(memberRoles, authRoles) { - if (memberRoles.every(value => { - return authRoles.includes(value) + if (authRoles.every(value => { + return memberRoles.includes(value) })) { return true } else { @@ -34,7 +34,7 @@ module.exports = { if (conf.roles) { const discord = new DiscordOauth2() const memberRoles = await discord.getGuildMember(accessToken, conf.guildId) - if (!hasRoles(memberRoles.roles, conf.roles)) { + if (!hasRoles(memberRoles.roles, conf.roles.split())) { throw new WIKI.Error.AuthLoginFailed() } } else if (conf.guildId && !_.some(profile.guilds, { id: conf.guildId })) { diff --git a/server/modules/authentication/discord/package-lock.json b/server/modules/authentication/discord/package-lock.json new file mode 100644 index 00000000..17756ef6 --- /dev/null +++ b/server/modules/authentication/discord/package-lock.json @@ -0,0 +1,22 @@ +{ + "name": "wikijs-discord-oauth2", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "wikijs-discord-oauth2", + "version": "1.0.0", + "license": "AGPL-3.0-or-later", + "dependencies": { + "discord-oauth2": "^2.11.0" + }, + "devDependencies": {} + }, + "node_modules/discord-oauth2": { + "version": "2.11.0", + "resolved": "https://registry.npmjs.org/discord-oauth2/-/discord-oauth2-2.11.0.tgz", + "integrity": "sha512-pIbgXm498f7vqNd8/7JwoLd36YMFOFASSJdqyCGdwQpaG7ULHu9nLyifpVXI1b88xvNLqQwqugS8jxkn8Ypd1Q==" + } + } +} diff --git a/server/modules/authentication/discord/package.json b/server/modules/authentication/discord/package.json new file mode 100644 index 00000000..8c391798 --- /dev/null +++ b/server/modules/authentication/discord/package.json @@ -0,0 +1,19 @@ +{ + "name": "wikijs-discord-oauth2", + "version": "1.0.0", + "description": "Supports using Discord as a SSO source, and allows the administrator to configure discord groups that are required for authentication.", + "main": "authentication.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [ + "wikijs", + "discord", + "sso" + ], + "author": "Tom Dakan", + "license": "AGPL-3.0-or-later", + "dependencies": { + "discord-oauth2": "^2.11.0" + } +}