跳转到主要内容

使用Microsoft Graph API实现的OneDrive的Pyfilesystem2实现

项目描述

fs.onedrivefs

使用OneDrive实现的pyfilesystem2文件系统

image codecov PyPI version

使用方法

fs.onedrivefs可以为您创建一个requests_oauthlib.OAuth2Session。这样,OAuth2Session将为您刷新令牌。

onedriveFS = OneDriveFS(
  clientId=<your client id>,
  clientSecret=<your client secret>,
  token=<token JSON saved by oauth2lib>,
  SaveToken=<function which saves a new token string after refresh>)

# onedriveFS is now a standard pyfilesystem2 file system

您可以通过传递requests.Session来在库外部处理令牌。以下是一个使用MSAL Python的示例

class MSALSession(OAuth2Session):
  def __init__(self, client: msal.ClientApplication):
    super().__init__()
    self.client = client

  def request(self, *args, **kwargs):
    account = self.client.get_accounts()[0]
    self.token = self.client.acquire_token_silent_with_error(
      scopes=["Files.ReadWrite"], account=account
    )

    return super().request(*args, **kwargs)

client = msal.ConfidentialClientApplication(
  client_id=<your client id>,
  client_credential=<your client secret>,
  authority=f"https://login.microsoftonline.com/<your tenant>",
  token_cache=<your token cache>,
)

# Authentication flow to populate the token cache
# YOUR AUTHENTICATION FLOW

session = MSALSession(client=client)
onedriveFS = OneDriveFS(session=session)

# onedriveFS is now a standard pyfilesystem2 file system

在此处注册您的应用程序以获取客户端ID和密钥这里

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源代码分发

fs_onedrivefs-1.2.0.tar.gz (595.8 kB 查看哈希值)

上传时间 源代码

构建分发

fs_onedrivefs-1.2.0-py3-none-any.whl (10.6 kB 查看哈希值)

上传时间 Python 3

由以下支持