Python 用于 Developer/Enterprise 的 SDK:阐明 JWT 身份验证

Box Python SDK for Developer/Enterprise: Clarifying JWT Authentication

https://github.com/box/box-python-sdk/blob/1b2d19662e904a2cc850dab2c66ee122c3b3e20e/README.rst#get-the-authorization-url 状态:

auth = JWTAuth(
     client_id='YOUR_CLIENT_ID',
     client_secret='YOUR_CLIENT_SECRET',
     enterprise_id='YOUR_ENTERPRISE_ID',
     jwt_key_id='YOUR_JWT_KEY_ID',
     rsa_private_key_file_sys_path='CERT.PEM',
     store_tokens=your_store_tokens_callback_method,
     )

前 3 个参数是 self-explanatory。

4: jwt_key_id : 这是从哪里来的?这与 JWT header 中的 public 密钥 ID 相同吗?类似的问题(Authenticate with Box Developer Edition using box-python-sdk)没有列出这个论点。

5: 我有私钥文件的路径;当我 运行 这个脚本 returns 一个错误时,Password was not given but private key is encrypted. 这里的社区回答 https://community.box.com/t5/Box-Developer-Forum/Setting-password-for-private-key-when-using-JWTAuth-via-box/td-p/19407 建议需要另一个参数,所以我添加了: rsa_private_key_passphrase = 'my_passphrase' 作为 JWTAuth 的另一个参数。这是正确的吗?

6:store_tokens 参数看起来是可选的,所以我假设我可以输入 store_tokens=None 而小猫不会死,对吧?

4:您是正确的,因为 jwt_key_id 与应用程序配置设置中的 8 个字符长 Public 密钥 ID 相同。

5:对于 rsa_private_key_file_sys_path,您必须输入 private_key.pem 文件的绝对路径。

6:是的,store_tokens 不是强制性的,您可以将其删除。相反,将其替换为 JWT 身份验证所需的 rsa_private_key_passphrase

重要提示: rsa_private_key_passphrase 必须以字节为单位,因此请确保格式为 rsa_private_key_passphrase = b'my_passphrase'.

希望事情已经解决了。