[英]Microsoft Graph and access without a user
I'm trying to upload and download files in my sharepoint online using a background task (daemon) that runs frequently in my ASP.NET Core app. 我正在尝试使用在我的ASP.NET核心应用程序中经常运行的后台任务(守护程序)在线上传和下载我的sharepoint中的文件。 Because it's a background task, no user identity is used. 因为它是后台任务,所以不使用用户身份。 Instead, I tried to follow this document , getting an access token using the https://graph.microsoft.com/.default
scope, as well as having my enterprise app on azure having particular permissions already granted by the admin. 相反,我尝试遵循此文档 ,使用https://graph.microsoft.com/.default
范围获取访问令牌,以及让我的企业应用程序在azure上具有管理员已授予的特定权限。
I'm able to get an access token using my app's client id and secret. 我可以使用我的应用程序的客户端ID和密码获取访问令牌。 However when I try to request the drives on a particular site on sharepoint, it just stalls, hinting me that it can't reach the path. 但是,当我尝试在sharepoint上的特定站点上请求驱动器时,它只是停顿,暗示我无法到达路径。 I can reach this same path totally fine when I use my user credentials instead. 当我使用我的用户凭证时,我可以完全达到相同的路径。
I think I may be missing a step or some azure administration-related task. 我想我可能会错过一个步骤或一些与天蓝色的管理相关的任务。 Below is the code snippet that shows I can get the access token, but stalls when getting the drives. 下面是代码片段,显示我可以获取访问令牌,但在获取驱动器时会停止。
var client = new ConfidentialClientApplication(id, uri, cred, null, new SessionTokenCache());
var authResult = await client.AcquireTokenForClientAsync(new[] {"https://graph.microsoft.com/.default"});
var token = authResult.AccessToken; // get token successfully
var graphServiceClient = new GraphServiceClient(new DelegateAuthenticationProvider(async request => {request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token)}));
// stalls below
var drives = await graphServiceClient.Sites[<sharepoint_host>].SiteWithPath(<known_path>).Drives.Request().GetAsync();
Using Microsoft Graph SDK within an ASP.NET Core 2 app. 在ASP.NET Core 2应用程序中使用Microsoft Graph SDK。
Edit: Below is an updated screenshot showing application permissions added and consented: 编辑:下面是更新的屏幕截图,显示添加和同意的应用程序权限:
Based on your image you have granted delegated permissions to the app. 根据您的图片,您已授予该应用的委派权限。 You need to grant application permissions. 您需要授予应用程序权限。 Delegated permissions only apply when acting on behalf of a user. 委派权限仅在代表用户行事时适用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.