|
|
|
@ -13,7 +13,8 @@ module.exports = {
|
|
|
|
const siteURL = conf.siteURL.slice(-1) === '/' ? conf.siteURL.slice(0, -1) : conf.siteURL
|
|
|
|
const siteURL = conf.siteURL.slice(-1) === '/' ? conf.siteURL.slice(0, -1) : conf.siteURL
|
|
|
|
|
|
|
|
|
|
|
|
OAuth2Strategy.prototype.userProfile = function (accessToken, cb) {
|
|
|
|
OAuth2Strategy.prototype.userProfile = function (accessToken, cb) {
|
|
|
|
this._oauth2.get(`${siteURL}/api/v1/me`, accessToken, (err, body, res) => {
|
|
|
|
this._oauth2.useAuthorizationHeaderforGET(true)
|
|
|
|
|
|
|
|
this._oauth2.get(`${siteURL}/oauth/userinfo`, accessToken, (err, body, res) => {
|
|
|
|
if (err) {
|
|
|
|
if (err) {
|
|
|
|
WIKI.logger.warn('Rocket.chat - Failed to fetch user profile.')
|
|
|
|
WIKI.logger.warn('Rocket.chat - Failed to fetch user profile.')
|
|
|
|
return cb(err)
|
|
|
|
return cb(err)
|
|
|
|
@ -21,10 +22,10 @@ module.exports = {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const usr = JSON.parse(body)
|
|
|
|
const usr = JSON.parse(body)
|
|
|
|
cb(null, {
|
|
|
|
cb(null, {
|
|
|
|
id: usr._id,
|
|
|
|
id: usr.sub,
|
|
|
|
displayName: _.isEmpty(usr.name) ? usr.username : usr.name,
|
|
|
|
displayName: _.isEmpty(usr.name) ? usr.preffered_username : usr.name,
|
|
|
|
email: usr.emails[0].address,
|
|
|
|
email: usr.email,
|
|
|
|
picture: usr.avatarUrl
|
|
|
|
picture: usr.picture
|
|
|
|
})
|
|
|
|
})
|
|
|
|
} catch (err) {
|
|
|
|
} catch (err) {
|
|
|
|
WIKI.logger.warn('Rocket.chat - Failed to parse user profile.')
|
|
|
|
WIKI.logger.warn('Rocket.chat - Failed to parse user profile.')
|
|
|
|
@ -40,7 +41,8 @@ module.exports = {
|
|
|
|
clientID: conf.clientId,
|
|
|
|
clientID: conf.clientId,
|
|
|
|
clientSecret: conf.clientSecret,
|
|
|
|
clientSecret: conf.clientSecret,
|
|
|
|
callbackURL: conf.callbackURL,
|
|
|
|
callbackURL: conf.callbackURL,
|
|
|
|
passReqToCallback: true
|
|
|
|
passReqToCallback: true,
|
|
|
|
|
|
|
|
state: true
|
|
|
|
}, async (req, accessToken, refreshToken, profile, cb) => {
|
|
|
|
}, async (req, accessToken, refreshToken, profile, cb) => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const user = await WIKI.models.users.processProfile({
|
|
|
|
const user = await WIKI.models.users.processProfile({
|
|
|
|
|