Skip to content

Commit

Permalink
Merge pull request #650 from LukasKalbertodt/ldap-username-field
Browse files Browse the repository at this point in the history
Add setting `ldap.usernameField`
  • Loading branch information
SISheogorath committed Dec 12, 2017
2 parents b840c3f + 17e3b8b commit 454e0f8
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -170,6 +170,7 @@ There are some configs you need to change in the files below
| HMD_LDAP_SEARCHBASE | `o=users,dc=example,dc=com` | LDAP directory to begin search from |
| HMD_LDAP_SEARCHFILTER | `(uid={{username}})` | LDAP filter to search with |
| HMD_LDAP_SEARCHATTRIBUTES | `displayName, mail` | LDAP attributes to search with (use comma to separate) |
| HMD_LDAP_USERNAMEFIELD | `uid` | The LDAP field which is used as the username on HackMD |
| HMD_LDAP_TLS_CA | `server-cert.pem, root.pem` | Root CA for LDAP TLS in PEM format (use comma to separate) |
| HMD_LDAP_PROVIDERNAME | `My institution` | Optional name to be displayed at login form indicating the LDAP provider |
| HMD_SAML_IDPSSOURL | `https://idp.example.com/sso` | authentication endpoint of IdP. for details, see [guide](docs/guides/auth.md#saml-onelogin). |
Expand Down
1 change: 1 addition & 0 deletions config.json.example
Expand Up @@ -71,6 +71,7 @@
"searchBase": "change this",
"searchFilter": "change this",
"searchAttributes": ["change this"],
"usernameField": "change this e.g. uid"
"tlsOptions": {
"changeme": "See https://nodejs.org/api/tls.html#tls_tls_connect_options_callback"
}
Expand Down
1 change: 1 addition & 0 deletions lib/config/default.js
Expand Up @@ -96,6 +96,7 @@ module.exports = {
searchBase: undefined,
searchFilter: undefined,
searchAttributes: undefined,
usernameField: undefined,
tlsca: undefined
},
saml: {
Expand Down
1 change: 1 addition & 0 deletions lib/config/environment.js
Expand Up @@ -71,6 +71,7 @@ module.exports = {
searchBase: process.env.HMD_LDAP_SEARCHBASE,
searchFilter: process.env.HMD_LDAP_SEARCHFILTER,
searchAttributes: toArrayConfig(process.env.HMD_LDAP_SEARCHATTRIBUTES),
usernameField: process.env.HMD_LDAP_USERNAMEFIELD,
tlsca: process.env.HMD_LDAP_TLS_CA
},
saml: {
Expand Down
8 changes: 7 additions & 1 deletion lib/web/auth/ldap/index.js
Expand Up @@ -24,9 +24,15 @@ passport.use(new LDAPStrategy({
}
}, function (user, done) {
var uuid = user.uidNumber || user.uid || user.sAMAccountName
var username = uuid

if (config.ldap.usernameField && user[config.ldap.usernameField]) {
username = user[config.ldap.usernameField]
}

var profile = {
id: 'LDAP-' + uuid,
username: uuid,
username: username,
displayName: user.displayName,
emails: user.mail ? [user.mail] : [],
avatarUrl: null,
Expand Down

0 comments on commit 454e0f8

Please sign in to comment.