Alon
Alon

Reputation: 11905

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

I am trying to retrieve the user object by ID using Node.js. Here is my code:

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);

But client.users.get(principalID) produces a request that returns:

Request_BadRequest: Invalid domain name in the request url

This is the url it produces (with the true values instead of {tenant id} and {user id}):

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

Upvotes: 0

Views: 1966

Answers (1)

Joy Wang
Joy Wang

Reputation: 42063

For azure-graph sdk, it seems should be GraphkManagementClient(credentials,'<tenantId>').

You could refer to this 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.
});

It is also mentioned here:

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

Upvotes: 2

Related Questions