HI,
I want to Authenticate service management rest api using the Active Directory. Can you please mention the Steps?
I have tried to authenticate using node.js module as follows it shows as the authorization error. Please let me know anything i have missed in the following
var adal=require('adal-node');
var AuthenticationContext= adal.AuthenticationContext;
var tenantID="57d091d4-4dae-41e2-9a2b-0bc0644688df";
var clientID="fd6bec69-7e92-49a0-85b1-affb20a9d7af";
var resource="https://management.azure.com/";
var authURL="https://login.windows.net/" + tenantID;
var secret="E7ZaMHCNqcO4qHzzJm6RI4X7kS7CTVUjNJ/13eCltvI=";
var context=new AuthenticationContext(authURL);
var rest=require('restler');
context.acquireTokenWithClientCredentials(resource,clientID, secret, function(err,tokenResponse) {
console.log('err:'+err);
console.log('tokenResponse:'+JSON.stringify(tokenResponse,null,2));
authHeader = tokenResponse['accessToken'];
requestURL="https://management.azure.com/subscriptions/84da9df4-cf54-4040-9743-9fbbda1903f0?api-version=2015-01-01";
rest.get(requestURL, {accessToken:authHeader}).on('complete',function(result)
{
console.log('result:'+JSON.stringify(result,null,2));
});
});
Response:-
tokenResponse:{
"expiresIn": 3599,
"tokenType": "Bearer",
"expiresOn": "2015-08-13T06:03:39.986Z",
"resource": "https://management.azure.com/",
"accessToken": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6Ik1uQ19WWmNBVGZNNXBPWWlKSE1iYTlnb0VLWSIsImtpZCI6Ik1uQ19WWmNBVGZNNXBPWWlKSE1iYTlnb0VLWSJ9.eyJhdWQiOiJodHRwczovL21hbmFnZW1lbnQuYXp1cmUuY29tLyIsImlzcyI6Imh0dHBzOi8vc3RzLndpbmRvd3MubmV0LzU3ZDA5MWQ0LTRkYWUtNDFlMi05YTJiLTBiYzA2NDQ2ODhkZi8iLCJpY
XQiOjE0NDA2NzY5OTgsIm5iZiI6MTQ0MDY3Njk5OCwiZXhwIjoxNDQwNjgwODk4LCJ2ZXIiOiIxLjAiLCJ0aWQiOiI1N2QwOTFkNC00ZGFlLTQxZTItOWEyYi0wYmMwNjQ0Njg4ZGYiLCJvaWQiOiIyMTQ4MTBmNy02OGRiLTRlZDEtOTdjOC0wZGJlMTNkZjI1NzAiLCJzdWIiOiIyMTQ4MTBmNy02OGRiLTRlZDEtOTdjOC0wZGJlMTNkZjI1NzAiLCJpZHAiOiJodHRwczovL3N0cy53aW5kb3dzLm5ld
C81N2QwOTFkNC00ZGFlLTQxZTItOWEyYi0wYmMwNjQ0Njg4ZGYvIiwiYXBwaWQiOiJmZDZiZWM2OS03ZTkyLTQ5YTAtODViMS1hZmZiMjBhOWQ3YWYiLCJhcHBpZGFjciI6IjEifQ.upG8bCJKLz0pkzkiUoBGtiRBlIFLVf7DImDRq3KfbL24g7CoORV3EExl2Pio-AskofIUuP1hEFgkNve75vEv_jNIeQKfbDSeJzhM9phUj2mRR40TnUmN3mgPv72hYzGtWPH7Btlbeq93gsNjPCmLRqwZd6pdRzLOuH
P4RC8TABw_9tuqwZQB_ShzX6-0kIGno48kFqZWk61HrSjkQEV9h9quqYbafn1HkHr4i_huhQx4OxN8w8y8ab0xF0VRDkXIKysDdCHc9uaXj0eaGMc8SqZ6uDUaN6iWkpV4MR96jjbTgK5ll6TkLL3TAfuyNP_Q9fxI4ef0JwlMm10SF1ccZQ",
"isMRRT": true,
"_clientId": "fd6bec69-7e92-49a0-85b1-affb20a9d7af",
"_authority": "https://login.windows.net/57d091d4-4dae-41e2-9a2b-0bc0644688df"
}
result:{
"error": {
"code": "AuthorizationFailed",
"message": "The client '214810f7-68db-4ed1-97c8-0dbe13df2570' with object id '214810f7-68db-4ed1-97c8-0dbe13df2570' does not have authorization to perform action 'Microsoft.Resources/subscriptions/read' over scope '/subscriptions/84da9df4-cf54-4040-9743-9fbbda1903f0'."
}
}