基本身份验证政策运行时错误问题排查

您正在查看的是 Apigee Edge 文档。
转到 Apigee X 文档
信息

UnresolvedVariable

错误代码

steps.basicauthentication.UnresolvedVariable

错误响应正文

{
    "fault": {
        "faultstring": "Unresolved variable : [variable_name]",
        "detail": {
            "errorcode": "steps.basicauthentication.UnresolvedVariable"
        }
    }
}

错误消息示例

{
    "fault": {
        "faultstring": "Unresolved variable : request.header.Authorization",
        "detail": {
            "errorcode": "steps.basicauthentication.UnresolvedVariable"
        }
    }
}

原因

如果包含 BasicAuthentication 政策<Source> 元素中指定的 Base64 编码字符串的变量是以下任一项,就会出现此错误:

  • 超出范围(在执行政策的特定流中不可用)
  • 无法解析(未定义)

例如,如果 BasicAuthentication 政策在 <Source> 元素中指定了 request.header.Authorization 变量,但授权标头不是作为 API 请求的一部分传递,就会出现此错误。

诊断

  1. 标识用于 BasicAuthentication 政策中 <Source> 元素的变量。您可以在错误响应的 faultstring 元素中找到此信息。例如,在以下 faultstring, 中,<Source> 元素所用的变量为 request.header.Authorization

    "faultstring": "Unresolved variable : request.header.Authorization"
    
  2. 检查出现故障的特定 API 代理中的所有 BasicAuthentication 政策。可能有一个或多个 BasicAuthentication 政策。标识一个或多个 BasicAuthentication 政策,在其中,在 <Source> 元素中指定的变量与故障字符串中标识的变量名称(上述第 1 步)相匹配。

    例如,以下政策将 <Source> 元素设置为名为 request.header.Authorization 的变量,该变量与 faultstring 中的内容相匹配:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <BasicAuthentication name="DecodeBaseAuthHeaders">
      <DisplayName>Decode Basic Authentication Header</DisplayName>
      <Operation>Decode</Operation>
      <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
      <User ref="request.header.username"/>
      <Password ref="request.header.password"/>
      <Source>request.header.Authorization</Source>
    </BasicAuthentication>
    
  3. 确定变量是否已定义,以及在执行 BasicAuthentication 政策的流中是否可用。

  4. 如果该变量:

    1. 超出范围(在执行政策的特定流中不可用)
    2. 无法解析(未定义)

    那么就会导致错误。

    在上面所示的 BasicAuthentication 示例中,变量 request.header.Authorization 未作为请求的一部分进行传递。也就是说,API 请求是在没有授权标头的情况下发出的,如下所示:

    curl -v "http://org-env.apigee.net/basicauth"

    由于在 BasicAuthentication 政策中使用的变量不可用,因此您会收到错误代码:

    steps.basicauthentication.UnresolvedVariable
    

解决方法

确保将 BasicAuthentication 政策中使用的变量定义为输入或作为输入传递,并且在执行政策的流中可用。

如需解决上述 BasicAuthentication 示例中的问题,请发出一个 API 请求,如下所示:

curl -v "http://org-env.apigee.net/basicauth" -H "Authorization: Basic YWthc2g6MTIz"

InvalidBasicAuthenticationSource

错误代码

steps.basicauthentication.InvalidBasicAuthenticationSource

错误响应正文

{
    "fault": {
        "faultstring": "Source variable : [variable_name] for basic authentication decode policy is not valid",
        "detail": {
            "errorcode": "steps.basicauthentication.InvalidBasicAuthenticationSource"
        }
    }
}

错误示例错误消息

{
    "fault": {
        "faultstring": "Source variable : request.header.Authorization for basic authentication decode policy is not valid",
        "detail": {
            "errorcode": "steps.basicauthentication.InvalidBasicAuthenticationSource"
        }
    }
}

可能的原因

造成此错误的可能原因包括:

原因 说明
来源变量无效 BasicAuthentication 政策的输入来源变量不是有效的 Base64 编码字符串。
标头格式不正确 包含传递给 BasicAuthentication 政策的 Base64 编码字符串的标头格式不正确。

原因:来源变量无效

如果包含 BasicAuthentication 政策<Source> 元素中指定的 Base64 编码字符串的变量不包含有效值,就会出现此错误。

例如,如果 BasicAuthentication 政策的 <Source> 元素中指定的变量没有有效的 Base64 编码字符串,就会出现此错误。

诊断

  1. 标识用于 BasicAuthentication 政策中 <Source> 元素的变量。您可以在错误响应的 faultstring 元素中找到此信息。例如,在以下 faultstring, 中,<Source> 元素所用的变量为 request.header.Authorization

    "faultstring": "Source variable : request.header.Authorization for basic authentication decode policy is not valid"
    
  2. 检查出现故障的特定 API 代理中的所有 BasicAuthentication 政策。可能有一个或多个 BasicAuthentication 政策。标识一个或多个 BasicAuthentication 政策,在其中,在 <Source> 元素中指定的变量与故障字符串中标识的变量名称(上述第 1 步)相匹配。

    例如,以下政策将 <Source> 元素设置为名为 request.header.Authorization 的变量,该变量与 faultstring 中的内容相匹配:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <BasicAuthentication name="DecodeBaseAuthHeaders">
        <DisplayName>Decode Basic Authentication Header</DisplayName>
        <Operation>Decode</Operation>
        <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
        <User ref="request.header.username"/>
        <Password ref="request.header.password"/>
        <Source>request.header.Authorization</Source>
    </BasicAuthentication>
    
  3. 如果存储在 <Source> 元素中指定的变量的值不是有效的 Base64 编码字符串,则 是导致错误的原因。

    在上面显示的 BasicAuthentication 示例中,客户端以标头发送的变量 request.header.Authorization 无效,如下所示:

    curl -v "http://org-env.apigee.net/basicauth" -H "Authorization: Basic 23435"

    由于变量 request.header.Authorization 包含无效的 Base64 编码字符串“23435"”,您将收到错误代码:

    steps.basicauthentication.InvalidBasicAuthenticationSource

分辨率

确保为 BasicAuthentication 政策中 <Source> 元素指定的变量具有有效的 Base64 编码字符串。

如需解决上述 BasicAuthentication 示例中的问题,请通过在授权标头中传递有效的 Base64 编码字符串来发出 API 请求,如下所示:

curl -v "http://org-env.apigee.net/basicauth" -H "Authorization: Basic YWthc2g6MTIz"

原因:标题格式错误/无效

如果传递给 BasicAuthentication 政策的标头格式不正确或无效,就会出现此错误。

例如,如果 BasicAuthentication 政策在 <Source> 元素中指定了 request.header.Authorization 变量,并且作为 API 请求的一部分传递的标头格式不正确/无效,就会出现此错误。

诊断

  1. 标识用于 BasicAuthentication 政策中 <Source> 元素的变量。您可以在错误响应的 faultstring 元素中找到此信息。例如,在以下错误中,用于 <Source> 元素的变量是 request.header.Authorization

    "faultstring": "Source variable : request.header.Authorization for basic authentication decode policy is not valid"
    
  2. 检查出现故障的特定 API 代理中的所有 BasicAuthentication 政策。可能有一个或多个 BasicAuthentication 政策。标识一个或多个 BasicAuthentication 政策,在其中,在 <Source> 元素中指定的变量与故障字符串中标识的变量名称(上述第 1 步)相匹配。

    例如,以下政策将 <Source> 元素设置为名为 request.header.Authorization 的变量,该变量与 faultstring 中的内容相匹配:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <BasicAuthentication name="DecodeBaseAuthHeaders">
        <DisplayName>Decode Basic Authentication Header</DisplayName>
        <Operation>Decode</Operation>
        <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
        <User ref="request.header.username"/>
        <Password ref="request.header.password"/>
        <Source>request.header.Authorization</Source>
    </BasicAuthentication>
    
  3. 如果该变量是标头且格式有误或无效,也就是说,它没有身份验证类型或者身份验证类型不是“基本”类型,就会导致错误。

    授权标头的格式如下:

    Authorization: <Authentication type> <credentials>
    

    格式错误的标头可通过两种方式传递到 BasicAuthentication 政策:

    示例 1:标头中没有身份验证类型:

    curl -v "http://org-env.apigee.net/basicauth" -H "Authorization: YWthc2g6MTIz"

    在上面的示例中,授权标头没有身份验证类型。如果将此标头传递给上面显示的 BasicAuthentication 政策,您将收到错误代码:

    steps.basicauthentication.InvalidBasicAuthenticationSource
    

    示例 2:身份验证类型不是“基本”类型:

    curl -v "http://org-env.apigee.net/basicauth" -H "Authorization: OAuth YWthc2g6MTIz"

    在上面的示例中,授权标头不具有“基本”身份验证类型:如果将此标头传递给上面显示的 BasicAuthentication 政策,您将收到错误代码:

    steps.basicauthentication.InvalidBasicAuthenticationSource
    

    同样,如果授权标头中使用身份验证类型(如 Bearer、Digest Auth 等),也会出现此错误。

分辨率

确保传递 BasicAuthentication 政策的输入的标头具有身份验证类型,并且为“基本”类型。

如需解决上述 BasicAuthentication 政策示例中的问题,请通过在授权标头中传递有效的 Base64 编码字符串(具有“基本”身份验证类型)来发出 API 请求,如下所示:

curl -v "http://org-env.apigee.net/basicauth" -H "Authorization: Basic YWthc2g6MTIz"