Skip to content

Commit 17e3b8b

Browse files
authored
Merge branch 'master' into ldap-username-field
2 parents 612b2d1 + 7475872 commit 17e3b8b

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ There are some configs you need to change in the files below
169169
| HMD_LDAP_TOKENSECRET | `supersecretkey` | secret used for generating access/refresh tokens |
170170
| HMD_LDAP_SEARCHBASE | `o=users,dc=example,dc=com` | LDAP directory to begin search from |
171171
| HMD_LDAP_SEARCHFILTER | `(uid={{username}})` | LDAP filter to search with |
172-
| HMD_LDAP_SEARCHATTRIBUTES | no example | LDAP attributes to search with |
172+
| HMD_LDAP_SEARCHATTRIBUTES | `displayName, mail` | LDAP attributes to search with (use comma to separate) |
173173
| HMD_LDAP_USERNAMEFIELD | `uid` | The LDAP field which is used as the username on HackMD |
174174
| HMD_LDAP_TLS_CA | `server-cert.pem, root.pem` | Root CA for LDAP TLS in PEM format (use comma to separate) |
175175
| HMD_LDAP_PROVIDERNAME | `My institution` | Optional name to be displayed at login form indicating the LDAP provider |
@@ -289,7 +289,7 @@ See more at [http://operational-transformation.github.io/](http://operational-tr
289289

290290
# License
291291

292-
**License under MIT.**
292+
**License under AGPL.**
293293

294294
[gitter-image]: https://badges.gitter.im/Join%20Chat.svg
295295
[gitter-url]: https://gitter.im/hackmdio/hackmd?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge

config.json.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
"tokenSecret": "change this",
7171
"searchBase": "change this",
7272
"searchFilter": "change this",
73-
"searchAttributes": "change this",
73+
"searchAttributes": ["change this"],
7474
"usernameField": "change this e.g. uid"
7575
"tlsOptions": {
7676
"changeme": "See https://nodejs.org/api/tls.html#tls_tls_connect_options_callback"

lib/config/environment.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const {toBooleanConfig} = require('./utils')
3+
const {toBooleanConfig, toArrayConfig} = require('./utils')
44

55
module.exports = {
66
domain: process.env.HMD_DOMAIN,
@@ -15,7 +15,7 @@ module.exports = {
1515
preload: toBooleanConfig(process.env.HMD_HSTS_PRELOAD)
1616
},
1717
protocolusessl: toBooleanConfig(process.env.HMD_PROTOCOL_USESSL),
18-
alloworigin: process.env.HMD_ALLOW_ORIGIN ? process.env.HMD_ALLOW_ORIGIN.split(',') : undefined,
18+
alloworigin: toArrayConfig(process.env.HMD_ALLOW_ORIGIN),
1919
usecdn: toBooleanConfig(process.env.HMD_USECDN),
2020
allowanonymous: toBooleanConfig(process.env.HMD_ALLOW_ANONYMOUS),
2121
allowfreeurl: toBooleanConfig(process.env.HMD_ALLOW_FREEURL),
@@ -70,7 +70,7 @@ module.exports = {
7070
tokenSecret: process.env.HMD_LDAP_TOKENSECRET,
7171
searchBase: process.env.HMD_LDAP_SEARCHBASE,
7272
searchFilter: process.env.HMD_LDAP_SEARCHFILTER,
73-
searchAttributes: process.env.HMD_LDAP_SEARCHATTRIBUTES,
73+
searchAttributes: toArrayConfig(process.env.HMD_LDAP_SEARCHATTRIBUTES),
7474
usernameField: process.env.HMD_LDAP_USERNAMEFIELD,
7575
tlsca: process.env.HMD_LDAP_TLS_CA
7676
},
@@ -80,8 +80,8 @@ module.exports = {
8080
issuer: process.env.HMD_SAML_ISSUER,
8181
identifierFormat: process.env.HMD_SAML_IDENTIFIERFORMAT,
8282
groupAttribute: process.env.HMD_SAML_GROUPATTRIBUTE,
83-
externalGroups: process.env.HMD_SAML_EXTERNALGROUPS ? process.env.HMD_SAML_EXTERNALGROUPS.split('|') : [],
84-
requiredGroups: process.env.HMD_SAML_REQUIREDGROUPS ? process.env.HMD_SAML_REQUIREDGROUPS.split('|') : [],
83+
externalGroups: toArrayConfig(process.env.HMD_SAML_EXTERNALGROUPS, '|', []),
84+
requiredGroups: toArrayConfig(process.env.HMD_SAML_REQUIREDGROUPS, '|', []),
8585
attribute: {
8686
id: process.env.HMD_SAML_ATTRIBUTE_ID,
8787
username: process.env.HMD_SAML_ATTRIBUTE_USERNAME,

lib/config/utils.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,10 @@ exports.toBooleanConfig = function toBooleanConfig (configValue) {
66
}
77
return configValue
88
}
9+
10+
exports.toArrayConfig = function toArrayConfig (configValue, separator = ',', fallback) {
11+
if (configValue && typeof configValue === 'string') {
12+
return (configValue.split(separator).map(arrayItem => arrayItem.trim()))
13+
}
14+
return fallback
15+
}

0 commit comments

Comments
 (0)