共用方式為

Microsoft Entra 身份验证

可以通过将 Bearer 身份验证方案与从 Microsoft Entra ID 获取的令牌一起使用,对 HTTP 请求进行身份验证。 必须通过传输层安全性(TLS)传输这些请求。

先决条件

必须将用于请求 Microsoft Entra 令牌的主体分配给适用的 Azure 应用配置角色之一。

为每个请求提供身份验证所需的所有 HTTP 标头。 下面是最低要求:

请求标头 Description
Authorization 方案所需的 Bearer 身份验证信息。

Example:

Host: {myconfig}.azconfig.io
Authorization: Bearer {{AadToken}}

Microsoft Entra 令牌获取

在获取Microsoft Entra 令牌之前,必须确定要进行身份验证的用户、请求令牌的受众以及要使用的Microsoft Entra 终结点(颁发机构)。

观众

请求具有适当受众的 Microsoft Entra 令牌。 访问群体也可以称为要为其请求令牌的资源

对于全球 Azure 云中的 Azure 应用配置,请使用以下受众:

https://appconfig.azure.com

对于国家云中的 Azure 应用配置,请使用下表中指定的适用受众:

国家云 受众
由世纪互联运营的 Azure https://appconfig.azure.cn

Microsoft Entra 颁发机构

Microsoft Entra 颁发机构是用于获取 Microsoft Entra 令牌的终结点。 它的形式 https://login.chinacloudapi.cn/{tenantId}。 该 {tenantId} 段是指尝试进行身份验证的用户或应用程序所属的 Microsoft Entra 租户 ID。

身份验证库

Azure 身份验证库(MSAL)有助于简化获取Microsoft Entra 令牌的过程。 Azure 为多种语言生成这些库。 有关详细信息,请参阅 文档

Errors

可能会遇到以下错误。

HTTP/1.1 401 Unauthorized
WWW-Authenticate: HMAC-SHA256, Bearer

原因: 尚未向方案提供授权请求标头 Bearer

溶液: 提供有效的 Authorization HTTP 请求标头。

HTTP/1.1 401 Unauthorized
WWW-Authenticate: HMAC-SHA256, Bearer error="invalid_token", error_description="Authorization token failed validation"

原因: Microsoft Entra 令牌无效。

溶液: 从 Microsoft Entra 颁发机构获取Microsoft Entra 令牌,并确保使用了适当的受众。

HTTP/1.1 401 Unauthorized
WWW-Authenticate: HMAC-SHA256, Bearer error="invalid_token", error_description="The access token is from the wrong issuer. It must match the AD tenant associated with the subscription to which the configuration store belongs. If you just transferred your subscription and see this error message, please try back later."

原因: Microsoft Entra 令牌无效。

溶液: 从 Microsoft Entra 颁发机构获取Microsoft Entra 令牌。 确保 Microsoft Entra 租户与配置存储所属的订阅相关联。 如果主体属于多个Microsoft Entra 租户,则可能会出现此错误。