Azure Web 应用程序的 Azure Api 管理身份验证

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

所以我最近阅读了很多有关 API 管理和 Web 应用程序身份验证的内容。 这可能是最好的一个:https://techcommunity.microsoft.com/t5/fasttrack-for-azure/protecting-apis-in-azure-api-management-using-oauth-2-0-客户/ba-p/3054130

但是,我想要实现的不仅仅是能够向 INTERNAL AD 工作人员提供访问权限,我还想处理组织外部的 API/人员。我希望注册(并被我们接受)的人能够通过 OAuth2.0 请求 JWT。然后使用他们的订阅密钥和令牌进入流程。 但我不知道如何设置。 我看到了一些关于 api 管理的身份验证的内容。 这里有什么建议如何为外部人员完成最后一部分吗? (不让他们成为来宾 AD 用户(或 Microsoft Entra ;))

azure azure-active-directory azure-api-management
1个回答
0
投票

我想要实现的目标不仅是能够向内部 AD 工作人员授予访问权限,我还想处理组织外部的 API/人员,而不是让他们成为来宾 AD 用户(或 Microsoft Entra)

要允许组织外部的所有用户访问 Azure 广告应用程序,您必须通过选择“”任何组织目录中的帐户(任何 Microsoft Entra ID 租户 - 多租户)和个人 Microsoft 帐户(例如 Skype)将应用程序创建为 多租户 ,Xbox)

我创建了

APIMapp
APIMClientApp
作为多租户,如下所示:

enter image description here

enter image description here

APIMapp
中,公开了一个 API 并确保添加授权的客户端应用程序:

我添加了

APIMClientApp
客户端 ID 作为客户端应用程序

enter image description here

在APIM中,更新了入境政策如下:

<inbound>
<base  />
<validate-jwt  header-name="Authorization"  failed-validation-httpcode="401"  failed-validation-error-message="Unauthorized. Access token is missing or invalid.">
<openid-config  url="https://login.microsoftonline.com/common/.well-known/openid-configuration"  />
<required-claims>
<claim  name="aud"  match="any">
<value>APIMappClientID</value>
</claim>
</required-claims>
</validate-jwt>
</inbound>

现在要授权另一个租户用户,我使用了以下端点:

https://login.microsoftonline.com/common/oauth2/v2.0/authorize?
&client_id=APIMClientApp
&response_type=code
&redirect_uri=https://jwt.ms
&response_mode=query
&scope=api://APIMapp/user_impersonation
&state=12345

enter image description here

enter image description here

使用以下参数生成访问令牌

https://login.microsoftonline.com/common/oauth2/v2.0/token

client_id:APIMClientApp
scope:api://APIMapp/api.access
code:code
redirect_uri:https://jwt.ms
grant_type:authorization_code
client_secret:ClientSecret

enter image description here

当我解码访问令牌时,范围就存在:

enter image description here

  • 使用上述访问令牌,其他租户用户可以调用 APIM。
  • 如果您只想授权其他租户 Azure AD 用户,则通过选择“任何组织目录中的帐户(任何 Microsoft Entra ID 租户 - 多租户)”来创建应用程序
  • 并利用
    https://login.microsoftonline.com/organizations/

参考:

客户端应用程序配置 (MSAL) - Microsoft Entra

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