Microsoft Graph API 访问用户 OneDrive 的代码库解决方案

Microsoft Graph API code-base solution to access a user OneDrive

我想访问特定工作用户的 OneDrive。我可以在 Azure AD 中注册一个应用程序并分配两种类型的权限之一(委托或应用程序)。
根据 Whosebug 中的 Microsoft Documentation if I register an app with the application-level access it could have access to all users' drive and based on ,无法限制对特定驱动器的访问。所以我忽略了这个方法。
另一方面,基于 Microsoft Documentation 如果我想将委托权限分配给定义的应用程序,我必须在同意页面上手动批准访问列表。这对我来说是不希望的,因为我正在寻找一个在幕后常规基地运行的代码库解决方案。

有什么解决方案可以让我通过 python 代码访问特定的 OneDrive 吗?

一个好的建议是使用 Graph API for OneDrive

例如,其中一个用例可以是Get current user's OneDrive:

The signed in user's drive (when using delegated authentication) can be accessed from the me singleton.

If a user's OneDrive is not provisioned but the user has a license to use OneDrive, this request will automatically provision the user's drive, when using delegated authentication.

Http 请求:

GET /me/drive

可帮助您从 Python 调用 Graph API 的资源:

https://github.com/microsoftgraph/python-security-rest-sample

编辑:


此外,我找到了一种可以禁用用户同意的方法。

通过 Azure 门户configure user consent settings

  1. 以全局管理员身份登录到 Azure 门户。
  2. Select Azure Active Directory > 企业应用程序 > 同意和权限 > 用户同意设置.
  3. 根据应用程序的用户同意、select 不允许用户同意
  4. Select 保存 以保存您的设置。

如果您想要除此之外的同意权限,您可以design your own Consent

如果您只想连接 1 个用户的 Onedrive,您可以使用适合您的方案的 ROPC flow。但出于安全考虑,微软不推荐这样做。是的,如果您启用了 MFA,则无法使用它。