ldap-authentication 2.3.3 → 3.0.2
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.
- package/.github/workflows/integration-test.yml +1 -1
- package/.vscode/launch.json +15 -0
- package/README.md +29 -5
- package/index.js +13 -2
- package/package.json +3 -3
- package/test/test.js +0 -1
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
// Use IntelliSense to learn about possible attributes.
|
|
3
|
+
// Hover to view descriptions of existing attributes.
|
|
4
|
+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
5
|
+
"version": "0.2.0",
|
|
6
|
+
"configurations": [
|
|
7
|
+
{
|
|
8
|
+
"type": "node",
|
|
9
|
+
"request": "launch",
|
|
10
|
+
"name": "Debug Example",
|
|
11
|
+
"skipFiles": ["<node_internals>/**"],
|
|
12
|
+
"program": "${workspaceFolder}/example/index.js"
|
|
13
|
+
}
|
|
14
|
+
]
|
|
15
|
+
}
|
package/README.md
CHANGED
|
@@ -181,19 +181,43 @@ auth()
|
|
|
181
181
|
|
|
182
182
|
The user object if `authenticate()` is success.
|
|
183
183
|
|
|
184
|
-
The user object has a `raw` field that has the raw data from the LDAP/AD server. It can be used to access buffer objects (profile pics for example).
|
|
185
|
-
Buffer data can now be accessed by `user.raw.profilePhoto`, etc, instead of `user.profilePhoto`.
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
184
|
+
In version 2, The user object has a `raw` field that has the raw data from the LDAP/AD server. It can be used to access buffer objects (profile pics for example).
|
|
189
185
|
|
|
186
|
+
Buffer data can now be accessed by `user.raw.profilePhoto`, etc, instead of `user.profilePhoto`.
|
|
190
187
|
|
|
188
|
+
In version 3, the `raw` field is no longer used. Instead, append `;binary` to the attributes you
|
|
189
|
+
want to get back as buffer. Check the following example on how to get a user's profile photo:
|
|
191
190
|
|
|
191
|
+
```javascript
|
|
192
|
+
export async function verifyLogin(email: string, password: string) {
|
|
192
193
|
|
|
194
|
+
const options = {
|
|
195
|
+
//...other config options
|
|
196
|
+
userPassword: password,
|
|
197
|
+
username: email,
|
|
198
|
+
attributes: ['thumbnailPhoto;binary', 'givenName', 'sn', 'sAMAccountName', 'userPrincipalName', 'memberOf' ]
|
|
199
|
+
};
|
|
193
200
|
|
|
201
|
+
try {
|
|
202
|
+
const ldapUser = await authenticate(options);
|
|
194
203
|
|
|
204
|
+
if (!ldapUser) {
|
|
205
|
+
return { error: "user not found" };
|
|
206
|
+
}
|
|
195
207
|
|
|
208
|
+
// accessing the image
|
|
209
|
+
const profilePhoto = ldapUser['thumbnailPhoto;binary'];
|
|
196
210
|
|
|
211
|
+
/* using the image
|
|
212
|
+
<img src={`data:image/*;base64,${user.profilePhoto}`} />
|
|
213
|
+
*/
|
|
214
|
+
return { user: ldapUser };
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
```
|
|
197
218
|
|
|
219
|
+
## Supported Node Versions
|
|
198
220
|
|
|
221
|
+
Version 2 supports Node version 12, 14, 15, 16, 17 and 18.
|
|
199
222
|
|
|
223
|
+
Version 3 supports Node version 15, 16, 17 and 18
|
package/index.js
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
const assert = require('assert')
|
|
2
2
|
const ldap = require('ldapjs')
|
|
3
3
|
|
|
4
|
+
// convert a SearchResultEntry object in ldapjs 3.0
|
|
5
|
+
// to a user object to maintain backward compatibility
|
|
6
|
+
|
|
7
|
+
function _searchResultToUser(pojo) {
|
|
8
|
+
assert(pojo.type == 'SearchResultEntry')
|
|
9
|
+
let user = { dn: pojo.objectName }
|
|
10
|
+
pojo.attributes.forEach((attribute) => {
|
|
11
|
+
user[attribute.type] =
|
|
12
|
+
attribute.values.length == 1 ? attribute.values[0] : attribute.values
|
|
13
|
+
})
|
|
14
|
+
return user
|
|
15
|
+
}
|
|
4
16
|
// bind and return the ldap client
|
|
5
17
|
function _ldapBind(dn, password, starttls, ldapOpts) {
|
|
6
18
|
return new Promise(function (resolve, reject) {
|
|
@@ -86,8 +98,7 @@ async function _searchUser(
|
|
|
86
98
|
return
|
|
87
99
|
}
|
|
88
100
|
res.on('searchEntry', function (entry) {
|
|
89
|
-
user = entry.
|
|
90
|
-
user.raw = entry.raw
|
|
101
|
+
user = _searchResultToUser(entry.pojo)
|
|
91
102
|
})
|
|
92
103
|
res.on('searchReference', function (referral) {
|
|
93
104
|
// TODO: we don't support reference yet
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ldap-authentication",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.2",
|
|
4
4
|
"description": "A simple async nodejs library for LDAP user authentication",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "./index.d.ts",
|
|
@@ -36,9 +36,9 @@
|
|
|
36
36
|
},
|
|
37
37
|
"homepage": "https://github.com/shaozi/ldap-authentication#readme",
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"ldapjs": "^
|
|
39
|
+
"ldapjs": "^3.0.1"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"jasmine": "^4.
|
|
42
|
+
"jasmine": "^4.6.0"
|
|
43
43
|
}
|
|
44
44
|
}
|
package/test/test.js
CHANGED
|
@@ -72,7 +72,6 @@ describe('ldap-authentication test', () => {
|
|
|
72
72
|
let user = await authenticate(options)
|
|
73
73
|
expect(user).toBeTruthy()
|
|
74
74
|
expect(user.uid).toEqual('einstein')
|
|
75
|
-
expect(user.raw).toBeTruthy()
|
|
76
75
|
})
|
|
77
76
|
it('Use an regular user to authenticate iteself and return attributes', async () => {
|
|
78
77
|
let options = {
|