您正在查看 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
的變數,但 Authorization 標頭並未包含在 API 要求中,就會發生此錯誤。
診斷
在 BasicAuthentication 政策中,找出
<Source>
元素使用的變數。您可以在錯誤回應的faultstring
元素中找到這項資訊。舉例來說,在下列faultstring,
中,<Source>
元素使用的變數為request.header.Authorization
:"faultstring": "Unresolved variable : request.header.Authorization"
檢查發生錯誤的特定 API Proxy 中的所有 BasicAuthentication 政策。可能有一或多項基本驗證政策。找出
<Source>
元素中指定的變數與錯誤字串中識別的變數名稱相符的特定 BasicAuthentication 政策。例如,下列政策會將
<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 政策的流程中使用。
如果該變數為其中一種:
- 超出範圍 (不適用於執行政策的特定流程)
- 無法解析 (未定義)
這就是錯誤的原因。
在上方顯示的基本驗證政策範例中,系統並未在要求中傳送變數
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 政策。可能有一或多項基本驗證政策。找出
<Source>
元素中指定的變數與錯誤字串中識別的變數名稱相符的特定 BasicAuthentication 政策 (ies)。例如,下列政策會將
<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 政策。可能有一或多項基本驗證政策。找出
<Source>
元素中指定的變數與錯誤字串中識別的變數名稱相符的特定 BasicAuthentication 政策 (ies)。例如,下列政策會將
<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>
如果變數是標頭且格式錯誤或無效,也就是沒有驗證類型,或是驗證類型不是「基本」,就就是造成錯誤的原因。
授權標頭的格式如下:
Authorization: <Authentication type> <credentials>
格式錯誤的標頭可透過兩種方式傳送至 BasicAuthentication 政策:
示例 1:標頭中沒有驗證類型:
curl -v "http://org-env.apigee.net/basicauth" -H "Authorization: YWthc2g6MTIz"
在上述範例中,Authorization 標頭沒有「驗證」類型。如果這個標頭傳遞至上述 BasicAuthentication 政策,您會收到錯誤代碼:
steps.basicauthentication.InvalidBasicAuthenticationSource
範例 2:驗證類型不是「基本」類型:
curl -v "http://org-env.apigee.net/basicauth" -H "Authorization: OAuth YWthc2g6MTIz"
在上述範例中,Authorization 標頭沒有「Basic」的驗證類型。如果傳送至上述 BasicAuthentication 政策,您會收到錯誤代碼:
steps.basicauthentication.InvalidBasicAuthenticationSource
同樣地,如果 Authorization 標頭中使用了驗證類型 (例如 Bearer、Digest Auth 等),也可能會發生這個錯誤。
解析度
確認將輸入至 BasicAuthentication 政策的標頭具有驗證類型,且類型為「基本」。
如要修正上述 BasicAuthentication 政策的問題,請在 Authorization 標頭中傳遞包含「Basic」驗證類型的有效 Base64 編碼字串,以提出 API 要求,如下所示:
curl -v "http://org-env.apigee.net/basicauth" -H "Authorization: Basic YWthc2g6MTIz"