|
@@ -3,7 +3,7 @@ const _ = require('lodash')
|
|
|
/* global WIKI */
|
|
|
|
|
|
// ------------------------------------
|
|
|
-// OAuth2 Connect Account
|
|
|
+// OAuth2 Account
|
|
|
// ------------------------------------
|
|
|
|
|
|
const OAuth2Strategy = require('passport-oauth2').Strategy
|
|
@@ -17,15 +17,15 @@ module.exports = {
|
|
|
clientSecret: conf.clientSecret,
|
|
|
userInfoURL: conf.userInfoURL,
|
|
|
callbackURL: conf.callbackURL,
|
|
|
- passReqToCallback: true,
|
|
|
+ passReqToCallback: true
|
|
|
}, async (req, accessToken, refreshToken, profile, cb) => {
|
|
|
try {
|
|
|
const user = await WIKI.models.users.processProfile({
|
|
|
providerKey: req.params.strategy,
|
|
|
profile: {
|
|
|
...profile,
|
|
|
- id: _.get(profile, conf.userId),
|
|
|
- displayName: _.get(profile, conf.displayName, ''),
|
|
|
+ id: _.get(profile, conf.userIdClaim),
|
|
|
+ displayName: _.get(profile, conf.displayNameClaim, '???'),
|
|
|
email: _.get(profile, conf.emailClaim)
|
|
|
}
|
|
|
})
|
|
@@ -36,19 +36,26 @@ module.exports = {
|
|
|
})
|
|
|
|
|
|
client.userProfile = function (accesstoken, done) {
|
|
|
- this._oauth2._useAuthorizationHeaderForGET = true;
|
|
|
+ this._oauth2._useAuthorizationHeaderForGET = true
|
|
|
this._oauth2.get(conf.userInfoURL, accesstoken, (err, data) => {
|
|
|
if (err) {
|
|
|
return done(err)
|
|
|
}
|
|
|
try {
|
|
|
data = JSON.parse(data)
|
|
|
- } catch(e) {
|
|
|
+ } catch (e) {
|
|
|
return done(e)
|
|
|
}
|
|
|
done(null, data)
|
|
|
})
|
|
|
}
|
|
|
passport.use('oauth2', client)
|
|
|
+ },
|
|
|
+ logout (conf) {
|
|
|
+ if (!conf.logoutURL) {
|
|
|
+ return '/'
|
|
|
+ } else {
|
|
|
+ return conf.logoutURL
|
|
|
+ }
|
|
|
}
|
|
|
}
|