【发布时间】:2020-04-11 20:30:02
【问题描述】:
在 Azure blob 存储中,我需要在用户登录其帐户时获取访问令牌,并使用此访问令牌执行列表/上传/下载用户 blob 存储中的文件。(类似于我们可以在 Dropbox/Google 驱动器中执行)。 使用给定的请求用户身份验证,我得到了代码,
https://login.microsoftonline.com/{tenant}/oauth2/v2.0/authorize?
client_id=client_id&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%2Fmyapp%2F&response_mode=query&scope=openid%20offline_access%20https%3A%2F%2Fstorage.azure.com%2Fuser_impersonation&state=12345
代码用于使用以下请求获取令牌
POST /{tenant}/oauth2/v2.0/token HTTP/1.1
Host: https://login.microsoftonline.com
Content-Type: application/x-www-form-urlencoded
client_id=client_id&scope=openid%20offline_access%20https%3A%2F%2Fstorage.azure.com%2Fuser_impersonation&code=OAAABAAAAiL9Kn2Z27UubvWFPbm0gLWQJVzCTE9UkP3pSx1aXxUjq3n8b2JRLk4OxVXr...&redirect_uri=http%3A%2F%2Flocalhost%2Fmyapp%2F&grant_type=authorization_code&client_secret=client_secret
但是当我使用https://account_name.blob.core.windows.net/container_name?restype=container&comp=list 调用获取请求以列出列表时,我得到了server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature。如何使用获得的令牌访问 blob 存储中的文件?我们可以使用 python 做到这一点吗?
【问题讨论】:
标签: python azure azure-devops-rest-api