我正在尝试使用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)
产生的请求返回:
Request_BadRequest:请求网址中的域名无效
这是它产生的网址(使用真实值而不是{tenant id}和{user id}):
https://graph.windows.net/ {租户ID} /用户/ {用户ID}?api-version = 1.6
答案 0 :(得分:2)
对于天蓝色图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);