ldap-authentication 3.3.2 → 3.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +16 -8
  2. package/package.json +1 -2
package/index.js CHANGED
@@ -98,6 +98,14 @@ async function _searchUser(
98
98
  user = searchEntries[0]
99
99
  }
100
100
 
101
+ // when attribute endwith ;binary, ldapts returns Buffer, we convert them into base64 string
102
+ if (user != null && attributes != null) {
103
+ for (let attr of attributes) {
104
+ if (attr.endsWith(';binary') && Buffer.isBuffer(user[attr])) {
105
+ user[attr] = user[attr].toString('base64')
106
+ }
107
+ }
108
+ }
101
109
  return user
102
110
  }
103
111
 
@@ -173,10 +181,10 @@ async function authenticateWithAdmin(
173
181
  ldapOpts
174
182
  )
175
183
  } catch (error) {
176
- if (ldapAdminClient.isConnected) {
184
+ if (ldapAdminClient && ldapAdminClient.isConnected) {
177
185
  await ldapAdminClient.unbind()
178
186
  }
179
- throw { admin: error }
187
+ throw new LdapAuthenticationError(error)
180
188
  }
181
189
  let user = await _searchUser(
182
190
  ldapAdminClient,
@@ -200,10 +208,10 @@ async function authenticateWithAdmin(
200
208
  try {
201
209
  ldapUserClient = await _ldapBind(userDn, userPassword, starttls, ldapOpts)
202
210
  } catch (error) {
203
- if (ldapUserClient.isConnected) {
211
+ if (ldapUserClient && ldapUserClient.isConnected) {
204
212
  await ldapUserClient.unbind()
205
213
  }
206
- throw error
214
+ throw new LdapAuthenticationError(error)
207
215
  }
208
216
  if (groupsSearchBase && groupClass && groupMemberAttribute) {
209
217
  let groups = await _searchUserGroups(
@@ -239,10 +247,10 @@ async function authenticateWithUser(
239
247
  try {
240
248
  ldapUserClient = await _ldapBind(userDn, userPassword, starttls, ldapOpts)
241
249
  } catch (error) {
242
- if (ldapUserClient.isConnected) {
250
+ if (ldapUserClient && ldapUserClient.isConnected) {
243
251
  await ldapUserClient.unbind()
244
252
  }
245
- throw error
253
+ throw new LdapAuthenticationError(error)
246
254
  }
247
255
  if (!usernameAttribute || !userSearchBase) {
248
256
  // if usernameAttribute is not provided, no user detail is needed.
@@ -304,10 +312,10 @@ async function verifyUserExists(
304
312
  ldapOpts
305
313
  )
306
314
  } catch (error) {
307
- if (ldapAdminClient.isConnected) {
315
+ if (ldapAdminClient && ldapAdminClient.isConnected) {
308
316
  await ldapAdminClient.unbind()
309
317
  }
310
- throw { admin: error }
318
+ throw new LdapAuthenticationError(error)
311
319
  }
312
320
  let user = await _searchUser(
313
321
  ldapAdminClient,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ldap-authentication",
3
- "version": "3.3.2",
3
+ "version": "3.3.4",
4
4
  "description": "A simple async nodejs library for LDAP user authentication",
5
5
  "main": "index.js",
6
6
  "types": "./index.d.ts",
@@ -15,7 +15,6 @@
15
15
  "ldap",
16
16
  "authenticate",
17
17
  "authentication",
18
- "ldapjs",
19
18
  "ldapts",
20
19
  "security",
21
20
  "simple",