Azure API 管理 - OAuth2.0 客户端凭证授权问题

问题描述 投票:0回答:1

我正在尝试设置一个 API,该 API 将使用 Azure API 管理来获取 Azure AD B2C 目录中的用户列表。通过邮递员,我可以发出以下请求来获取不记名令牌,我可以用它查询端点https://graph.microsoft.com/v1.0/users:

POST /{TenantId}/oauth2/v2.0/token HTTP/1.1
Host: login.microsoftonline.com
Content-Length: 525
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW

----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="grant_type"

client_credentials
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="client_id"

{ClientId}
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="client_secret"

{ClientSecret}
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="scope"

https://graph.microsoft.com/.default
----WebKitFormBoundary7MA4YWxkTrZu0gW

但是,当我尝试使用 Authorizations 配置同样的东西时,出现以下错误:

Failed to acquire access token for service using client credentials flow: IdentityProvider=oauth2. Details: {"error":"invalid_request","error_description":"AADSTS90014: The required field 'scope' is missing from the credential. Ensure that you have all the necessary parameters for the login request.}

这是有道理的,因为我从未配置过

scope
属性。但是,
scope
不是我可以为
Client Credentials
Grant Type 定义的属性:

我在哪里定义

scope
?是否在应用程序注册中定义?

oauth-2.0 microsoft-graph-api azure-ad-b2c azure-api-management
1个回答
0
投票

也许当您选择其他授权类型时,会出现一个范围字段。我没有测试但是基于this section.

无论如何,在使用客户端凭证流时,没有范围,因为我们始终将范围设置为

xxx/.default
,就像本节所示。无论如何,您需要按照文档进行
expose an api, add roles, then add the api permission
。您只能注册一个应用程序,这意味着用于保护 web api(暴露 api)的应用程序也用于身份验证。

© www.soinside.com 2019 - 2024. All rights reserved.