You're viewing Apigee Edge documentation.
Go to the Apigee X documentation. info
Decodes the JWS header without verifying the signature on the JWS, and writes each header to a flow variable. This policy is most useful when used in concert with the VerifyJWS policy, when the value of a header from within the JWS must be known before verifying the signature of the JWS.
A JWS can have an attached payload, as in the form:
Or, the JWS can omit the payload, called a detached payload, and be in the form:
The DecodeJWS policy works with both forms because it only decodes the header portion of the JWS. The DecodeJWS policy also works regardless of the algorithm that was used to sign the JWS.
See JWS and JWT policies overview for a detailed introduction and an overview of the format of a JWS.
Watch a short video to learn how to decode a JWT. While this video is specific to a JWT, many of the concepts are the same for JWS.
Sample: Decode a JWS
The policy shown below decodes a JWS found in the flow variable var.JWS. This variable must be present and contain a viable (decodable) JWS. The policy can obtain the JWS from any flow variable.
<DecodeJWS name="JWS-Decode-HS256"> <DisplayName>JWS Verify HS256</DisplayName> <Source>var.JWS</Source> </DecodeJWS>
For each header in the header portion of the JWS, the policy sets a flow variable named:
If the JWS has an attached payload, then it sets the
flow variable to the payload. For a detached payload,
payload is empty.
See Flow variables for a complete list of the variables set by this policy.
Element reference for Decode JWS
The policy reference describes the elements and attributes of the Decode JWS policy.
Attributes that apply to the top-level element
<DecodeJWS name="JWS" continueOnError="false" enabled="true" async="false">
The following attributes are common to all policy parent elements.
The internal name of the policy. Characters you can use in the name are restricted to:
A-Z0-9._\-$ %. However, the Edge management UI enforces additional
restrictions, such as automatically removing characters that are not alphanumeric.
Optionally, use the
false to return an error when a policy fails. This is expected
behavior for most policies.
true to enforce the policy.
|This attribute is deprecated.
<DisplayName>Policy Display Name</DisplayName>
Use in addition to the name attribute to label the policy in the management UI proxy editor with a different, natural-language name.
|If you omit this element, the value of the policy's name attribute is used.
If present, specifies the flow variable in which the policy expects to find the JWS to decode.
request.header.authorization (See the note above for important information
about the default).
|An Edge flow variable name
Upon success, the Verify JWS and Decode JWS policies set context variables according to this pattern:
For example, if the policy name is
verify-jws, then the policy will store
the algorithm specified in the JWS to this context variable:
|The JSON-parsable value of a header in the payload. One variable is set for
every header in the payload. While you can also use the
header.name flow variables,
this is the recommended variable to use to access a header.
|The signing algorithm used on the JWS. For example, RS256, HS384, and so on. See (Algorithm) Header Parameter for more.
|The Key ID, if added when the JWS was generated. See also "Using a JSON Web Key Set (JWKS)" at JWT and JWS policies overview to verify a JWS. See (Key ID) Header Parameter for more.
|The header type value. See (Type) Header Parameter for more.
|The value of the named header (standard or additional). One of these will be set for every additional header in the header portion of the JWS.
|The header in JSON format.
|The JWS payload if the JWS has an attached payload. For a detached payload, this variable is empty.
In the case of VerifyJWS, this variable will be true when the signature is verified, and
the current time is before the token expiry, and after the token notBefore value, if they
are present. Otherwise false.
In the case of DecodeJWS, this variable is not set.
This section describes the fault codes and error messages that are returned and fault variables that are set by Edge when this policy triggers an error. This information is important to know if you are developing fault rules to handle faults. To learn more, see What you need to know about policy errors and Handling faults.
These errors can occur when the policy executes.
|The policy was unable to decode the JWS. The JWS is possibly corrupted.
|Occurs when the flow variable specified in the
<Source> element of
the policy does not exist.
|For a missing claim or claim mismatch, or a missing header or header mismatch.
|Invalid JSON found in the JWS header.
|This error occurs when the JWS signature verification fails.
|The JWS payload is invalid.
<DetachedContent> is omitted and the JWS has a detached content payload.
|The JWS payload is missing.
|Occurs when the JWS omits the algorithm header.
|An unknown exception occurred.
These errors can occur when you deploy a proxy containing this policy.
|The only valid values are: RS256, RS384, RS512, PS256, PS384, PS512, ES256, ES384, ES512, HS256, HS384, HS512.
|Other possible deployment errors.
These variables are set when a runtime error occurs. For more information, see What you need to know about policy errors.
|fault_name is the name of the fault, as listed in the Runtime errors table above. The fault name is the last part of the fault code.
fault.name Matches "TokenExpired"
|All JWS policies set the same variable in the case of a failure.
jws.JWS-Policy.failed = true
Example error response
For error handling, the best practice is to trap the
errorcode part of the error
response. Do not rely on the text in the
faultstring, because it could change.
Example fault rule