node.js - 我的函数在 Active Directory 中为节点返回未定义
问题描述
有谁知道如何在以下函数中返回身份验证?它目前正在返回 null 。我尝试使用异步等待和其他许多东西,但仍然很难返回任何东西。谢谢您的帮助!
var ActiveDirectory = require('activedirectory');
var config = { url: myurl,
baseDN: 'CN=Users,DC=usdtl,DC=com',
username: my-username,
password: my-pass }
var ad = new ActiveDirectory(config);
ad.authenticate(userPrincipalName, password, (err, auth) => {
if (err) {
console.log('ERROR: '+JSON.stringify(err));
return auth;
}
if (auth) {
console.log(auth)
return auth
}
})
解决方案
这太棒了。我从未听说过异步。有没有其他方法可以从以下类返回回调结果?因为我一直在尝试使异步工作,但它不起作用。我在另一个地方调用这个类函数。
import { Injectable } from '@nestjs/common';
@Injectable()
export class AuthService {
async authenticateUser(username, password) {
let isAuthenticated: boolean = false
var ActiveDirectory = require('activedirectory');
var config = { url: 'my_url',
baseDN: 'CN=Users,DC=usdtl,DC=com' }
var ad = new ActiveDirectory(config);
ad.authenticate(username, password, function(err, auth) {
if (err) {
console.log('ERROR: '+JSON.stringify(err));
return err;
}
if (auth) {
console.log('Authenticated!');
isAuthenticated = auth
}
});
}
}
推荐阅读
- azure-devops - 在 portal.azure.com 项目中显示 dev.azure.com 项目
- abap - SAP Smartforms 动态更改某些项目的位置
- python - 2 路 Socket 通过蓝牙进行通信
- javascript - 如果鼠标在移动,则生成一个 scipt 以每 n 秒检查一次
- c++ - C++ 临时优步应用程序
- php - 使用 C9。无法使用 PHP 连接到 MySQL 数据库
- python - 使用 spyder 时如何获取函数的“帮助”?
- android - 如何在模拟器中部署离子应用程序时解决错误
- docker - 我们可以在 Docker 文件 COPY 命令中使用本地环境变量吗?
- entity-framework - 使用 fluent API 设置模型属性的显示名称