azure - 无法使用 Azure AD 和客户端凭据流请求特定范围的 OAuth2 token

标签 azure oauth token clientcredential

我们正在开发一个具有前端和后端的应用程序。应使用 OAuth2 token 通过 Rest API 访问后端。授权提供商是 Azure AD。

在 Azure 中,我们创建了 2 个应用程序注册。一种用于 API,一种用于客户端应用程序。 API 注册定义了 3 个范围(读、写、删除)。客户端应用程序注册已委派这些范围的权限。

我们正在从客户端应用注册请求带有 clientID 和 clientSecret 的 token 。

问题是我们只能请求范围为 api/.default 的 token 。例如。 api/read 导致无效范围错误。 但如果我们使用 api/.default,则 token 中不包含范围 (scp) 属性。是否不需要检查使用 API 的应用程序是否具有正确的权限?

我不确定我们是否做错了什么,或者我们是否有错误的理解/期望。

最佳答案

使用客户端凭据流获取 Azure AD JWT token 时,范围必须采用以下格式:

api://<clientid of the API app registered>/.default

根据 MSDN,OAUTH Client Credential Flow

scope - Required - The value passed for the scope parameter in this request should be the resource identifier (application ID URI) of the resource you want, affixed with the .default suffix. For the Microsoft Graph example, the value is https://graph.microsoft.com/.default. This value tells the Microsoft identity platform that of all the direct application permissions you have configured for your app, the endpoint should issue a token for the ones associated with the resource you want to use. To learn more about the /.default scope, see the consent documentation.

关于azure - 无法使用 Azure AD 和客户端凭据流请求特定范围的 OAuth2 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66776730/

相关文章:

PHP - 如何获得 token ?

JavaCC 识别 token 中的 token

python - U-SQL + Python 返回列数未知的数据帧

Azure 板 : Query - Pending Work for an Epic

c# - 如何保护 OAuth key 不被用户反编译我的项目?

ruby-on-rails - Facebook 请求扩展权限(但不应该)

python - 使用 PLY 解析标记

asp.net-mvc - 无法从应用程序连接到 SQL Azure,但可以从 SSMS 连接到 SQL Azure

Azure PAM 未收到来自 ‎"Microsoft Graph data connect‎"数据工厂管道执行的特权访问请求

eclipse - 使用 Eclipse 插件进行 AppEngine 部署期间出现错误 401 未经授权(无效的 OAuth token )