通过令牌访问Azure Web App时拒绝访问

时间:2019-07-31 20:11:42

标签: azure oauth-2.0 azure-active-directory postman azure-web-app-service

我们正在测试通过将内置的Azure Web App身份验证/授权与Azure Active Directory结合使用来锁定Azure Web Apps上托管的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.

我花了几天的时间尝试着所有可以找到的东西。我想念什么?一旦我关闭了Web应用程序所需的授权,就可以得到预期的结果。但是使用grant_type:密码,我无法进入!我有一个与范围有关的感觉,但是在这里我找不到所需的文档。有什么想法吗?

用户能够手动登录到网页并提取数据,因此这不是权限问题。我相信这与令牌有关。

1 个答案:

答案 0 :(得分:1)

如果您使用的是v2.0端点,则范围应为{your_client_id}/.default。将https://{webappname}.azurewebsites.net替换为Azure AD中API应用程序的客户端ID /应用程序ID。

enter image description here

修改

如韦恩所说,您也可以将scope设置为{your_client_id}/User.Read以获得访问令牌。

相关问题