|
@@ -2,6 +2,7 @@ const debug = require('debug')('growi:service:PassportService');
|
|
|
const passport = require('passport');
|
|
const passport = require('passport');
|
|
|
const LocalStrategy = require('passport-local').Strategy;
|
|
const LocalStrategy = require('passport-local').Strategy;
|
|
|
const LdapStrategy = require('passport-ldapauth');
|
|
const LdapStrategy = require('passport-ldapauth');
|
|
|
|
|
+const GoogleStrategy = require('passport-google-oauth').OAuth2Strategy;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* the service class of Passport
|
|
* the service class of Passport
|
|
@@ -25,6 +26,11 @@ class PassportService {
|
|
|
*/
|
|
*/
|
|
|
this.isLdapStrategySetup = false;
|
|
this.isLdapStrategySetup = false;
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * the flag whether LdapStrategy is set up successfully
|
|
|
|
|
+ */
|
|
|
|
|
+ this.isGoogleStrategySetup = false;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* the flag whether serializer/deserializer are set up successfully
|
|
* the flag whether serializer/deserializer are set up successfully
|
|
|
*/
|
|
*/
|
|
@@ -235,6 +241,68 @@ class PassportService {
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Asynchronous configuration retrieval
|
|
|
|
|
+ *
|
|
|
|
|
+ * @memberof PassportService
|
|
|
|
|
+ */
|
|
|
|
|
+ setupGoogleStrategy() {
|
|
|
|
|
+ // check whether the strategy has already been set up
|
|
|
|
|
+ if (this.isGoogleStrategySetup) {
|
|
|
|
|
+ throw new Error('GoogleStrategy has already been set up');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const config = this.crowi.config;
|
|
|
|
|
+ const Config = this.crowi.model('Config');
|
|
|
|
|
+ //this
|
|
|
|
|
+ const isGoogleEnabled = Config.isEnabledPassportGoogle(config);
|
|
|
|
|
+
|
|
|
|
|
+ // when disabled
|
|
|
|
|
+ if (!isGoogleEnabled) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ debug('GoogleStrategy: setting up..');
|
|
|
|
|
+
|
|
|
|
|
+ // passport.use(new LdapStrategy(this.getLdapConfigurationFunc(config, {passReqToCallback: true}),
|
|
|
|
|
+ // (req, ldapAccountInfo, done) => {
|
|
|
|
|
+ // debug('LDAP authentication has succeeded', ldapAccountInfo);
|
|
|
|
|
+
|
|
|
|
|
+ // // store ldapAccountInfo to req
|
|
|
|
|
+ // req.ldapAccountInfo = ldapAccountInfo;
|
|
|
|
|
+
|
|
|
|
|
+ // done(null, ldapAccountInfo);
|
|
|
|
|
+ // }
|
|
|
|
|
+ // ));
|
|
|
|
|
+ console.log('rere')
|
|
|
|
|
+ passport.use(new GoogleStrategy({
|
|
|
|
|
+ clientID: config.crowi['google:clientId'],
|
|
|
|
|
+ clientSecret: config.crowi['google:clientSecret'],
|
|
|
|
|
+ callbackURL: '/auth/passport/google/callback',
|
|
|
|
|
+ },
|
|
|
|
|
+ function(accessToken, refreshToken, profile, done) {
|
|
|
|
|
+ console.log(profile)
|
|
|
|
|
+ // User.findOrCreate({ googleId: profile.id }, function(err, user) {
|
|
|
|
|
+ // return done(err, user);
|
|
|
|
|
+ // });
|
|
|
|
|
+ }
|
|
|
|
|
+ ));
|
|
|
|
|
+
|
|
|
|
|
+ this.isGoogleStrategySetup = true;
|
|
|
|
|
+ debug('GoogleStrategy: setup is done');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * reset GoogleStrategy
|
|
|
|
|
+ *
|
|
|
|
|
+ * @memberof PassportService
|
|
|
|
|
+ */
|
|
|
|
|
+ resetGoogleStrategy() {
|
|
|
|
|
+ debug('GoogleStrategy: reset');
|
|
|
|
|
+ passport.unuse('google');
|
|
|
|
|
+ this.isGoogleStrategySetup = false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* setup serializer and deserializer
|
|
* setup serializer and deserializer
|
|
|
*
|
|
*
|