【问题标题】:ADAL: Where do I view the resource ID's?ADAL:我在哪里查看资源 ID?
【发布时间】:2019-09-03 00:42:40
【问题描述】:

我不熟悉使用 adal-node npm 包。

在它提到的例子中:

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

这个 ID 来自哪里?从我的用例来看,我只想批量更新我的 AD 中的用户。

【问题讨论】:

  • @TonyJu,完成。谢谢!

标签: azure active-directory adal


【解决方案1】:

资源的值是标识令牌有效的资源的 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);
      });
    }
});

【讨论】:

  • 我选择 Kalyan 的答案作为接受的答案,因为他还解释了我的问题中的 URI 是什么,这对我来说是问题的一部分。它也很简洁,准确地解决了我的问题。您包含的代码是我已经拥有并理解的。我主要需要帮助来理解资源参数及其可能的值。
【解决方案2】:

资源是一种服务/应用程序/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",这是您应该使用的资源。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-10
    • 1970-01-01
    相关资源
    最近更新 更多