oauth2.js 897 B

123456789101112131415161718192021222324252627282930313233343536
  1. /* global WIKI */
  2. // ------------------------------------
  3. // OAuth2 Account
  4. // ------------------------------------
  5. const OAuth2Strategy = require('passport-oauth2').Strategy
  6. module.exports = {
  7. key: 'oauth2',
  8. title: 'OAuth2',
  9. useForm: false,
  10. props: {
  11. clientId: String,
  12. clientSecret: String,
  13. authorizationURL: String,
  14. tokenURL: String
  15. },
  16. init (passport, conf) {
  17. passport.use('oauth2',
  18. new OAuth2Strategy({
  19. authorizationURL: conf.authorizationURL,
  20. tokenURL: conf.tokenURL,
  21. clientID: conf.clientId,
  22. clientSecret: conf.clientSecret,
  23. callbackURL: conf.callbackURL
  24. }, (accessToken, refreshToken, profile, cb) => {
  25. WIKI.db.users.processProfile(profile).then((user) => {
  26. return cb(null, user) || true
  27. }).catch((err) => {
  28. return cb(err, null) || true
  29. })
  30. })
  31. )
  32. }
  33. }