Microsoft Graph和无用户访问 [英] Microsoft Graph and access without a user

查看:127
本文介绍了Microsoft Graph和无用户访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用在ASP.NET Core应用程序中经常运行的后台任务(守护程序)在线上传和下载共享点中的文件.因为这是后台任务,所以不使用任何用户身份.相反,我尝试遵循此

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. Because it's a background task, no user identity is used. Instead, I tried to follow this

我可以使用应用程序的客户端ID和密码获取访问令牌.但是,当我尝试在共享点上的特定站点上请求驱动器时,它只是停顿了,提示我无法到达路径.当我改用我的用户凭证时,我可以完全达到相同的路径.

I'm able to get an access token using my app's client id and secret. 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. 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(); 

在ASP.NET Core 2应用程序中使用Microsoft Graph SDK.

Using Microsoft Graph SDK within an ASP.NET Core 2 app.

以下是更新的屏幕截图,显示了已添加并同意的应用程序权限:

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.

这篇关于Microsoft Graph和无用户访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆