Skip to content

Commit 16b3e01

Browse files
authored
Merge pull request #606 from DoubleMalt/feature/MattermostAuth
Add Mattermost authentication strategy
2 parents f281273 + 5cda550 commit 16b3e01

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:
@@ -112,13 +112,13 @@ If you are upgrading HackMD from an older version, follow these steps:
112112

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

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

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

120-
We've dropped MongoDB after version 0.4.0.
121-
So here is the migration tool for you to transfer the old DB data to the new DB.
120+
We've dropped MongoDB after version 0.4.0.
121+
So here is the migration tool for you to transfer the old DB data to the new DB.
122122
This tool is also used for official service.
123123

124124
# Configuration
@@ -156,6 +156,9 @@ There are some configs you need to change in the files below
156156
| HMD_GITLAB_BASEURL | no example | GitLab authentication endpoint, set to use other endpoint than GitLab.com (optional) |
157157
| HMD_GITLAB_CLIENTID | no example | GitLab API client id |
158158
| HMD_GITLAB_CLIENTSECRET | no example | GitLab API client secret |
159+
| HMD_MATTERMOST_BASEURL | no example | Mattermost authentication endpoint |
160+
| HMD_MATTERMOST_CLIENTID | no example | Mattermost API client id |
161+
| HMD_MATTERMOST_CLIENTSECRET | no example | Mattermost API client secret |
159162
| HMD_DROPBOX_CLIENTID | no example | Dropbox API client id |
160163
| HMD_DROPBOX_CLIENTSECRET | no example | Dropbox API client secret |
161164
| HMD_GOOGLE_CLIENTID | no example | Google API client id |
@@ -231,7 +234,7 @@ There are some configs you need to change in the files below
231234

232235
| service | settings location | description |
233236
| ------- | --------- | ----------- |
234-
| facebook, twitter, github, gitlab, dropbox, google, ldap | environment variables or `config.json` | for signin |
237+
| facebook, twitter, github, gitlab, mattermost, dropbox, google, ldap | environment variables or `config.json` | for signin |
235238
| imgur | environment variables or `config.json` | for image upload |
236239
| google drive(`google/apiKey`, `google/clientID`), dropbox(`dropbox/appKey`) | `config.json` | for export and import |
237240

@@ -243,6 +246,7 @@ There are some configs you need to change in the files below
243246
| twitter | `/auth/twitter/callback` |
244247
| github | `/auth/github/callback` |
245248
| gitlab | `/auth/gitlab/callback` |
249+
| mattermost | `/auth/mattermost/callback` |
246250
| dropbox | `/auth/dropbox/callback` |
247251
| google | `/auth/google/callback` |
248252

@@ -264,9 +268,9 @@ hackmd/
264268

265269
## Operational Transformation
266270

267-
From 0.3.2, we started supporting operational transformation.
268-
It makes concurrent editing safe and will not break up other users' operations.
269-
Additionally, now can show other clients' selections.
271+
From 0.3.2, we started supporting operational transformation.
272+
It makes concurrent editing safe and will not break up other users' operations.
273+
Additionally, now can show other clients' selections.
270274
See more at [http://operational-transformation.github.io/](http://operational-transformation.github.io/)
271275

272276

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)