0

我正在尝试使用 nodejs 从 azure 活动目录中查找用户。我正在使用Node-ActiveDirectory来完成这项任务。首先,我尝试按照上面链接中的示例连接到 Azure 活动目录。我使用过的示例代码如下。

var ActiveDirectory = require('activedirectory');
var config = { url: 'ldap://myhotmail.onmicrosoft.com',
    baseDN: 'dc=myhotmail,dc=onmicrosoft,dc=com',
    username: 'roledene@myhotmail.onmicrosoft.com',
    password: 'myPassword'
}
var ad = new ActiveDirectory(config);

var username = 'roledene@myhotmail.onmicrosoft.com';
var password = 'myPassword';

ad.authenticate(username, password, function(err, auth) {
    if (err) {
        console.log('ERROR: '+JSON.stringify(err));
        return;
    }

    if (auth) {
        console.log('Authenticated!');
    }
    else {
        console.log('Authentication failed!');
    }
});

但它给出了以下错误。这段代码有什么问题?

ERROR: {"code":"ENOTFOUND","errno":"ENOTFOUND","syscall":"getaddrinfo","hostname":"myhotmail.onmicrosoft.com","host":"myhotmail.onmicrosoft.com","port":389}
4

1 回答 1

1

正如@juunas 评论,我尝试使用 Microsoft Graph 客户端。

我将引用设置 ms 图形客户端的初始步骤,此处确切提到了更多详细信息

安装 ms 图形客户端

npm install @microsoft/microsoft-graph-client

从 MS graph api 连接和查询

const MicrosoftGraph = require("@microsoft/microsoft-graph-client");

var client = MicrosoftGraph.Client.init({
    authProvider: (iss, sub, profile, accessToken, refreshToken, done) => {
        done(null, {
            profile,
            accessToken,
            refreshToken
        }); //first parameter takes an error if you can't get an access token
    }
});

// Example calling /me with no parameters
client
    .api('/me')
    .get((err, res) => {
        console.log(res); // prints info about authenticated user
    });
于 2018-04-11T12:45:06.747 回答