|
@ -13,7 +13,6 @@ const UserBlock = mongoose.model('UserBlock'); |
|
|
|
|
|
|
|
|
const passport = require('passport'); |
|
|
const passport = require('passport'); |
|
|
const PassportLocal = require('passport-local'); |
|
|
const PassportLocal = require('passport-local'); |
|
|
const OAuth2Strategy = require('passport-oauth2'); |
|
|
|
|
|
|
|
|
|
|
|
const striptags = require('striptags'); |
|
|
const striptags = require('striptags'); |
|
|
const uuidv4 = require('uuid').v4; |
|
|
const uuidv4 = require('uuid').v4; |
|
@ -41,7 +40,6 @@ class UserService extends SiteService { |
|
|
this.log.info(`starting ${module.exports.name} service`); |
|
|
this.log.info(`starting ${module.exports.name} service`); |
|
|
|
|
|
|
|
|
this.registerPassportLocal(); |
|
|
this.registerPassportLocal(); |
|
|
this.registerPassportOAuth2(); |
|
|
|
|
|
|
|
|
|
|
|
if (process.env.DTP_ADMIN === 'enabled') { |
|
|
if (process.env.DTP_ADMIN === 'enabled') { |
|
|
this.registerPassportAdmin(); |
|
|
this.registerPassportAdmin(); |
|
@ -305,8 +303,6 @@ class UserService extends SiteService { |
|
|
throw new SiteError(403, 'Admin privileges required'); |
|
|
throw new SiteError(403, 'Admin privileges required'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
this.log.debug('user authenticated', { user }); |
|
|
|
|
|
|
|
|
|
|
|
return user; |
|
|
return user; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -332,25 +328,6 @@ class UserService extends SiteService { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
registerPassportOAuth2 ( ) { |
|
|
|
|
|
const AUTH_HOST = process.env.DTP_CORE_AUTH_HOST || 'localhost'; |
|
|
|
|
|
const oauthOptions = { |
|
|
|
|
|
authorizationURL: `http://${AUTH_HOST}/oauth2/authorize`, |
|
|
|
|
|
tokenURL: `http://${AUTH_HOST}/oauth2/token`, |
|
|
|
|
|
clientID: process.env.DTP_CORE_CLIENT_ID, |
|
|
|
|
|
clientSecret: process.env.DTP_CORE_CLIENT_SECRET, |
|
|
|
|
|
callbackURL: `http://${process.env.DTP_SITE_DOMAIN}/auth/core/callback`, |
|
|
|
|
|
}; |
|
|
|
|
|
passport.use(new OAuth2Strategy(oauthOptions, this.handleOAuth2Login.bind(this))); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async handleOAuth2Login (accessToken, refreshToken, profile, cb) { |
|
|
|
|
|
this.log.info('OAuth2 login', { accessToken, refreshToken, profile }); |
|
|
|
|
|
User.findOrCreate({ exampleId: profile.id }, function (err, user) { |
|
|
|
|
|
return cb(err, user); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
registerPassportAdmin ( ) { |
|
|
registerPassportAdmin ( ) { |
|
|
const options = { |
|
|
const options = { |
|
|
usernameField: 'username', |
|
|
usernameField: 'username', |
|
|