Skip to content

Commit 612b2d1

Browse files
Add setting ldap.usernameField
This determines which ldap field is used as the username on HackMD. By default, the "id" is used as username, too. The id is taken from the fields `uidNumber`, `uid` or `sAMAccountName`. To give the user more flexibility, they can now choose the field used for the username instead.
1 parent 1b7d621 commit 612b2d1

File tree

5 files changed

+11
-1
lines changed

5 files changed

+11
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
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 | no example | LDAP attributes to search with |
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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: 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

Lines changed: 7 additions & 1 deletion
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)