其中 $EXTERNAL_IP 是外部負載平衡器的 IP 位址。這個 IP 位址會公開在網際網路上。詳情請參閱「自訂存取路由」。
Because the authorization request header is not passed, the Decode JWT policy fails with the error:
```
"faultstring": "Invalid token: policy({0})"
```
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-05 (世界標準時間)。"],[[["\u003cp\u003eThis document provides troubleshooting guidance for common errors encountered with Apigee's Decode JWT policy, specifically \u003ccode\u003eFailedToDecode\u003c/code\u003e and \u003ccode\u003eInvalidToken\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eFailedToDecode\u003c/code\u003e error occurs when the JWT in the \u003ccode\u003e<Source>\u003c/code\u003e element is malformed or missing necessary components like the header, payload, or signature, which can be resolved by ensuring the JWT is correctly formatted as \u003ccode\u003eheader.payload.signature\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eInvalidToken\u003c/code\u003e error occurs if the variable specified in the \u003ccode\u003e<Source>\u003c/code\u003e element of the Decode JWT policy is out of scope or not defined, and can be resolved by ensuring a valid JWT is present in a defined variable.\u003c/p\u003e\n"],["\u003cp\u003eTo diagnose either error, identify the variable in the Decode JWT policy's \u003ccode\u003e<Source>\u003c/code\u003e element and check if it contains a valid, properly formatted, and decodable JWT.\u003c/p\u003e\n"],["\u003cp\u003eBoth of these errors can be corrected by passing a valid, properly formatted JWT (like \u003ccode\u003eheader.payload.signature\u003c/code\u003e) in the expected variable, such as the Authorization request header, as demonstrated in the provided cURL examples.\u003c/p\u003e\n"]]],[],null,["# Decode JWT runtime error troubleshooting\n\n*You're viewing **Apigee** and **Apigee hybrid** documentation.\nView [Apigee Edge](https://docs.apigee.com/api-platform/troubleshoot/policies/runtime/decode-JWT-runtime-errors) documentation.*\n| **Note:** Was this troubleshooting playbook helpful? Please let us know by clicking [Send Feedback]().\n\nFailedToDecode\n--------------\n\n### Error code\n\n steps.jwt.FailedToDecode\n\n### Error response body\n\n {\n \"fault\": {\n \"faultstring\": \"Failed to Decode Token: policy({0})\",\n \"detail\": {\n \"errorcode\": \"steps.jwt.FailedToDecode\"\n }\n }\n }\n\n### Cause\n\nThis error occurs if the [JSON Web Token](/apigee/docs/api-platform/reference/policies/jwt-policies-overview) (JWT) specified in the `\u003cSource\u003e` element of the Decode JWT policy is malformed, invalid or otherwise not decodable.\n\nA properly structured JWT should contain a header, payload and signature in the following format: `header.payload.signature`. If the JWT passed to the DecodeJWT policy is missing a component part, then you will get the error. For example, if the JWT has only `payload.signature`, but is missing its `header`, the error will occur.\n\n### Diagnosis\n\n1. Identify the variable specified in the `\u003cSource\u003e` element of the Decode JWT policy. This variable should contain the JWT.\n\n Here's a sample Decode JWT policy: \n\n \u003cDecodeJWT name=\"JWT-Decode-HS256\"\u003e\n \u003cDisplayName\u003eJWT Verify HS256\u003c/DisplayName\u003e\n \u003cSource\u003erequest.header.authorization\u003c/Source\u003e\n \u003cIgnoreUnresolvedVariables\u003efalse\u003c/IgnoreUnresolvedVariables\u003e\n \u003c/DecodeJWT\u003e\n\n In the above example, the JWT should be contained in the Authorization request header.\n2. Examine the variable identified in Step 1 and check to see if the JWT it contains is valid. If the input JWT is not valid, then that's the cause for the error.\n\n In the example API request below, the input JWT is passed in the Authorization request header: \n\n ```\n curl -v \"http://$EXTERNAL_IP/v1/decodeJWT\" -H \"Authorization: Bearer eyJ1c2VySWQiOiJiMDhmODZhZi0zNWRhLTQ4ZjItOGZhYi1jZWYzOTA0NjYwYmQifQ.-xN_h82PHVTCMA9vdoHrcZxH-x5mb11y1537t3rGzcM\"\n ```\n\n\n Where **$EXTERNAL_IP** is the IP address of the external load balancer.\n This IP address is exposed to the internet. For more information, see\n [Customize access routing](/apigee/docs/api-platform/get-started/configure-routing#external-access).\n\n \u003cbr /\u003e\n\n Close examination of the JWT shows that it has the format `payload.signature` which is invalid. The expected format of the JWT is `header.payload.signature`. As a result, the Decode JWT policy fails with the error : \n\n \"faultstring\": \"Failed to Decode Token: policy({0})\"\n\n### Resolution\n\nEnsure that the JWT passed to the Decode JWT policy contains all three elements, is correctly formatted and is decodable.\n\nTo correct the example shown above, you can pass in a valid JWT with the format `header.payload.signature`. This can be done by making the API call using the cURL command as follows: \n\n```\ncurl -v \"http://$EXTERNAL_IP/v1/decodeJWT\" -H \"Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VySWQiOiJiMDhmODZhZi0zNWRhLTQ4ZjItOGZhYi1jZWYzOTA0NjYwYmQifQ.-xN_h82PHVTCMA9vdoHrcZxH-x5mb11y1537t3rGzcM\"\n```\n\n\nWhere **$EXTERNAL_IP** is the IP address of the external load balancer.\nThis IP address is exposed to the internet. For more information, see\n[Customize access routing](/apigee/docs/api-platform/get-started/configure-routing#external-access).\n\n\u003cbr /\u003e\n\nInvalidToken\n------------\n\n### Error code\n\n steps.jwt.InvalidToken\n\n### Error response body\n\n {\n \"fault\": {\n \"faultstring\": \"Invalid token: policy({0})\",\n \"detail\": {\n \"errorcode\": \"steps.jwt.InvalidToken\"\n }\n }\n }\n\n### Cause\n\nThis error occurs if the flow variable specified in the `\u003cSource\u003e` element of the Decode JWT policy is:\n\n- out of scope (not available in the specific flow where the policy is being executed) or\n- can't be resolved (is not defined)\n\n### Diagnosis\n\n1. Identify the variable specified in the `\u003cSource\u003e` element of the Decode JWT policy. This variable should contain the JWT.\n\n Here's a sample Decode JWT policy: \n\n \u003cDecodeJWT name=\"JWT-Decode-HS256\"\u003e\n \u003cDisplayName\u003eJWT Verify HS256\u003c/DisplayName\u003e\n \u003cSource\u003erequest.header.authorization\u003c/Source\u003e\n \u003cIgnoreUnresolvedVariables\u003efalse\u003c/IgnoreUnresolvedVariables\u003e\n \u003c/DecodeJWT\u003e\n\n In the example above, the Authorization request header should contain the JWT.\n2. Determine if the variable identified in Step 1 is defined and available in the flow in which the Decode JWT policy is executed.\n\n3. If the variable is either:\n\n - out of scope (not available in the specific flow where the policy is being executed) or\n - can't be resolved (is not defined)\n\n then that's the cause for the error.\n\n In the example API request below, the JWT is not passed in the authorization request header by the user. \n\n ```\n curl -v \"http://$EXTERNAL_IP/v1/decodeJWT\"\n ```\n\n\nWhere **$EXTERNAL_IP** is the IP address of the external load balancer.\nThis IP address is exposed to the internet. For more information, see\n[Customize access routing](/apigee/docs/api-platform/get-started/configure-routing#external-access).\n\n\u003cbr /\u003e\n\n Because the authorization request header is not passed, the Decode JWT policy fails with the error:\n\n ```\n \"faultstring\": \"Invalid token: policy({0})\"\n ```\n\n### Resolution\n\nEnsure that the variable referenced in the `\u003cSource\u003e` element of the Decode JWT policy is defined, contains a valid (decodable) JWT and is available in the specific flow where the Decode JWT policy is being executed.\n\nTo correct the example shown above, you can pass a valid JWT in the request authorization header. This can be done by making the API call using the cURL command as follows: \n\n```\ncurl -v \"http://$EXTERNAL_IP/v1/decodeJWT\" -H \"Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VySWQiOiJiMDhmODZhZi0zNWRhLTQ4ZjItOGZhYi1jZWYzOTA0NjYwYmQifQ.-xN_h82PHVTCMA9vdoHrcZxH-x5mb11y1537t3rGzcM\"\n```\n\n\nWhere **$EXTERNAL_IP** is the IP address of the external load balancer.\nThis IP address is exposed to the internet. For more information, see\n[Customize access routing](/apigee/docs/api-platform/get-started/configure-routing#external-access).\n\n\u003cbr /\u003e"]]