Browse Source

feat: rocket.chat auth module

pull/2502/head
NGPixel 4 years ago
parent
commit
b0f61d6605
3 changed files with 94 additions and 0 deletions
  1. 1
      client/static/svg/auth-icon-rocketchat.svg
  2. 64
      server/modules/authentication/rocketchat/authentication.js
  3. 29
      server/modules/authentication/rocketchat/definition.yml

1
client/static/svg/auth-icon-rocketchat.svg

@ -0,0 +1 @@
<svg width="2500" height="2139" viewBox="0 0 256 219" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid"><path d="M255.95 109.307c0-12.853-3.844-25.173-11.43-36.63-6.81-10.283-16.351-19.385-28.355-27.057-23.18-14.806-53.647-22.963-85.782-22.963-10.734 0-21.315.907-31.577 2.705-6.366-5.96-13.82-11.322-21.707-15.56C34.964-10.62.022 9.322.022 9.322s32.487 26.688 27.204 50.08C12.693 73.821 4.814 91.207 4.814 109.307c0 .056.003.115.003.173 0 .057-.003.113-.003.174 0 18.1 7.876 35.486 22.412 49.902C32.509 182.95.022 209.639.022 209.639s34.942 19.939 77.077-.48c7.886-4.238 15.338-9.603 21.707-15.56 10.264 1.796 20.843 2.702 31.577 2.702 32.137 0 62.601-8.151 85.782-22.958 12.004-7.671 21.545-16.77 28.356-27.058 7.585-11.455 11.43-23.781 11.43-36.628 0-.06-.003-.115-.003-.174l.002-.176z" fill="#C1272D"/><path d="M130.383 40.828c59.505 0 107.746 30.814 107.746 68.824 0 38.007-48.241 68.823-107.746 68.823-13.25 0-25.94-1.532-37.662-4.325-11.915 14.332-38.125 34.26-63.587 27.82 8.282-8.895 20.552-23.926 17.926-48.686-15.262-11.873-24.422-27.07-24.422-43.632-.003-38.013 48.238-68.824 107.745-68.824" fill="#FFF"/><path d="M130.383 126.18c7.906 0 14.314-6.408 14.314-14.314 0-7.905-6.408-14.313-14.314-14.313-7.905 0-14.313 6.408-14.313 14.313 0 7.906 6.408 14.314 14.313 14.314zm49.764 0c7.905 0 14.314-6.408 14.314-14.314 0-7.905-6.409-14.313-14.314-14.313s-14.313 6.408-14.313 14.313c0 7.906 6.408 14.314 14.313 14.314zm-99.53-.003c7.904 0 14.311-6.407 14.311-14.31 0-7.904-6.407-14.312-14.31-14.312-7.905 0-14.312 6.408-14.312 14.311 0 7.904 6.407 14.311 14.311 14.311z" fill="#C1272D"/><path d="M130.383 169.42c-13.25 0-25.94-1.33-37.662-3.75-10.52 10.969-32.188 25.714-54.643 25.172-2.959 4.484-6.175 8.15-8.944 11.126 25.462 6.44 51.672-13.486 63.587-27.82 11.723 2.795 24.414 4.325 37.662 4.325 59.027 0 106.962-30.326 107.726-67.915-.764 32.582-48.699 58.861-107.726 58.861z" fill="#CCC"/></svg>

64
server/modules/authentication/rocketchat/authentication.js

@ -0,0 +1,64 @@
const _ = require('lodash')
/* global WIKI */
// ------------------------------------
// Rocket.chat Account
// ------------------------------------
const OAuth2Strategy = require('passport-oauth2').Strategy
module.exports = {
init (passport, conf) {
const siteURL = conf.siteURL.slice(-1) === '/' ? conf.siteURL.slice(0, -1) : conf.siteURL
OAuth2Strategy.prototype.userProfile = function (accessToken, cb) {
this._oauth2.get(`${siteURL}/api/v1/me`, accessToken, (err, body, res) => {
if (err) {
WIKI.logger.warn('Rocket.chat - Failed to fetch user profile.')
return cb(err)
}
try {
const usr = JSON.parse(body)
cb(null, {
id: usr._id,
displayName: _.isEmpty(usr.name) ? usr.username : usr.name,
email: usr.email,
picture: usr.avatarUrl
})
} catch (err) {
WIKI.logger.warn('Rocket.chat - Failed to parse user profile.')
cb(err)
}
})
}
passport.use('rocketchat',
new OAuth2Strategy({
authorizationURL: `${siteURL}/oauth/authorize`,
tokenURL: `${siteURL}/oauth/token`,
clientID: conf.clientId,
clientSecret: conf.clientSecret,
callbackURL: conf.callbackURL,
passReqToCallback: true
}, async (req, accessToken, refreshToken, profile, cb) => {
try {
const user = await WIKI.models.users.processProfile({
providerKey: req.params.strategy,
profile
})
cb(null, user)
} catch (err) {
cb(err, null)
}
})
)
},
logout (conf) {
if (!conf.logoutURL) {
return '/'
} else {
return conf.logoutURL
}
}
}

29
server/modules/authentication/rocketchat/definition.yml

@ -0,0 +1,29 @@
key: rocketchat
title: Rocket.chat
description: Communicate and collaborate with your team, share files, chat in real-time, or switch to video/audio conferencing.
author: requarks.io
logo: https://static.requarks.io/logo/rocketchat.svg
color: red accent-3
website: https://rocket.chat/
isAvailable: true
useForm: false
scopes:
- openid
- profile
- email
props:
clientId:
type: String
title: Client ID
hint: Application Client ID
order: 1
clientSecret:
type: String
title: Client Secret
hint: Application Client Secret
order: 2
siteURL:
type: String
title: Rocket.chat Site URL
hint: The base URL of your Rocket.chat site (e.g. https://example.rocket.chat)
order: 3
Loading…
Cancel
Save