Unverified Commit a5297f8c authored by Lucas's avatar Lucas Committed by GitHub

feat: option to restrict Discord auth to a specific server (#1548)

* Optionally restrict discord authentication to members of a specific server * fix: discord auth module code linting Co-authored-by: 's avatarLucas Neves <lneves@modusgames.com> Co-authored-by: 's avatarNicolas Giard <github@ngpixel.com>
parent a6dd9374
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
// ------------------------------------ // ------------------------------------
const DiscordStrategy = require('passport-discord').Strategy const DiscordStrategy = require('passport-discord').Strategy
const _ = require('lodash')
module.exports = { module.exports = {
init (passport, conf) { init (passport, conf) {
...@@ -14,9 +15,12 @@ module.exports = { ...@@ -14,9 +15,12 @@ module.exports = {
clientSecret: conf.clientSecret, clientSecret: conf.clientSecret,
authorizationURL: 'https://discordapp.com/api/oauth2/authorize?prompt=none', authorizationURL: 'https://discordapp.com/api/oauth2/authorize?prompt=none',
callbackURL: conf.callbackURL, callbackURL: conf.callbackURL,
scope: 'identify email' scope: 'identify email guilds'
}, async (accessToken, refreshToken, profile, cb) => { }, async (accessToken, refreshToken, profile, cb) => {
try { try {
if (conf.guildId && !_.some(profile.guilds, { id: conf.guildId })) {
throw new WIKI.Error.AuthLoginFailed()
}
const user = await WIKI.models.users.processProfile({ const user = await WIKI.models.users.processProfile({
profile: { profile: {
...profile, ...profile,
......
...@@ -18,3 +18,8 @@ props: ...@@ -18,3 +18,8 @@ props:
title: Client Secret title: Client Secret
hint: Application Client Secret hint: Application Client Secret
order: 2 order: 2
guildId:
type: String
title: Server ID
hint: Optional - Your unique server identifier, such that only members are authorized
order: 3
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment