0

在 GCP 云功能中使用 nodejs 连接到 LDAP 时出现以下错误

错误:TypeError:Object.createClient 所需的选项(对象)

索引.js

exports.helloWorld = (event, context) => {
  const gcsEvent = event;
  var username = ***;
  var password = ***;
  console.log(`hello world`);
  var ldap = require('ldapjs');
  var client =ldap.createClient(username, password)({
   url: 'LDAP://...'
    }) 

client.bind(username, password,  function(error){
   if(error){ 
      console.log("error");
        } 
    else{ 
    console.log("Connected to ldap");
   } 
})
}

包.json

{
  "name": "sample-http",
  "version": "0.0.1",
 "author": "sang",
  "description": "LDAP Binding for node.js",
   "dependencies": {
    "ldapjs": "^0.7.1"
  }
  }
4

1 回答 1

0

var client =ldap.createClient(username, password)({ url: 'LDAP://...' })

不应该是这样吗

var client =ldap.createClient({ url: 'LDAP://...' })

createClient提供用户名和密码时,将 Object 作为参数。

参考npmdoc

在此处输入图像描述

于 2021-09-06T16:54:38.880 回答