【发布时间】:2019-08-01 17:53:24
【问题描述】:
我们正在测试通过使用 Azure Active Directory 的内置 Azure Web 应用身份验证/授权来锁定托管在 Azure Web 应用上的 API。
我们在 Postman 中使用以下参数调用 POST https://login.microsoftonline.com/{tenantIDhere}/oauth2/v2.0/token:
grant_type: password
client_id: {ID}
username: {username}@{tenenat}.onmicrosoft.com
password: {password}
scope: https://{webappname}.azurewebsites.net/.default
client_secret: {secret}
以下是我得到的回复:
"token_type":"Bearer","scope":"https://{webappname}.azurewebsites.net/user_impersonation https://{webappname}.azurewebsites.net/.default","expires_in":3599,"ext_expires_in":3599,"access_token":"{TOKEN HERE}"}
所以我使用该令牌并尝试通过在标头中传递令牌来访问网页,然后使用 POST 得到以下错误:
https://{webappname}.azurewebsites.net/api/url
Authorization: Bearer {TOKEN HERE}
响应(401 未授权)
You do not have permission to view this directory or page.
我花了几天时间尝试所有我能找到的东西。我错过了什么??一旦我关闭网络应用程序所需的授权,我就会得到预期的结果。但是使用grant_type:密码,我无法进入!我觉得它与范围有关,但我在这里找不到关于我需要什么的文档。有什么想法吗?
用户可以手动登录网页并拉取数据,因此不是权限问题。这与我相信的令牌有关。
【问题讨论】:
标签: azure oauth-2.0 azure-active-directory postman azure-web-app-service