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: Lucas Neves <lneves@modusgames.com>
Co-authored-by: Nicolas Giard <github@ngpixel.com>
pull/1609/head
Lucas 4 years ago committed by GitHub
parent a6dd93746e
commit a5297f8c6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -5,6 +5,7 @@
// ------------------------------------
const DiscordStrategy = require('passport-discord').Strategy
const _ = require('lodash')
module.exports = {
init (passport, conf) {
@ -14,9 +15,12 @@ module.exports = {
clientSecret: conf.clientSecret,
authorizationURL: 'https://discordapp.com/api/oauth2/authorize?prompt=none',
callbackURL: conf.callbackURL,
scope: 'identify email'
scope: 'identify email guilds'
}, async (accessToken, refreshToken, profile, cb) => {
try {
if (conf.guildId && !_.some(profile.guilds, { id: conf.guildId })) {
throw new WIKI.Error.AuthLoginFailed()
}
const user = await WIKI.models.users.processProfile({
profile: {
...profile,

@ -18,3 +18,8 @@ props:
title: Client Secret
hint: Application Client Secret
order: 2
guildId:
type: String
title: Server ID
hint: Optional - Your unique server identifier, such that only members are authorized
order: 3

Loading…
Cancel
Save