azure-graph 产生 Request_BadRequest:请求中的无效域名 url

azure-graph produces Request_BadRequest: Invalid domain name in the request url

我正在尝试使用 Node.js 通过 ID 检索用户对象。这是我的代码:

const MsRest = require('ms-rest-azure');    
const credentials = await MsRest.loginWithServicePrincipalSecret(keys.appId, keys.pass, keys.tenantId, { tokenAudience: 'graph' });
const GraphkManagementClient = require('azure-graph');
const client = new GraphkManagementClient(credentials, subscriptionId);
return client.users.get(principalID);

但是 client.users.get(principalID) 产生了一个请求 returns:

Request_BadRequest: Invalid domain name in the request url

这是它生成的 url(使用真实值而不是 {tenant id} 和 {user id}):

https://graph.windows.net/{tenant id}/users/{user id}?api-version=1.6

对于azure-graph sdk,好像应该是GraphkManagementClient(credentials,'<tenantId>').

你可以参考这个sample:

const AzureGraphClient = require('azure-graph');
const MsRestAzure = require('ms-rest-azure');

const options = {
  tokenAudience: 'graph',
  domain: '<tenantId>' 
};

MsRestAzure.loginWithServicePrincipalSecret(
  'clientId or appId',
  'secret or password',
  'domain or tenantId',
  options, 
  (err, credentials) => {
  if (err) throw err;

  let graphClient = AzureGraphClient(credentials, '<tenantId>');

  // ..use the client instance to manage service resources.
});

也提到here:

var graphRbacManagementClient = require('azure-graph');
var client = new graphRbacManagementClient(credentials, tenantId);