Skip to content

Commit 454e0f8

Browse files
authored
Merge pull request #650 from LukasKalbertodt/ldap-username-field
Add setting `ldap.usernameField`
2 parents b840c3f + 17e3b8b commit 454e0f8

File tree

5 files changed

+11
-1
lines changed

5 files changed

+11
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ There are some configs you need to change in the files below
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 |
172172
| HMD_LDAP_SEARCHATTRIBUTES | `displayName, mail` | LDAP attributes to search with (use comma to separate) |
173+
| HMD_LDAP_USERNAMEFIELD | `uid` | The LDAP field which is used as the username on HackMD |
173174
| HMD_LDAP_TLS_CA | `server-cert.pem, root.pem` | Root CA for LDAP TLS in PEM format (use comma to separate) |
174175
| HMD_LDAP_PROVIDERNAME | `My institution` | Optional name to be displayed at login form indicating the LDAP provider |
175176
| 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

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
"searchBase": "change this",
7272
"searchFilter": "change this",
7373
"searchAttributes": ["change this"],
74+
"usernameField": "change this e.g. uid"
7475
"tlsOptions": {
7576
"changeme": "See https://nodejs.org/api/tls.html#tls_tls_connect_options_callback"
7677
}

lib/config/default.js

+1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ module.exports = {
9696
searchBase: undefined,
9797
searchFilter: undefined,
9898
searchAttributes: undefined,
99+
usernameField: undefined,
99100
tlsca: undefined
100101
},
101102
saml: {

lib/config/environment.js

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ module.exports = {
7171
searchBase: process.env.HMD_LDAP_SEARCHBASE,
7272
searchFilter: process.env.HMD_LDAP_SEARCHFILTER,
7373
searchAttributes: toArrayConfig(process.env.HMD_LDAP_SEARCHATTRIBUTES),
74+
usernameField: process.env.HMD_LDAP_USERNAMEFIELD,
7475
tlsca: process.env.HMD_LDAP_TLS_CA
7576
},
7677
saml: {

lib/web/auth/ldap/index.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,15 @@ passport.use(new LDAPStrategy({
2424
}
2525
}, function (user, done) {
2626
var uuid = user.uidNumber || user.uid || user.sAMAccountName
27+
var username = uuid
28+
29+
if (config.ldap.usernameField && user[config.ldap.usernameField]) {
30+
username = user[config.ldap.usernameField]
31+
}
32+
2733
var profile = {
2834
id: 'LDAP-' + uuid,
29-
username: uuid,
35+
username: username,
3036
displayName: user.displayName,
3137
emails: user.mail ? [user.mail] : [],
3238
avatarUrl: null,

0 commit comments

Comments
 (0)