You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
852 B

  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: ['clientId', 'clientSecret', 'authorizationURL', 'tokenURL'],
  11. init (passport, conf) {
  12. passport.use('oauth2',
  13. new OAuth2Strategy({
  14. authorizationURL: conf.authorizationURL,
  15. tokenURL: conf.tokenURL,
  16. clientID: conf.clientId,
  17. clientSecret: conf.clientSecret,
  18. callbackURL: conf.callbackURL
  19. }, (accessToken, refreshToken, profile, cb) => {
  20. wiki.db.User.processProfile(profile).then((user) => {
  21. return cb(null, user) || true
  22. }).catch((err) => {
  23. return cb(err, null) || true
  24. })
  25. })
  26. )
  27. }
  28. }