我对 Python 和编程很陌生,我正在尝试弄清楚如何自动化 box.com 身份验证过程,这让我很兴奋。任何帮助,将不胜感激!
我在下面有这段代码,这显然不是我的,而是来自教程。我想弄清楚
keyring.get_password('Box_Auth', 'mybox@box.com')
我在想 mybox@box.com 是我的重定向 URI?但我不确定当它要求 Box_Auth 时它在寻找什么。
这是完整的代码
"""An example of Box authentication with external store"""
import keyring
from boxsdk import OAuth2
from boxsdk import Client
CLIENT_ID = ''
CLIENT_SECRET = ''
def read_tokens():
"""Reads authorisation tokens from keyring"""
# Use keyring to read the tokens
auth_token = keyring.get_password('Box_Auth', 'mybox@box.com')
refresh_token = keyring.get_password('Box_Refresh', 'mybox@box.com')
return auth_token, refresh_token
def store_tokens(access_token, refresh_token):
"""Callback function when Box SDK refreshes tokens"""
# Use keyring to store the tokens
keyring.set_password('Box_Auth', 'mybox@box.com', access_token)
keyring.set_password('Box_Refresh', 'mybox@box.com', refresh_token)
def main():
"""Authentication against Box Example"""
# Retrieve tokens from secure store
access_token, refresh_token = read_tokens()
# Set up authorisation using the tokens we've retrieved
oauth = OAuth2(
client_id=CLIENT_ID,
client_secret=CLIENT_SECRET,
access_token=access_token,
refresh_token=refresh_token,
store_tokens=store_tokens,
)
# Create the SDK client
client = Client(oauth)
# Get current user details and display
current_user = client.user(user_id='me').get()
print('Box User:', current_user.name)
再次,我真的很感激任何帮助!