Azure active directory 从守护程序应用程序访问租户Microsoft Graph

Azure active directory 从守护程序应用程序访问租户Microsoft Graph,azure-active-directory,microsoft-graph-api,azure-ad-graph-api,Azure Active Directory,Microsoft Graph Api,Azure Ad Graph Api,我正在开发一个与Microsoft 365 Office Planner交互的守护程序应用程序,以操作Microsoft Graph任务。当我调用Microsoft Graph API来获取与我的租户相关的任务时,我得到了一个未经授权的请求异常 我已在Azure Active Directory中注册了我的应用程序,并授予它使用Microsoft Graph的权限 我根据以下流程请求访问令牌: 我能够从Azure Active Directory v2.0端点获取令牌。 请求代码如下所示:

我正在开发一个与Microsoft 365 Office Planner交互的守护程序应用程序,以操作Microsoft Graph任务。当我调用Microsoft Graph API来获取与我的租户相关的任务时,我得到了一个未经授权的请求异常

我已在Azure Active Directory中注册了我的应用程序,并授予它使用Microsoft Graph的权限

我根据以下流程请求访问令牌:

我能够从Azure Active Directory v2.0端点获取令牌。 请求代码如下所示:

 new KeyValuePair<string, string>("grant_type", "client_credentials"),
         new KeyValuePair<string, string>("client_id", "<clent id>"),
         new KeyValuePair<string, string>("client_secret", "<client secret>"),
         new KeyValuePair<string, string>("resource", @"https://graph.microsoft.com")
     var content = new FormUrlEncodedContent(pairs);

     var response = client.PostAsync("https://login.microsoftonline.com/<tenant id>/oauth2/token", content).Result;
我通过以下响应消息获得状态代码401 Unauthorized:

Unauthorized: Access is denied due to invalid credentials.
You do not have permission to view this directory or page using the credentials that you supplied.
是否存在我尚未执行的授权过程以授予对我的应用程序的访问权限。请帮忙


提前谢谢

根据测试,Microsoft Graph似乎不支持使用仅应用程序令牌列出任务。在我授予应用程序的
Group.ReadAll
应用程序权限后,我在请求中得到如下错误:

GET:https://graph.microsoft.com/beta/tasks?$filter=createdBy+eq+'xx@xxxx.onmicrosoft.com'

但是,已使用具有相同权限的委托令牌成功调用请求:

作为一种解决方法,您可以检查OAuth2代码授权流是否对您的场景有帮助


其他用户提出了关于使用“仅应用程序”标记列出任务的反馈,如果您还需要此功能,您可以对此反馈进行投票。

根据测试,Microsoft Graph似乎不支持使用“仅应用程序”标记列出任务。在我授予应用程序的
Group.ReadAll
应用程序权限后,我在请求中得到如下错误:

GET:https://graph.microsoft.com/beta/tasks?$filter=createdBy+eq+'xx@xxxx.onmicrosoft.com'

但是,已使用具有相同权限的委托令牌成功调用请求:

作为一种解决方法,您可以检查OAuth2代码授权流是否对您的场景有帮助

其他用户提出了关于使用app only token列出任务的反馈,如果您还需要此功能,您可以从中投票此反馈