VerifyJWT policy

You're viewing Apigee Edge documentation.
Go to the Apigee X documentation.
info

What

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

When this policy executes, Edge verifies the signature of a JWT, and verifies that the JWT is valid according to the expiry and not-before times if they are present. The policy can optionally also verify the values of specific claims on the JWT, such as the subject, the issuer, the audience, or the value of additional claims.

If the JWT is verified and valid, then all of the claims contained within the JWT are extracted into context variables for use by subsequent policies or conditions, and the request is allowed to proceed. If the JWT signature cannot be verified or if the JWT is invalid because of one of the timestamps, all processing stops and an error is returned in the response.

To learn about the parts of a JWT and how they are encrypted and signed, refer to RFC7519.

Video

Watch a short video to learn how to verify the signature on a JWT.

Samples

Verify a JWT signed with the HS256 algorithm

This example policy verifies a JWT that was signed with the HS256 encryption algorithm, HMAC using a SHA-256 checksum. The JWT is passed in the proxy request by using a form parameter named jwt. The key is contained in a variable named private.secretkey. See the video above for a complete example, including how to make a request to the policy.

The policy configuration includes the information Edge needs to decode and evaluate the JWT, such as where to find the JWT (in a flow variable specified in the Source element), the required signing algorithm, where to find the secret key (stored in an Edge flow variable, which could have been retrieved from the Edge KVM, for example), and a set of required claims and their values.

<VerifyJWT name="JWT-Verify-HS256">
    <DisplayName>JWT Verify HS256</DisplayName>
    <Algorithm>HS256</Algorithm>
    <Source>request.formparam.jwt</Source>
    <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
    <SecretKey encoding="base64">
        <Value ref="private.secretkey"/>
    </SecretKey>
    <Subject>monty-pythons-flying-circus</Subject>
    <Issuer>urn://apigee-edge-JWT-policy-test</Issuer>
    <Audience>fans</Audience>
    <AdditionalClaims>
        <Claim name="show">And now for something completely different.</Claim>
    </AdditionalClaims>
</VerifyJWT>

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

Verify a JWT signed with the RS256 algorithm

This example policy verifies a JWT that was signed with the RS256 algorithm. To verify, you need to provide the public key. The JWT is passed in the proxy request by using a form parameter named jwt. The public key is contained in a variable named public.publickey. See the video above for a complete example, including how to make a request to the policy.

See the Element reference for details on the requirements and options for each element in this sample policy.

<VerifyJWT name="JWT-Verify-RS256">
    <Algorithm>RS256</Algorithm>
    <Source>request.formparam.jwt</Source>
    <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
    <PublicKey>
        <Value ref="public.publickey"/>
    </PublicKey>
    <Subject>apigee-seattle-hatrack-montage</Subject>
    <Issuer>urn://apigee-edge-JWT-policy-test</Issuer>
    <Audience>urn://c60511c0-12a2-473c-80fd-42528eb65a6a</Audience>
    <AdditionalClaims>
        <Claim name="show">And now for something completely different.</Claim>    
    </AdditionalClaims>
</VerifyJWT>

For the above configuration, a JWT with this header …

{
  "typ" : "JWT", 
  "alg" : "RS256"
}

And this payload …

{ 
  "sub" : "apigee-seattle-hatrack-montage",
  "iss" : "urn://apigee-edge-JWT-policy-test",
  "aud" : "urn://c60511c0-12a2-473c-80fd-42528eb65a6a",
  "show": "And now for something completely different."
}

… will be deemed as valid, if the signature can be verified with the provided public key.

A JWT with the same header but with this payload …

{ 
  "sub" : "monty-pythons-flying-circus",
  "iss" : "urn://apigee-edge-JWT-policy-test",
  "aud" : "urn://c60511c0-12a2-473c-80fd-42528eb65a6a",
  "show": "And now for something completely different."
}

… will be determined to be invalid, even if the signature can be verified, because the "sub" claim included in the JWT does not match the required value of the "Subject" element as specified in the policy configuration.

The policy writes its output to context variables so that subsequent policies or conditions in the API proxy can examine those values. See Flow 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 JWT depend on the chosen algorithm, as shown in the following table:

Algorithm Key elements
HS*
<SecretKey encoding="base16|hex|base64|base64url">
  <Value ref="private.secretkey"/>
</SecretKey>
RS*, ES*, PS*
<PublicKey>
  <Value ref="rsa_public_key_or_value"/>
</PublicKey>

or:

<PublicKey>
  <Certificate ref="signed_cert_val_ref"/>
</PublicKey>

or:

<PublicKey>
  <JWKS ref="jwks_val_or_ref"/>
</PublicKey>
*For more on the key requirements, see About signature encryption algorithms.

Element reference

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

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

Attributes that apply to the top-level element

<VerifyJWT name="JWT" continueOnError="false" enabled="true" async="false">

The following attributes are common to all policy parent elements.

Attribute Description Default Presence
name 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 <displayname></displayname> element to label the policy in the management UI proxy editor with a different, natural-language name.

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

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

false Optional
enabled Set to true to enforce the policy.

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

true Optional
async This attribute is deprecated. false Deprecated

<DisplayName>

<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.

Default If you omit this element, the value of the policy's name attribute is used.
Presence Optional
Type String

<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.

Default N/A
Presence Required
Type String of comma-separated values
Valid values HS256, HS384, HS512, RS256, RS384, RS512, ES256, ES384, ES512, PS256, PS384, PS512

<Audience>

<Audience>audience-here</Audience>

or:

<Audience ref='variable-name-here'/>

The policy verifies that the audience claim in the JWT matches the value specified in the configuration. If there is no match, the policy throws an error. This claim identifies the recipients that the JWT is intended for. This is one of the registered claims mentioned in RFC7519.

Default N/A
Presence Optional
Type String
Valid values A flow variable or string that identifies the audience.

<AdditionalClaims/Claim>

<AdditionalClaims>
    <Claim name='claim1'>explicit-value-of-claim-here</Claim>
    <Claim name='claim2' ref='variable-name-here'/>
    <Claim name='claim3' ref='variable-name-here' type='boolean'/>
 </AdditionalClaims>

or:

<AdditionalClaims ref='claim_payload'/>

Validates that the JWT payload contains the specified additional claim(s) and that the asserted claim values match.

An additional claim uses a name that is not one of the standard, registered JWT claim names. The value of a 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.

Default N/A
Presence Optional
Type String, number, boolean, or map
Array Set to true to indicate if the value is an array of types. Default: false
Valid values Any value that you want to use for an additional claim.

The <Claim> element takes these attributes:

  • name - (Required) The name of the claim.
  • ref - (Optional) The name of a flow variable. If present, the policy will use the value of this variable as the claim. If both a ref 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 to true to indicate if the value is an array of types. Default: false.

When you include the <Claim> element, the claim names are set statically when you configure the policy. Alternatively, you can pass a JSON object to specify the claim names. Because the JSON object is passed as a variable, the claim names are determined at runtime.

For example:

<AdditionalClaims ref='json_claims'/>

Where the variable json_claims contains a JSON object in the form:

{
  "sub" : "person@example.com",
  "iss" : "urn://secure-issuer@example.com",
  "non-registered-claim" : {
    "This-is-a-thing" : 817,
    "https://example.com/foobar" : { "p": 42, "q": false }
  }
}

<AdditionalHeaders/Claim>

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

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

An additionl claim uses a name that is not one of the standard, registered JWT 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.

Default N/A
Presence Optional
Type

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

The type defaults to String if no type is specified.

Array Set to true to indicate if the value is an array of types. Default: false
Valid values Any value that you want to use for an additional claim.

The <Claim> element takes these attributes:

  • name - (Required) The name of the claim.
  • ref - (Optional) The name of a flow variable. If present, the policy will use the value of this variable as the claim. If both a ref 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 to true to indicate if the value is an array of types. Default: false.

<CustomClaims>

Note: Currently, a CustomClaims element is inserted when you add a new GenerateJWT policy through the UI. This element is not functional and is ignored. The correct element to use instead is <AdditionalClaims>. The UI will be updated to insert the correct elements at a later time.

<Id>

<Id>explicit-jti-value-here</Id>
 -or-
<Id ref='variable-name-here'/>
 -or-
<Id/>

Verifies that the JWT has the specific jti claim. When the text value and ref attribute are both empty, the policy will generate a jti containing a random UUID. The JWT ID (jti) claim is a unique identifier for the JWT. For more information on jti, refer to RFC7519.

Default N/A
Presence Optional
Type String, or reference.
Valid values Either a string or the name of a flow variable containing the ID.

<IgnoreCriticalHeaders>

<IgnoreCriticalHeaders>true|false</IgnoreCriticalHeaders>

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

One reason to set this element to true is if you are in a testing environment and are not yet ready to casues a failure on a missing header.

Default false
Presence Optional
Type Boolean
Valid values true or false

<IgnoreIssuedAt>

<IgnoreIssuedAt>true|false</IgnoreIssuedAt>

Set to false (default) if you want the policy to throw an error when a JWT contains an iat (Issued at) claim that specifies a time in the future. Set to true to cause the policy to ignore iat during verification.

Default false
Presence Optional
Type Boolean
Valid values true 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).

Default false
Presence Optional
Type Boolean
Valid values true or false

<Issuer>

<Issuer ref='variable-name-here'/>
<Issuer>issuer-string-here</Issuer>

The policy verifies that the issuer in the JWT matches the string specified in the configuration element. A claim that identifies the issuer of the JWT. This is one of the registered set of claims mentioned in RFC7519.

Default N/A
Presence Optional
Type String, or reference
Valid values Any

<KnownHeaders>

<KnownHeaders>a,b,c</KnownHeaders>

or:

<KnownHeaders ref=variable_containing_headers/>

The GenerateJWT policy uses the <CriticalHeaders> element to populate the crit header in a JWT. For example:

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

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

You can optionally configure the VerifyJWT policy to ignore the crit header by setting the <IgnoreCriticalHeaders> element to true.

Default N/A
Presence Optional
Type Comma separated array of strings
Valid values Either an array or the name of a variable containing the array.

<PublicKey/Certificate>

<PublicKey>
   <Certificate ref="signed_public.cert"/>
</PublicKey>
-or-
<PublicKey>
    <Certificate>
    -----BEGIN CERTIFICATE-----
    cert data
    -----END CERTIFICATE-----
    </Certificate>
</PublicKey>

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

Default N/A
Presence To verify a JWT signed with an RSA algorithm, you must either either use the Certificate, JWKS, or Value elements.
Type String
Valid values A flow variable or string.

<PublicKey/JWKS>

<!-- Specify the JWKS. -->
<PublicKey>
   <JWKS>jwks-value-here</JWKS>
</PublicKey>

or:

<!-- Specify a variable containing the JWKS. -->
<PublicKey>
   <JWKS ref="public.jwks"/>
</PublicKey>

or:

<!-- Specify a public URL that returns the JWKS.
The URL is static, meaning you cannot set it using a variable. -->
<PublicKey>
   <JWKS uri="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 JWT bears a key ID which present in the set of JWKS, then the policy will use the correct public key to verify the JWT signature. For details about this feature, see Using a JSON Web Key Set (JWKS) to verify a JWT.

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

Default N/A
Presence To verify a JWT using an RSA algorithm, you must either either use the Certificate, JWKS, or Value element.
Type String
Valid values A flow variable, string value, or URL.

<PublicKey/Value>

<PublicKey>
   <Value ref="public.publickeyorcert"/>
</PublicKey>
-or-
<PublicKey>
    <Value>
    -----BEGIN PUBLIC KEY-----
    MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAw2kPrRzcufvUNHvTH/WW
    Q0UrCw5c0+Y707KX3PpXkZGbtTT4nvU1jC0d1lHV8MfUyRXmpmnNxJHAC2F73IyN
    C5TBtXMORc+us7A2cTtC4gZV256bT4h3sIEMsDl0Joz9K9MPzVPFxa1i0RgNt06n
    Xn/Bs2UbbLlKP5Q1HPxewUDEh0gVMqz9wdIGwH1pPxKvd3NltYGfPsUQovlof3l2
    ALvO7i5Yrm96kknfFEWf1EjmCCKvz2vjVbBb6mp1ZpYfc9MOTZVpQcXSbzb/BWUo
    ZmkDb/DRW5onclGzxQITBFP3S6JXd4LNESJcTp705ec1cQ9Wp2Kl+nKrKyv1E5Xx
    DQIDAQAB
    -----END PUBLIC KEY-----
    </Value>
</PublicKey>

Specifies the public key or public cert used to verify the signature on the JWT. Use the ref attribute to pass the key/cert 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.

Default N/A
Presence To verify a JWT signed with an RSA algorithm, you must either either use the Certificate, JWKS, or Value elements.
Type String
Valid values A flow variable or string.

<SecretKey/Value>

<SecretKey encoding="base16|hex|base64|base64url">
  <Value ref="private.your-variable-name"/>
</SecretKey>

Provides the secret key used to verify or sign tokens with an HMAC algorithm. Use only when the algorithm is one of HS256, HS384, HS512..

Default N/A
Presence Required for HMAC algorithms.
Type String
Valid values

For encoding, valid values are hex, base16, base64, or base64url. The encoding values hex and base16 are synonyms.

Use the ref attribute to pass the key in a flow variable.

Note: If a flow variable, it must have the prefix "private". For example, private.mysecret

<Source>

<Source>jwt-variable</Source>

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

Default request.header.authorization (See the note above for important information about the default).
Presence Optional
Type String
Valid values An Edge flow variable name.

<Subject>

<Subject>subject-string-here</Subject>

The policy verifies that the subject in the JWT matches the string specified in the policy configuration. This claim identifies or makes a statement about the subject of the JWT. This is one of the standard set of claims mentioned in RFC7519.

Default N/A
Presence Optional
Type String
Valid values Any value uniquely identifying a subject.

<TimeAllowance>

<TimeAllowance>120s</TimeAllowance>

The "grace period" for times. For example, if the time allowance is configured to be 60s, then an expired JWT would be treated as still valid, for 60s after the asserted expiry. The not-before-time will be evaluated similarly. Defaults to 0 seconds (no grace period).

Default 0 seconds (no grace period)
Presence Optional
Type String
Valid values A value or a reference to a flow variable containing the value. Time spans can be specified as follows:
  • s = seconds
  • m = minutes
  • h = hours
  • d = days

Flow variables

Upon success, the Verify JWT and Decode JWT policies set context variables according to this pattern:

jwt.{policy_name}.{variable_name}

For example, if the policy name is jwt-parse-token , then the policy will store the subject specified in the JWT to the context variable named jwt.jwt-parse-token.decoded.claim.sub. (For backward compatibility, it will also be available in jwt.jwt-parse-token.claim.subject)

Variable name Description
claim.audience The JWT audience claim. This value may be a string, or an array of strings.
claim.expiry The expiration date/time, expressed in milliseconds since epoch.
claim.issuedat The Date the token was issued, expressed in milliseconds since epoch.
claim.issuer The JWT issuer claim.
claim.notbefore If the JWT includes a nbf claim, this variable will contain the value, expressed in milliseconds since epoch.
claim.subject The JWT subject claim.
claim.name The value of the named claim (standard or additional) in the payload. One of these will be set for every claim in the payload.
decoded.claim.name The JSON-parsable value of the named claim (standard or additional) in the payload. One variable is set for every claim in the payload. For example, you can use decoded.claim.iat to retrieve the issued-at time of the JWT, expressed in seconds since epoch. While you can also use the claim.name flow variables, this is the recommended variable to use to access a claim.
decoded.header.name 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.
expiry_formatted The expiration date/time, formatted as a human-readable string. Example: 2017-09-28T21:30:45.000+0000
header.algorithm The signing algorithm used on the JWT. For example, RS256, HS384, and so on. See (Algorithm) Header Parameter for more.
header.kid The Key ID, if added when the JWT was generated. See also "Using a JSON Web Key Set (JWKS)" at JWT policies overview to verify a JWT. See (Key ID) Header Parameter for more.
header.type Will be set to JWT.
header.name 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 JWT.
header-json The header in JSON format.
is_expired true or false
payload-claim-names An array of claims supported by the JWT.
payload-json
The payload in JSON format.
seconds_remaining The number of seconds before the token will expire. If the token is expired, this number will be negative.
time_remaining_formatted The time remaining before the token will expire, formatted as a human-readable string. Example: 00:59:59.926
valid In the case of VerifyJWT, 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 DecodeJWT, 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 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.

Runtime errors

These errors can occur when the policy executes.

Fault code HTTP status Occurs when
steps.jwt.AlgorithmInTokenNotPresentInConfiguration 401 Occurs when the verification policy has multiple algorithms.
steps.jwt.AlgorithmMismatch 401 The algorithm specified in the Generate policy did not match the one expected in the Verify policy. The algorithms specified must match.
steps.jwt.FailedToDecode 401 The policy was unable to decode the JWT. The JWT is possibly corrupted.
steps.jwt.GenerationFailed 401 The policy was unable to generate the JWT.
steps.jwt.InsufficientKeyLength 401 For a key less than 32 bytes for the HS256 algorithm, less than 48 bytes for the HS386 algortithm, and less than 64 bytes for the HS512 algorithm.
steps.jwt.InvalidClaim 401 For a missing claim or claim mismatch, or a missing header or header mismatch.
steps.jwt.InvalidCurve 401 The curve specified by the key is not valid for the Elliptic Curve algorithm.
steps.jwt.InvalidJsonFormat 401 Invalid JSON found in the header or payload.
steps.jwt.InvalidToken 401 This error occurs when the JWT signature verification fails.
steps.jwt.JwtAudienceMismatch 401 The audience claim failed on token verification.
steps.jwt.JwtIssuerMismatch 401 The issuer claim failed on token verification.
steps.jwt.JwtSubjectMismatch 401 The subject claim failed on token verification.
steps.jwt.KeyIdMissing 401 The Verify policy uses a JWKS as a source for public keys, but the signed JWT does not include a kid property in the header.
steps.jwt.KeyParsingFailed 401 The public key could not be parsed from the given key information.
steps.jwt.NoAlgorithmFoundInHeader 401 Occurs when the JWT contains no algorithm header.
steps.jwt.NoMatchingPublicKey 401 The Verify policy uses a JWKS as a source for public keys, but the kid in the signed JWT is not listed in the JWKS.
steps.jwt.SigningFailed 401 In GenerateJWT, for a key less than the minimum size for the HS384 or HS512 algorithms
steps.jwt.TokenExpired 401 The policy attempts to verify an expired token.
steps.jwt.TokenNotYetValid 401 The token is not yet valid.
steps.jwt.UnhandledCriticalHeader 401 A header found by the Verify JWT policy in the crit header is not listed in KnownHeaders.
steps.jwt.UnknownException 401 An unknown exception occurred.
steps.jwt.WrongKeyType 401 Wrong 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 name Cause Fix
InvalidNameForAdditionalClaim The deployment will fail if the claim used in the child element <Claim> of the <AdditionalClaims> element is one of the following registered names: kid, iss, sub, aud, iat, exp, nbf, or jti.
InvalidTypeForAdditionalClaim If the claim used in the child element <Claim> of the <AdditionalClaims> element is not of type string, number, boolean, or map, the deployment will fail.
MissingNameForAdditionalClaim If the name of the claim is not specified in the child element <Claim> of the <AdditionalClaims> element, the deployment will fail.
InvalidNameForAdditionalHeader This error ccurs when the name of the claim used in the child element <Claim> of the <AdditionalClaims> element is either alg or typ.
InvalidTypeForAdditionalHeader If the type of claim used in the child element <Claim> of the <AdditionalClaims> element is not of type string, number, boolean, or map, the deployment will fail.
InvalidValueOfArrayAttribute This error occurs when the value of the array attribute in the child element <Claim> of the <AdditionalClaims> element is not set to true or false.
InvalidValueForElement If the value specified in the <Algorithm> element is not a supported value, the deployment will fail.
MissingConfigurationElement This error will occur if the <PrivateKey> element is not used with RSA family algorithms or the <SecretKey> element is not used with HS Family algorithms.
InvalidKeyConfiguration If the child element <Value> is not defined in the <PrivateKey> or <SecretKey> elements, the deployment will fail.
EmptyElementForKeyConfiguration If the ref attribute of the child element <Value> of the <PrivateKey> or <SecretKey> elements is empty or unspecified, the deployment will fail.
InvalidConfigurationForVerify This error occurs if the <Id> element is defined within the <SecretKey> element.
InvalidEmptyElement This error occurs if the <Source> element of the Verify JWT policy is empty. If present, it must be defined with an Edge flow variable name.
InvalidPublicKeyValue If the value used in the child element <JWKS> of the <PublicKey> element does not use a valid format as specified in RFC 7517, the deployment will fail.
InvalidConfigurationForActionAndAlgorithm If the <PrivateKey> element is used with HS Family algorithms or the <SecretKey> element is used with RSA Family algorithms, the deployment will fail.

Fault variables

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

Variables Where Example
fault.name="fault_name" 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"
JWT.failed All JWT policies set the same variable in the case of a failure. JWT.failed = true

Example error response

JWT Policy Fault Codes

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

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