Skip to content

Commit 5cda550

Browse files
committed
Add mattermost authentication
1 parent dad5798 commit 5cda550

File tree

14 files changed

+116
-13
lines changed

14 files changed

+116
-13
lines changed

README.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ HackMD
88
[![version][github-version-badge]][github-release-page]
99

1010

11-
HackMD lets you create realtime collaborative markdown notes on all platforms.
12-
Inspired by Hackpad, with more focus on speed and flexibility.
11+
HackMD lets you create realtime collaborative markdown notes on all platforms.
12+
Inspired by Hackpad, with more focus on speed and flexibility.
1313
Still in the early stage, feel free to fork or contribute to HackMD.
1414

1515
Thanks for using! :smile:
@@ -97,13 +97,13 @@ If you are upgrading HackMD from an older version, follow these steps:
9797

9898
* [migration-to-0.5.0](https://github.com/hackmdio/migration-to-0.5.0)
9999

100-
We don't use LZString to compress socket.io data and DB data after version 0.5.0.
100+
We don't use LZString to compress socket.io data and DB data after version 0.5.0.
101101
Please run the migration tool if you're upgrading from the old version.
102102

103103
* [migration-to-0.4.0](https://github.com/hackmdio/migration-to-0.4.0)
104104

105-
We've dropped MongoDB after version 0.4.0.
106-
So here is the migration tool for you to transfer the old DB data to the new DB.
105+
We've dropped MongoDB after version 0.4.0.
106+
So here is the migration tool for you to transfer the old DB data to the new DB.
107107
This tool is also used for official service.
108108

109109
# Configuration
@@ -141,6 +141,9 @@ There are some configs you need to change in the files below
141141
| HMD_GITLAB_BASEURL | no example | GitLab authentication endpoint, set to use other endpoint than GitLab.com (optional) |
142142
| HMD_GITLAB_CLIENTID | no example | GitLab API client id |
143143
| HMD_GITLAB_CLIENTSECRET | no example | GitLab API client secret |
144+
| HMD_MATTERMOST_BASEURL | no example | Mattermost authentication endpoint |
145+
| HMD_MATTERMOST_CLIENTID | no example | Mattermost API client id |
146+
| HMD_MATTERMOST_CLIENTSECRET | no example | Mattermost API client secret |
144147
| HMD_DROPBOX_CLIENTID | no example | Dropbox API client id |
145148
| HMD_DROPBOX_CLIENTSECRET | no example | Dropbox API client secret |
146149
| HMD_GOOGLE_CLIENTID | no example | Google API client id |
@@ -216,7 +219,7 @@ There are some configs you need to change in the files below
216219

217220
| service | settings location | description |
218221
| ------- | --------- | ----------- |
219-
| facebook, twitter, github, gitlab, dropbox, google, ldap | environment variables or `config.json` | for signin |
222+
| facebook, twitter, github, gitlab, mattermost, dropbox, google, ldap | environment variables or `config.json` | for signin |
220223
| imgur | environment variables or `config.json` | for image upload |
221224
| google drive(`google/apiKey`, `google/clientID`), dropbox(`dropbox/appKey`) | `config.json` | for export and import |
222225

@@ -228,6 +231,7 @@ There are some configs you need to change in the files below
228231
| twitter | `/auth/twitter/callback` |
229232
| github | `/auth/github/callback` |
230233
| gitlab | `/auth/gitlab/callback` |
234+
| mattermost | `/auth/mattermost/callback` |
231235
| dropbox | `/auth/dropbox/callback` |
232236
| google | `/auth/google/callback` |
233237

@@ -249,9 +253,9 @@ hackmd/
249253

250254
## Operational Transformation
251255

252-
From 0.3.2, we started supporting operational transformation.
253-
It makes concurrent editing safe and will not break up other users' operations.
254-
Additionally, now can show other clients' selections.
256+
From 0.3.2, we started supporting operational transformation.
257+
It makes concurrent editing safe and will not break up other users' operations.
258+
Additionally, now can show other clients' selections.
255259
See more at [http://operational-transformation.github.io/](http://operational-transformation.github.io/)
256260

257261

app.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,18 @@
100100
"description": "GitLab API client scope (optional)",
101101
"required": false
102102
},
103+
"HMD_MATTERMOST_BASEURL": {
104+
"description": "Mattermost authentication endpoint",
105+
"required": false
106+
},
107+
"HMD_MATTERMOST_CLIENTID": {
108+
"description": "Mattermost API client id",
109+
"required": false
110+
},
111+
"HMD_MATTERMOST_CLIENTSECRET": {
112+
"description": "Mattermost API client secret",
113+
"required": false
114+
},
103115
"HMD_DROPBOX_CLIENTID": {
104116
"description": "Dropbox API client id",
105117
"required": false

config.json.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@
4848
"clientSecret": "change this",
4949
"scope": "use 'read_user' scope for auth user only or remove this property if you need gitlab snippet import/export support (will result to be default scope 'api')"
5050
},
51+
"mattermost": {
52+
"baseURL": "change this",
53+
"clientID": "change this",
54+
"clientSecret": "change this"
55+
},
5156
"dropbox": {
5257
"clientID": "change this",
5358
"clientSecret": "change this",

lib/config/default.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ module.exports = {
7474
clientSecret: undefined,
7575
scope: undefined
7676
},
77+
mattermost: {
78+
baseURL: undefined,
79+
clientID: undefined,
80+
clientSecret: undefined
81+
},
7782
dropbox: {
7883
clientID: undefined,
7984
clientSecret: undefined

lib/config/dockerSecret.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ if (fs.existsSync(basePath)) {
3838
clientID: getSecret('gitlab_clientID'),
3939
clientSecret: getSecret('gitlab_clientSecret')
4040
},
41+
mattermost: {
42+
clientID: getSecret('mattermost_clientID'),
43+
clientSecret: getSecret('mattermost_clientSecret')
44+
},
4145
dropbox: {
4246
clientID: getSecret('dropbox_clientID'),
4347
clientSecret: getSecret('dropbox_clientSecret')

lib/config/environment.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ module.exports = {
4949
clientSecret: process.env.HMD_GITLAB_CLIENTSECRET,
5050
scope: process.env.HMD_GITLAB_SCOPE
5151
},
52+
mattermost: {
53+
baseURL: process.env.HMD_MATTERMOST_BASEURL,
54+
clientID: process.env.HMD_MATTERMOST_CLIENTID,
55+
clientSecret: process.env.HMD_MATTERMOST_CLIENTSECRET
56+
},
5257
dropbox: {
5358
clientID: process.env.HMD_DROPBOX_CLIENTID,
5459
clientSecret: process.env.HMD_DROPBOX_CLIENTSECRET

lib/config/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ config.isTwitterEnable = config.twitter.consumerKey && config.twitter.consumerSe
9090
config.isEmailEnable = config.email
9191
config.isGitHubEnable = config.github.clientID && config.github.clientSecret
9292
config.isGitLabEnable = config.gitlab.clientID && config.gitlab.clientSecret
93+
config.isMattermostEnable = config.mattermost.clientID && config.mattermost.clientSecret
9394
config.isLDAPEnable = config.ldap.url
9495
config.isPDFExportEnable = config.allowpdfexport
9596

lib/models/user.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,15 @@ module.exports = function (sequelize, DataTypes) {
111111
photo = letterAvatars(profile.username)
112112
}
113113
break
114+
case 'mattermost':
115+
photo = profile.avatarUrl
116+
if (photo) {
117+
if (bigger) photo = photo.replace(/(\?s=)\d*$/i, '$1400')
118+
else photo = photo.replace(/(\?s=)\d*$/i, '$196')
119+
} else {
120+
photo = letterAvatars(profile.username)
121+
}
122+
break
114123
case 'dropbox':
115124
// no image api provided, use gravatar
116125
photo = 'https://www.gravatar.com/avatar/' + md5(profile.emails[0].value)

lib/response.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ function showIndex (req, res, next) {
6464
twitter: config.isTwitterEnable,
6565
github: config.isGitHubEnable,
6666
gitlab: config.isGitLabEnable,
67+
mattermost: config.isMattermostEnable,
6768
dropbox: config.isDropboxEnable,
6869
google: config.isGoogleEnable,
6970
ldap: config.isLDAPEnable,

lib/web/auth/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ if (config.isFacebookEnable) authRouter.use(require('./facebook'))
3333
if (config.isTwitterEnable) authRouter.use(require('./twitter'))
3434
if (config.isGitHubEnable) authRouter.use(require('./github'))
3535
if (config.isGitLabEnable) authRouter.use(require('./gitlab'))
36+
if (config.isMattermostEnable) authRouter.use(require('./mattermost'))
3637
if (config.isDropboxEnable) authRouter.use(require('./dropbox'))
3738
if (config.isGoogleEnable) authRouter.use(require('./google'))
3839
if (config.isLDAPEnable) authRouter.use(require('./ldap'))

0 commit comments

Comments
 (0)