Skip to content

Commit 7475872

Browse files
authored
Merge pull request #651 from alecdwm/ldap-auth-searchattributes-fix
Parse env var `HMD_LDAP_SEARCHATTRIBUTES` as a comma-separated array
2 parents e9e7a8e + 5e5a021 commit 7475872

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
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_TLS_CA | `server-cert.pem, root.pem` | Root CA for LDAP TLS in PEM format (use comma to separate) |
174174
| HMD_LDAP_PROVIDERNAME | `My institution` | Optional name to be displayed at login form indicating the LDAP provider |
175175
| HMD_SAML_IDPSSOURL | `https://idp.example.com/sso` | authentication endpoint of IdP. for details, see [guide](docs/guides/auth.md#saml-onelogin). |

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
"tlsOptions": {
7575
"changeme": "See https://nodejs.org/api/tls.html#tls_tls_connect_options_callback"
7676
}

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
tlsca: process.env.HMD_LDAP_TLS_CA
7575
},
7676
saml: {
@@ -79,8 +79,8 @@ module.exports = {
7979
issuer: process.env.HMD_SAML_ISSUER,
8080
identifierFormat: process.env.HMD_SAML_IDENTIFIERFORMAT,
8181
groupAttribute: process.env.HMD_SAML_GROUPATTRIBUTE,
82-
externalGroups: process.env.HMD_SAML_EXTERNALGROUPS ? process.env.HMD_SAML_EXTERNALGROUPS.split('|') : [],
83-
requiredGroups: process.env.HMD_SAML_REQUIREDGROUPS ? process.env.HMD_SAML_REQUIREDGROUPS.split('|') : [],
82+
externalGroups: toArrayConfig(process.env.HMD_SAML_EXTERNALGROUPS, '|', []),
83+
requiredGroups: toArrayConfig(process.env.HMD_SAML_REQUIREDGROUPS, '|', []),
8484
attribute: {
8585
id: process.env.HMD_SAML_ATTRIBUTE_ID,
8686
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)