Box Headless OAuth2客户端
box-oauth的Python项目详细描述
python oauth2 headless client for box
python包可以帮助您在无法获取jwt文件的情况下连接box api(更好的长期解决方案)。如果您想通过OAuth2以无头方式(不带浏览器)连接到Box API,这可以帮助您
依赖关系
这个包依赖于keyring、selenium和boxsdk。由于selenium以无头模式运行,您需要确保chromedriver安装在您的机器上(不幸的是,这是在pip之外完成的)。
有关如何执行此操作的说明,请参见here
用法
通过OAuth2登录到Box
from box_auth.box_auth import BoxAuth
box = BoxAuth(
client_id, # From Box developer console
client_secret, # From box developer console
box_username,
box_password,
user_email # This is used by your keyring
)
box.login() # Login
print(box.get_current_user()) # Double check that it worked
要获得boxsdk客户端,只需运行:
Client = box.get_client()
按照boxsdk文档了解如何使用客户端访问box
测试
您需要在config_test.py文件(根目录)中使用以下变量,测试才能正常工作
client_id = # You can find this in the developer console, under your app configuration
client_secret = # ""
box_username =
box_password
user_email # This is used by your keyring to store the access and refresh token
user # This is used by tests to check that you are the correct user
然后从根目录中,只需运行
pytest
安装
作为PIP包
pip install box_oauth
或
python setup.py