I've registered a Native app in Azure AD and given all delegate permission to access graph API.I am trying to test this solution with a console solution (exe) with following code which uses client id and secret
private static async void AcquireTokenAsync() {
AuthenticationContext context = new AuthenticationContext("https://login.windows.net/xxxxxx-xxxx-485b-a40f-xxxxxxxx/oauth2/token", true);
var result = await context.AcquireTokenAsync("https://graph.microsoft.com",
new ClientCredential("xxxxxx-32cf-xxxx-8888-555555555555",
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxV89cWfH0w="
)
);
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", "Bearer " + result.AccessToken);
HttpResponseMessage response = await client.GetAsync("https://graph.microsoft.com/v1.0/users/");
string retResp = await response.Content.ReadAsStringAsync();
string token = result.AccessToken;
Console.WriteLine(token + "\n" + restResp);
}
There is no problem in retrieving token.I am getting the accesstoken but with following error /response in graph api call with the token
{
"error": {
"code": "Authorization_RequestDenied",
"message": "Insufficient privileges to complete the operation.",
"innerError": {
"request-id": "cb7aaaa9-d9a0-485a-7777-b5bfe68ba771",
"date": "2017-07-22T11:01:49"
}
}
}
Please suggest what is going wrong