【发布时间】:2019-09-03 00:42:40
【问题描述】:
我不熟悉使用 adal-node npm 包。
在它提到的例子中:
var resource = '00000002-0000-0000-c000-000000000000';
这个 ID 来自哪里?从我的用例来看,我只想批量更新我的 AD 中的用户。
【问题讨论】:
-
@TonyJu,完成。谢谢!
标签: azure active-directory adal
我不熟悉使用 adal-node npm 包。
在它提到的例子中:
var resource = '00000002-0000-0000-c000-000000000000';
这个 ID 来自哪里?从我的用例来看,我只想批量更新我的 AD 中的用户。
【问题讨论】:
标签: azure active-directory adal
资源的值是标识令牌有效的资源的 URI。
如果你想在你的 AD 中使用 Microsoft Graph API 到 update your users,你应该使用 https://graph.microsoft.com 作为资源。
您可以参考这个sample。您将获得图形客户端来更新用户。
const AuthenticationContext = require('adal-node').AuthenticationContext;
const MicrosoftGraph = require("@microsoft/microsoft-graph-client");
const authorityHostUrl = 'https://login.windows.net';
const tenantName = ''; //azure active directory tenant name. ie: name.onmicrosoft.com
const authorityUrl = authorityHostUrl + '/' + tenantName;
const applicationId = ''; //application id for registered app
const clientSecret = ''; //azure active directory registered app secret
const resource = "https://graph.microsoft.com"; //URI of resource where token is valid
const context = new AuthenticationContext(authorityUrl);
context.acquireTokenWithClientCredentials(
resource,
applicationId,
clientSecret,
function(err, tokenResponse) {
if (err) {
console.log('well that didn\'t work: ' + err.stack);
} else {
let client = MicrosoftGraph.Client.init({
defaultVersion: 'v1.0',
authProvider: (done) => {
done(null, tokenResponse.accessToken);
},
});
client
.api('/users')
.get((err, result) => {
console.log(result, err);
});
}
});
【讨论】:
资源是一种服务/应用程序/api,您要求 Azure AD 等身份提供程序为其颁发令牌。您也可以将 AppId(客户端 ID)作为资源
'00000002-0000-0000-c000-000000000000' 是 Azure AD Graph API (https://graph.windows.net/) 的客户端 ID。此 Api 已被弃用,取而代之的是 Microsoft Graph "https://graph.microsoft.com",这是您应该使用的资源。
【讨论】: