[英]synchronous calls (await ad.authenticate)
How can I make an asynchronous call?如何进行异步调用? i tried with this code:我试过这段代码:
abc = await ad.authenticate(username, password, function(err, auth) {
if(err){
console.log('ERROR: '+JSON.stringify(err));
fail_found = err.name;
return;
}
if(auth){
console.log('Authenticated!');
}else{
console.log('Authenticated Faliled');
fail_found = 'No Authenticated ';
}
});
}
console.log("Fails?: ",fail_found);
NPM: https://www.npmjs.com/package/activedirectory2 Github: https://github.com/jsumners/node-activedirectory/ NPM: https://www.npmjs.com/package/activedirectory2 Github: https://github.com/jsumners/node-activedirectory/
Thx !谢谢 !
You can try With a Promise :您可以尝试使用Promise :
let myPromise = new Promise((resolve, reject) => {
ad.authenticate(username, password, function(err, auth) {
if(err){
console.log('ERROR: '+JSON.stringify(err));
fail_found = err.name;
reject(fail_found)
return;
}
if(auth){
console.log('Authenticated!');
resolve('Authenticated!');
}else{
console.log('Authenticated Faliled');
fail_found = 'No Authenticated ';
reject(fail_found)
}
});
}
console.log("Fails?: ",fail_found);
reject(fail_found)
});
myPromise.then((successMessage) => {
console.log(successMessage);
}).catch(err => console.log(err))
Or in the first part of documentation show a promiseWrapper :或者在文档的第一部分显示一个promiseWrapper :
const AD = require('activedirectory2').promiseWrapper;
const config = { url: 'ldap://dc.domain.com',
baseDN: 'dc=domain,dc=com',
username: 'username@domain.com',
password: 'password' }
const ad = new AD(config);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.