我有一个非常基本的天蓝色函数:
#r "Newtonsoft.Json"
using System.Net;
using System.Net.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
public static async Task<IActionResult> Run(HttpRequest req, string authToken, ILogger log)
{
string msgId = req.Query["messageId"];
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(requestBody);
msgId = msgId ?? data?.messageId;
if (string.IsNullOrEmpty(msgId))
return new BadRequestObjectResult("Please pass a messageId on the query string or in the request body");
// access me via graph
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Add("Authorization", "Bearer " + authToken);
var response = await client.GetAsync("https://graph.microsoft.com/v1.0/users/*****/mailFolders/inbox/messages/" + msgId);
string retResp = await response.Content.ReadAsStringAsync();
log.LogInformation(retResp);
}
return new OkObjectResult(msgId);
}
但是我总是从Microsoft图形中得到以下答案:
{
"error": {
"code": "Authorization_RequestDenied",
"message": "Insufficient privileges to complete the operation.",
"innerError": {
"request-id": "24a1e799-2f9f-4452-8d46-20d4e3db160d",
"date": "2019-01-02T07:39:15"
}
}
}
是的:管理员同意,我什至尝试将所有可用权限授予该应用并同意,但我仍然收到相同的消息。您是否知道我如何验证令牌或获取更多信息?