ADAL:我在哪里查看资源ID?

时间:2019-04-12 09:22:25

标签: azure active-directory adal

我刚开始使用adal-node npm软件包。

在示例中提到:

var resource = '00000002-0000-0000-c000-000000000000';

此ID来自何处?从用例来看,我只想在AD中批量更新用户。

2 个答案:

答案 0 :(得分:2)

资源的值是一个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);
      });
    }
});

答案 1 :(得分:2)

资源是一项服务/应用程序/ API,您要求资源(例如Azure AD)为其提供令牌。您也可以将AppId(客户端ID)也用作资源

'00000002-0000-0000-c000-000000000000'是Azure AD Graph API(https://graph.windows.net/)的客户端ID。我们不建议使用此Api,而推荐使用Microsoft Graphhttps://graph.microsoft.com”。

相关问题