authentication.js 1010 B

1234567891011121314151617181920212223242526272829303132333435
  1. /* global WIKI */
  2. // ------------------------------------
  3. // Discord Account
  4. // ------------------------------------
  5. const DiscordStrategy = require('passport-discord').Strategy
  6. module.exports = {
  7. init (passport, conf) {
  8. passport.use('discord',
  9. new DiscordStrategy({
  10. clientID: conf.clientId,
  11. clientSecret: conf.clientSecret,
  12. authorizationURL: 'https://discordapp.com/api/oauth2/authorize?prompt=none',
  13. callbackURL: conf.callbackURL,
  14. scope: 'identify email'
  15. }, async (accessToken, refreshToken, profile, cb) => {
  16. try {
  17. const user = await WIKI.models.users.processProfile({
  18. profile: {
  19. ...profile,
  20. displayName: profile.username,
  21. picture: `https://cdn.discordapp.com/avatars/${profile.id}/${profile.avatar}.png`
  22. },
  23. providerKey: 'discord'
  24. })
  25. cb(null, user)
  26. } catch (err) {
  27. cb(err, null)
  28. }
  29. }
  30. ))
  31. }
  32. }