您目前查看的是 Apigee Edge 說明文件。
前往 Apigee X 說明文件。 info
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"
}
}
}
原因
如果基本驗證政策的 <Source> 元素中指定的 Base64 編碼字串所含變數符合下列任一條件,就會發生這項錯誤:
- 超出範圍 (無法在執行政策的特定流程中使用)
- 無法解析 (未定義)
舉例來說,如果 BasicAuthentication 政策在 <Source> 元素中指定變數request.header.Authorization,但 API 要求未傳遞 Authorization 標頭,就會發生這個錯誤。
診斷
找出 BasicAuthentication 政策中用於
<Source>元素的變數。您可以在錯誤回應的faultstring元素中找到這項資訊。舉例來說,在下列faultstring,中,用於<Source>元素的變數是request.header.Authorization:"faultstring": "Unresolved variable : request.header.Authorization"檢查發生失敗的特定 API Proxy 中的所有 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>判斷變數是否已定義,且可在執行 BasicAuthentication 政策的流程中使用。
如果變數為下列任一項:
- 超出範圍 (無法在執行政策的特定流程中使用)
- 無法解析 (未定義)
這就是錯誤原因。
在上述 BasicAuthentication 政策範例中,變數
request.header.Authorization未做為要求的一部分傳遞。也就是說,API 要求是在沒有 Authorization 標頭的情況下發出,如下所示: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 編碼字串,就會發生這項錯誤。
診斷
找出 BasicAuthentication 政策中用於
<Source>元素的變數。您可以在錯誤回應的faultstring元素中找到這項資訊。舉例來說,在下列faultstring,中,用於<Source>元素的變數是request.header.Authorization:"faultstring": "Source variable : request.header.Authorization for basic authentication decode policy is not valid"檢查發生失敗的特定 API Proxy 中的所有 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>如果
<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 政策的範例問題,請在 Authorization 標頭中傳遞有效的 Base64 編碼字串,藉此發出 API 要求,如下所示:
curl -v "http://org-env.apigee.net/basicauth" -H "Authorization: Basic YWthc2g6MTIz"
原因:標頭格式錯誤/無效
如果傳遞至 BasicAuthentication 政策的標頭格式錯誤或無效,就會發生這項錯誤。
舉例來說,如果 BasicAuthentication 政策在 <Source> 元素中指定變數為 request.header.Authorization,且做為 API 要求一部分傳遞的標頭格式錯誤/無效,就會發生這項錯誤。
診斷
找出 BasicAuthentication 政策中用於
<Source>元素的變數。您可以在錯誤回應的faultstring元素中找到這項資訊。舉例來說,在下列錯誤中,用於<Source>元素的變數是request.header.Authorization:"faultstring": "Source variable : request.header.Authorization for basic authentication decode policy is not valid"檢查發生失敗的特定 API Proxy 中的所有 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>如果變數是標頭,且格式有誤或無效 (即沒有驗證類型,或驗證類型不是「Basic」),就會導致錯誤。
Authorization 標頭的格式如下:
Authorization: <Authentication type> <credentials>格式錯誤的標頭可透過兩種方式傳遞至 BasicAuthentication 政策:
範例 1:標頭中沒有驗證類型:
curl -v "http://org-env.apigee.net/basicauth" -H "Authorization: YWthc2g6MTIz"
在上述範例中,「Authorization」標頭沒有驗證類型。如果將這個標頭傳遞至上述 BasicAuthentication 政策,您會收到下列錯誤碼:
steps.basicauthentication.InvalidBasicAuthenticationSource範例 2:驗證類型不是「Basic」類型:
curl -v "http://org-env.apigee.net/basicauth" -H "Authorization: OAuth YWthc2g6MTIz"
在上述範例中,「Authorization」標頭沒有「Basic」驗證類型。如果將這個值傳遞至上述 BasicAuthentication 政策,您會收到以下錯誤代碼:
steps.basicauthentication.InvalidBasicAuthenticationSource同樣地,如果授權標頭中使用了 Bearer、Digest Auth 等驗證類型,也可能會發生這項錯誤。
解析度
請確認傳遞 BasicAuthentication 政策輸入內容的標頭具有驗證類型,且類型為「Basic」。
如要修正上述範例 BasicAuthentication 政策的問題,請在 Authorization 標頭中傳遞有效的 Base64 編碼字串,並將「Basic」驗證類型設為如下所示,藉此提出 API 要求:
curl -v "http://org-env.apigee.net/basicauth" -H "Authorization: Basic YWthc2g6MTIz"