|
|
|
@ -13,7 +13,6 @@ const UserBlock = mongoose.model('UserBlock');
|
|
|
|
|
|
|
|
|
|
const passport = require('passport');
|
|
|
|
|
const PassportLocal = require('passport-local');
|
|
|
|
|
const OAuth2Strategy = require('passport-oauth2');
|
|
|
|
|
|
|
|
|
|
const striptags = require('striptags');
|
|
|
|
|
const uuidv4 = require('uuid').v4;
|
|
|
|
@ -41,7 +40,6 @@ class UserService {
|
|
|
|
|
async start ( ) {
|
|
|
|
|
this.log.info(`starting ${module.exports.name} service`);
|
|
|
|
|
this.registerPassportLocal();
|
|
|
|
|
this.registerPassportOAuth2();
|
|
|
|
|
if (process.env.DTP_ADMIN === 'enabled') {
|
|
|
|
|
this.registerPassportAdmin();
|
|
|
|
|
}
|
|
|
|
@ -338,25 +336,6 @@ class UserService {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
registerPassportOAuth2 ( ) {
|
|
|
|
|
const AUTH_HOST = process.env.DTP_CORE_AUTH_HOST || 'localhost';
|
|
|
|
|
const oauthOptions = {
|
|
|
|
|
authorizationURL: `https://${AUTH_HOST}/oauth2/authorize`,
|
|
|
|
|
tokenURL: `https://${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/example/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 ( ) {
|
|
|
|
|
const options = {
|
|
|
|
|
usernameField: 'username',
|
|
|
|
|