authentication.js 831 B

1234567891011121314151617181920212223242526272829303132
  1. /* global WIKI */
  2. // ------------------------------------
  3. // OAuth2 Account
  4. // ------------------------------------
  5. const OAuth2Strategy = require('passport-oauth2').Strategy
  6. module.exports = {
  7. init (passport, conf) {
  8. passport.use('oauth2',
  9. new OAuth2Strategy({
  10. authorizationURL: conf.authorizationURL,
  11. tokenURL: conf.tokenURL,
  12. clientID: conf.clientId,
  13. clientSecret: conf.clientSecret,
  14. callbackURL: conf.callbackURL,
  15. passReqToCallback: true
  16. }, async (req, accessToken, refreshToken, profile, cb) => {
  17. try {
  18. const user = await WIKI.models.users.processProfile({
  19. providerKey: req.params.strategy,
  20. profile
  21. })
  22. cb(null, user)
  23. } catch (err) {
  24. cb(err, null)
  25. }
  26. })
  27. )
  28. }
  29. }