VerifyJWS policy

This pageapplies toApigee andApigee hybrid.

View Apigee Edge documentation.

The VerifyJWS policy verifies the signature on a JWS received from clients or other systems. This policy also extracts headers into context variables so that subsequent policies or conditions can examine those values to make authorization or routing decisions. SeeJWS and JWT policies overview for a detailed introduction.

If the JWS is verified and valid, then the request is allowed to proceed. If the JWS signature cannot be verified or if the JWS is invalid because of some type of error, all processing stops and an error is returned in the response.

This policy is anExtensible policy and use of this policy might have cost or utilization implications, depending on your Apigee license. For information on policy types and usage implications, seePolicy types.

To learn about the parts of a JWS and how they are encrypted and signed, refer toRFC7515.

Samples

Verify an attached JWS signed with the HS256 algorithm

This example policy verifies an attached JWS that was signed with the HS256 encryption algorithm, HMAC using a SHA-256 checksum. The JWS is passed in the proxy request by using a form parameter namedJWS. The key is contained in a variable namedprivate.secretkey.

An attached JWS contains the encoded header, payload, and signature:

header.payload.signature

The policy configuration includes the information Apigee needs to decode and evaluate the JWS, such as where to find the JWS (in a flow variable specified in the<Source> element), the required signing algorithm, and where to find the secret key (stored in an Apigee flow variable, which could have been retrieved from the Apigee KVM, for example).

<VerifyJWS name="JWS-Verify-HS256">    <DisplayName>JWS Verify HS256</DisplayName>    <Algorithm>HS256</Algorithm>    <Source>request.formparam.JWS</Source>    <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>    <SecretKey>        <Value ref="private.secretkey"/>    </SecretKey></VerifyJWS>

The policy writes its output to context variables so that subsequent policies or conditions in the API proxy can examine those values. SeeFlow variables for a list of the variables set by this policy.

Verify a detached JWS signed with the RS256 algorithm

This example policy verifies a detached JWS that was signed with the RS256 algorithm. To verify, you need to provide the public key. The JWS is passed in the proxy request by using a form parameter namedJWS. The public key is contained in a variable namedpublic.publickey.

A detached JWS omits the payload from the JWS:

header..signature

It is up to you to pass the payload to the VerifyJWS policy by specifying the variable name containing the payload to the<DetachedContent> element. The specified content in<DetachedContent> must be in the original unencoded form it was when the JWS signature was created.

<VerifyJWSname="JWS-Verify-RS256"><DisplayName>JWSVerifyRS256</DisplayName><Algorithm>RS256</Algorithm><Source>request.formparam.JWS</Source><IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables><PublicKey><Valueref="public.publickey"/></PublicKey><DetachedContent>private.payload</DetachedContent></VerifyJWS>

The policy writes its output to context variables so that subsequent policies or conditions in the API proxy can examine those values. SeeFlow variables for a list of the variables set by this policy.

Setting the key elements

The elements that you use to specify the key used to verify the JWS depend on the chosen algorithm, as shown in the following table:

Note:The RS*, PS*, and ES* algorithms all use the same elements to specify the key, but the ES* key data is different than that used by the RS* and PS* algorithms. For more on the key requirements, seeAbout signature encryption algorithms.
Algorithmkey elements
HS*
<SecretKey>  <Value ref="private.secretkey"/></SecretKey>
RS*, ES*, PS*
<PublicKey>  <Value ref="rsa_public_key"/></PublicKey>

or:

<PublicKey>  <JWKS ref="jwks_val_ref_or_url"/></PublicKey>
*For more on the key requireSments, seeAbout signature encryption algorithms.

Element reference

The policy reference describes the elements and attributes of the Verify JWS policy.

Note: Configuration will differ somewhat depending on the encryption algorithm you use. Refer to theSamples for examples that demonstrate configurations for specific use cases.

S

Attributes that apply to the top-level element

<VerifyJWS name="JWS" continueOnError="false" enabled="true" async="false">

The following attributes are common to all policy parent elements.

AttributeDescriptionDefaultPresence
name The internal name of the policy. Characters you can use in the name are restricted to:A-Z0-9._\-$ %. However, the Apigee UI enforces additional restrictions, such as automatically removing characters that are not alphanumeric.

Optionally, use the<displayname></displayname> element to label the policy in the Apigee UI proxy editor with a different, natural-language name.

N/ARequired
continueOnError Set tofalse to return an error when a policy fails. This is expected behavior for most policies.

Set totrue to have flow execution continue even after a policy fails.

falseOptional
enabled Set totrue to enforce the policy.

Set tofalse to "turn off" the policy. The policy will not be enforced even if it remains attached to a flow.

trueOptional
asyncThis attribute is deprecated.falseDeprecated

<DisplayName>

<DisplayName>Policy Display Name</DisplayName>

Use in addition to the name attribute to label the policy in the Apigee UI proxy editor with a different, natural-language name.

DefaultIf you omit this element, the value of the policy's name attribute is used.
PresenceOptional
TypeString

<Algorithm>

<Algorithm>HS256</Algorithm>

Specifies the encryption algorithm to sign the token. RS*/PS*/ES* algorithms employ a public/secret key pair, while HS* algorithms employ a shared secret. See also About signature encryption algorithms.

You can specify multiple values separated by commas. For example "HS256, HS512" or "RS256, PS256". However, you cannot combine HS* algorithms with any others or ES* algorithms with any others because they require a specific key type. You can combine RS* and PS* algorithms.

DefaultN/A
PresenceRequired
TypeString of comma-separated values
Valid valuesHS256, HS384, HS512, RS256, RS384, RS512, ES256, ES384, ES512, PS256, PS384, PS512

<AdditionalHeaders/Claim>

<AdditionalHeaders><Claimname='claim1'>explicit-value-of-claim-here</Claim><Claimname='claim2'ref='variable-name-here'/><Claimname='claim3'ref='variable-name-here'type='boolean'/><Claimname='claim4'ref='variable-name'type='string'array='true'/></AdditionalHeaders>

Validates that the JWS header contains the specified additional claim name/value pair(s) and that the asserted claim values match.

The<Claim> element supports the dynamic string substitution feature calledmessage templating.

An additionl claim uses a name that is not one of the standard, registered JWS claim names. The value of an additional claim can be a string, a number, a boolean, a map, or an array. A map is simply a set of name/value pairs. The value for a claim of any of these types can be specified explicitly in the policy configuration, or indirectly via a reference to a flow variable.

Note: Do not use any of the registered claim names in this element. The registered claims are specified inRFC7519. They include: "iss", "sub", "aud", "iat", "exp", "nbf", and "jti".
DefaultN/A
PresenceOptional
Type

String (default), number, boolean, or map.

The type defaults to String if no type is specified.

ArraySet totrue to indicate if the value is an array of types. Default: false
Valid valuesAny value that you want to use for an additional claim.

The<Claim> element takes these attributes:

  • name - (Required) The name of the claim.Note: Do not use any of the registered claim names in this element. The registered claims are specified inRFC7519. They include: "iss", "sub", "aud", "iat", "exp", "nbf", and "jti".
  • ref - (Optional) The name of a flow variable. If present, the policy will use the value of this variable as the claim. If both aref attribute and an explicit claim value are specified, the explicit value is the default, and is used if the referenced flow variable is unresolved.
  • type - (Optional) One of: string (default), number, boolean, or map
  • array - (Optional) Set totrue to indicate if the value is an array of types. Default: false.

<DetachedContent>

<DetachedContent>variable-name-here</DetachedContent>

A generated JWS with a content payload is in the form:

header.payload.signature

If you use theGenerateJWS policy to create detached payload, the generated JWS omits the payload and is in the form:

header..signature

For a detached payload, it is up to you to pass the payload to the VerifyJWS policy by using the<DetachedContent> element. The specified content payload must be in the original unencoded form it was when the JWS signature was created.

Only set this element when you use the GenerateJWS policy to create a JWS with a detached content payload.

The policy throws an error when:

  • <DetachedContent> is specified when the JWS does not contain a detached content payload (fault code issteps.jws.ContentIsNotDetached).
  • <DetachedContent> is omitted and the JWS has a detached content payload (fault code issteps.jws.InvalidSignature).
DefaultN/A
PresenceOptional
TypeVariable reference

<IgnoreCriticalHeaders>

<IgnoreCriticalHeaders>true|false</IgnoreCriticalHeaders>

Set to false if you want the policy to throw an error when any header listed in thecrit header of the JWS is not listed in the<KnownHeaders> element. Set to true to cause the VerifyJWS policy to ignore thecrit header.

One reason to set this element to true is if you are in a testing environment and you do not want the policy to fail because of a missing header.

Defaultfalse
PresenceOptional
TypeBoolean
Valid valuestrue or false

<IgnoreUnresolvedVariables>

<IgnoreUnresolvedVariables>true|false</IgnoreUnresolvedVariables>

Set to false if you want the policy to throw an error when any referenced variable specified in the policy is unresolvable. Set to true to treat any unresolvable variable as an empty string (null).

Defaultfalse
PresenceOptional
TypeBoolean
Valid valuestrue or false

<KnownHeaders>

<KnownHeaders>a,b,c</KnownHeaders>or:<KnownHeadersref=variable_containing_headers/>

TheGenerateJWS policy uses the<CriticalHeaders> element to populate thecrit header in a token. For example:

{  “typ: “...”,  “alg” : “...”,  “crit” : [ “a”, “b”, “c” ],}

The VerifyJWS policy examinescrit header in the JWS, if it exists, and for each item listed it checks that the<KnownHeaders> element also lists that header. The<KnownHeaders> element can contain a superset of the items listed incrit. It is only necessary that all the headers listed incrit are listed in the<KnownHeaders> element. Any header that the policy finds incrit that is not also listed in<KnownHeaders> causes the VerifyJWS policy to fail.

You can optionally configure the VerifyJWS policy to ignore thecrit header by setting the<IgnoreCriticalHeaders> element totrue.

Note:The VerifyJWS policy does not actually handle or process the headers listed by the<KnownHeaders> element. It is left for you later in the proxy or the backend to actually handle those claims.
DefaultN/A
PresenceOptional
TypeComma separated array of strings
Valid valuesEither an array or the name of a variable containing the array.

<PublicKey/JWKS>

<!--SpecifytheJWKS.--><PublicKey><JWKS>jwks-value-here</JWKS></PublicKey>or:<!--SpecifyavariablecontainingtheJWKS.--><PublicKey><JWKSref="public.jwks"/></PublicKey>or:<!--SpecifyapublicURLthatreturnstheJWKS.TheURLisstatic,meaningyoucannotsetitusingavariable.--><PublicKey><JWKSuri="jwks-url"/></PublicKey>

Specifies a value in JWKS format (RFC 7517) containing a set of public keys.Use only when the algorithm is one of RS256/RS384/RS512, PS256/PS384/PS512, or ES256/ES384/ES512.

If the inbound JWS bears a key ID which present in the set of JWKS, then the policy will use the correct public key to verify the JWS signature. For details about this feature, see Using a JSON Web Key Set (JWKS) to verify a JWS.

If you fetch the value from a public URL, Apigee caches the JWKS for a period of 300 seconds. When the cache expires, Apigee fetches the JWKS again.

DefaultN/A
PresenceTo verify a JWS using an RSA algorithm, you must either either use the JWKS or Value element.
TypeString
Valid valuesA flow variable, string value, or URL.

<PublicKey/Value>

<PublicKey>   <Valueref="public.publickey"/></PublicKey>-or-<PublicKey>    <Value>-----BEGINPUBLICKEY-----MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAw2kPrRzcufvUNHvTH/WWQ0UrCw5c0+Y707KX3PpXkZGbtTT4nvU1jC0d1lHV8MfUyRXmpmnNxJHAC2F73IyNC5TBtXMORc+us7A2cTtC4gZV256bT4h3sIEMsDl0Joz9K9MPzVPFxa1i0RgNt06nXn/Bs2UbbLlKP5Q1HPxewUDEh0gVMqz9wdIGwH1pPxKvd3NltYGfPsUQovlof3l2ALvO7i5Yrm96kknfFEWf1EjmCCKvz2vjVbBb6mp1ZpYfc9MOTZVpQcXSbzb/BWUoZmkDb/DRW5onclGzxQITBFP3S6JXd4LNESJcTp705ec1cQ9Wp2Kl+nKrKyv1E5XxDQIDAQAB-----ENDPUBLICKEY-----    </Value></PublicKey>

Specifies the public key used to verify the signature on the JWS. Use the ref attribute to pass the key in a flow variable, or specify the PEM-encoded key directly.Use only when the algorithm is one of RS256/RS384/RS512, PS256/PS384/PS512, or ES256/ES384/ES512.

DefaultN/A
PresenceTo verify a JWS signed with an RSA algorithm, you must either either use the JWKS or Value elements.
TypeString
Valid valuesA flow variable or string.

<SecretKey>

<SecretKeyencoding="base16|hex|base64|base64url"><Valueref="private.your-variable-name"/></SecretKey>

Specifies the secret key to use when verifying a JWS that uses a symmetric (HS*) algorithm, one of HS256, HS384, or HS512.

This element is optional. However, you must include exactly one of either the<PublicKey> or<SecretKey> element. Use the<PublicKey> element when verifying a JWS for which the algorithm is RS*, PS*, or ES*, and use the<SecretKey> element when verifying a JWS for which the algorithm is HS*.

Children of<SecretKey>

The following table provides a description of the child elements and attributes of<SecretKey>:

ChildPresenceDescription
encoding (attribute)Optional

Specifies how the key is encoded in the referenced variable. By default, when noencoding attribute is present, the encoding of the key is treated as UTF-8. Valid values for the attribute are: hex, base16, base64, or base64url. The encoding values hex and base16 are synonyms.

<SecretKeyencoding="base64" >  <Value ref="private.secretkey"/></SecretKey>

In the above example, because the encoding isbase64, if the contents of the variableprivate.secretkey isSUxvdmVBUElz, the key will be decoded as a set of 9 bytes, which in hex will be49 4c 6f 76 65 41 50 49 73.

Note: Apigee enforces a minimum key strength. See the documentation for theValue element for details.
Value (element)Required

An encoded secret key. Specifies the secret key that will be used to verify the payload. Use theref attribute to provide the key indirectly via a variable, such asprivate.secret-key .

<SecretKey><Valueref="private.my-secret-variable"/></SecretKey>
Note: The variable name must include theprivate prefix as shown in the example above.

Apigee enforces a minimum key strength for the HS256/HS384/HS512 algorithms. The minimum key length for HS256 is 32 bytes, for HS384 it is 48 bytes, and for HS512 it is 64 bytes. Using a lower-strength key causes a runtime error.

<Source>

<Source>JWS-variable</Source>

If present, specifies the flow variable in which the policy expects to find the JWS to verify.

Note: By default, the JWS is retrieved from the variablerequest.header.authorization. In this case, Apigee looks for the JWS in the request Authorization header. If you pass the JWS in the Authorization header, you do not need to include the Source element in the policy; however, youmust includeBearer in the auth header. For example, you would pass the JWS in the Authorization header like this:
curl -v http://52.200.92.187:9001/doctest-JWS/verify-rs256 -H "Authorization: Bearer <your JWS>"

You can configure to policy to retrieve the JWS from a form or query parameter variable or any other variable. If the variable does not exist or if the policy otherwise can't find the JWS, the policy returns an error.

Defaultrequest.header.authorization (See the note above for important information about the default).
PresenceOptional
TypeString
Valid valuesAn Apigee flow variable name.

<Type>

<Type>type-string-here</Type>

Optional element whose only allowed value isSigned, specifying that the policy verifies a signed JWS.<Type> is provided just to match the corresponding element for the GenerateJWT and VerifyJWT policies (where it can take on either of the valuesSigned orEncrypted).

DefaultN/A
PresenceOptional
TypeString
Valid valueSigned

Flow variables

Upon success, theVerify JWS andDecode JWS policies set context variables according to this pattern:

jws.{policy_name}.{variable_name}

For example, if the policy name isverify-jws, then the policy will store the algorithm specified in the JWS to this context variable:jws.verify-jws.header.algorithm

Variable nameDescription
decoded.header.nameThe JSON-parsable value of a header in the payload. One variable is set for every header in the payload. While you can also use theheader.name flow variables, this is the recommended variable to use to access a header.
header.algorithmThe signing algorithm used on the JWS. For example, RS256, HS384, and so on. See(Algorithm) Header Parameter for more.
header.kidThe Key ID, if added when the JWS was generated. See also "Using a JSON Web Key Set (JWKS)" atJWT and JWS policies overview to verify a JWS. See(Key ID) Header Parameter for more.
header.typeThe header type value. See(Type) Header Parameter for more.
header.nameThe 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.
header-jsonThe header in JSON format.
payloadThe JWS payload if the JWS has an attached payload. For a detached paylod, this variable is empty.
valid 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.

Error reference

This section describes the fault codes and error messages that are returned and fault variables that are set by Apigee when this policy triggers an error. This information is important to know if you are developing fault rules to handle faults. To learn more, seeWhat you need to know about policy errors andHandling faults.

Runtime errors

These errors can occur when the policy executes.

Fault codeHTTP statusOccurs when
steps.jws.AlgorithmInTokenNotPresentInConfiguration401Occurs when the verification policy has multiple algorithms
steps.jws.AlgorithmMismatch401The algorithm specified in the header by theGenerate policy did not match the one expected in theVerify policy. The algorithms specified must match.
steps.jws.ContentIsNotDetached401<DetachedContent> is specified when the JWS does not contain a detached content payload.
steps.jws.FailedToDecode401The policy was unable to decode the JWS. The JWS is possibly corrupted.
steps.jws.InsufficientKeyLength401For a key less than 32 bytes for the HS256 algorithm
steps.jws.InvalidClaim401For a missing claim or claim mismatch, or a missing header or header mismatch.
steps.jws.InvalidCurve401The curve specified by the key is not valid for the Elliptic Curve algorithm.
steps.jws.InvalidJsonFormat401Invalid JSON found in the JWS header.
steps.jws.InvalidJws401This error occurs when the JWS signature verification fails.
steps.jws.InvalidPayload401The JWS payload is invalid.
steps.jws.InvalidSignature401<DetachedContent> is omitted and the JWS has a detached content payload.
steps.jws.KeyIdMissing401TheVerify policy uses a JWKS as a source for public keys, but the signed JWS does not include akid property in the header.
steps.jws.KeyParsingFailed401The public key could not be parsed from the given key information.
steps.jws.MissingPayload401The JWS payload is missing.
steps.jws.NoAlgorithmFoundInHeader401Occurs when the JWS omits the algorithm header.
steps.jws.NoMatchingPublicKey401TheVerify policy uses a JWKS as a source for public keys, but thekid in the signed JWS is not listed in the JWKS.
steps.jws.UnhandledCriticalHeader401A header found by the Verify JWS policy in thecrit header is not listed inKnownHeaders.
steps.jws.UnknownException401An unknown exception occurred.
steps.jws.WrongKeyType401Wrong type of key specified. For example, if you specify an RSA key for an Elliptic Curve algorithm, or a curve key for an RSA algorithm.

Deployment errors

These errors can occur when you deploy a proxy containing this policy.

Error nameOccurs when
InvalidAlgorithmThe only valid values are:RS256, RS384, RS512, PS256, PS384, PS512, ES256, ES384, ES512, HS256, HS384, HS512.

EmptyElementForKeyConfiguration

FailedToResolveVariable

InvalidConfigurationForActionAndAlgorithmFamily

InvalidConfigurationForVerify

InvalidEmptyElement

InvalidFamiliesForAlgorithm

InvalidKeyConfiguration

InvalidNameForAdditionalClaim

InvalidNameForAdditionalHeader

InvalidPublicKeyId

InvalidPublicKeyValue

InvalidSecretInConfig

InvalidTypeForAdditionalClaim

InvalidTypeForAdditionalHeader

InvalidValueForElement

InvalidValueOfArrayAttribute

InvalidVariableNameForSecret

MissingConfigurationElement

MissingElementForKeyConfiguration

MissingNameForAdditionalClaim

MissingNameForAdditionalHeader

Other possible deployment errors.

Fault variables

These variables are set when a runtime error occurs. For more information, seeWhat you need to know about policy errors.

VariablesWhereExample
fault.name="fault_name"fault_name is the name of the fault, as listed in theRuntime errors table above. The fault name is the last part of the fault code.fault.name Matches "TokenExpired"
JWS.failedAll 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 theerrorcode part of the error response. Do not rely on the text in thefaultstring, because it could change.

Example fault rule

<FaultRules>    <FaultRule name="JWS Policy Errors">        <Step>            <Name>JavaScript-1</Name>            <Condition>(fault.name Matches "TokenExpired")</Condition>        </Step>        <Condition>JWS.failed=true</Condition>    </FaultRule></FaultRules>

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-17 UTC.